Skip to content

Commit

Permalink
update task.json with the appropriate mode
Browse files Browse the repository at this point in the history
mode can be "test" or "prod"
  • Loading branch information
arturcic committed Jul 9, 2024
1 parent e26db05 commit eae305d
Show file tree
Hide file tree
Showing 6 changed files with 653 additions and 98 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,15 @@ jobs:
id: gitversion # step id used as reference for output values
uses: ./gitversion/execute
- run: |
$mode = "test"
$date = Get-Date -format "yyMMddHH"
$version = "${{steps.gitversion.outputs.majorMinorPatch}}.$date"
$major = "${{steps.gitversion.outputs.major}}"
$minor = "${{steps.gitversion.outputs.minor}}"
$patch = "${{steps.gitversion.outputs.patch}}"
. .\update-version.ps1 # Import the functions
update-manifest .\dist\azure\vss-extension.json -Version $version
dir -r .\dist\**\task.json | % { update-task $_ -Major $major -Minor $minor -Patch $patch }
npm run publish:azure -- --token ${{ secrets.TFX_TOKEN }}
npm run publish:prepare -- --mode $mode --version $version
npm run publish:azure -- --token ${{ secrets.TFX_TOKEN }} --env mode=$mode version=$version
name: Publish Azure extension
- name: Get tags
id: get-tags
Expand Down
42 changes: 42 additions & 0 deletions dist/azure/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"gitversion": {
"setup": {
"test": "67561427-431b-4ab7-97bb-aa71c8deb5d0",
"prod": "a06c02ae-7b9a-4082-90dc-fe27b500e54f"
},
"execute": {
"test": "9b58ed30-0deb-4083-b007-5f6ce7787544",
"prod": "9013cf7f-ee8d-49f4-a39b-db244928d391"
}
},
"gitreleasemanager": {
"setup": {
"test": "9bcd25be-3019-481a-bca1-5b935ce1538b",
"prod": "e3022448-b00d-4b57-b504-606a0bcf8279"
},
"publish": {
"test": "2cd41def-54d8-45f3-9567-07242afd624b",
"prod": "b3c54483-4140-45d8-b442-3a0b096b5f7f"
},
"open": {
"test": "c7d6e958-c010-4c33-9f29-017257201aa2",
"prod": "5d437bf5-f193-4449-b531-c4c69eebaa48"
},
"discard": {
"test": "13c52c58-7d93-4aca-a011-4310b9b4d95c",
"prod": "9ae78b66-6100-4522-8106-b7ae00bbfcdf"
},
"create": {
"test": "930f4353-abcc-421c-9187-660d0f3cf3f7",
"prod": "c77d38be-46a9-4ef1-a181-2d6050ed23d2"
},
"close": {
"test": "b0825d48-79a2-4cff-9413-f52386a67b4d",
"prod": "f5304356-f6e3-48e9-9b65-a9efa41ce7a2"
},
"addasset": {
"test": "16670609-2a4a-48a0-9ece-6fd159719052",
"prod": "b803651c-21ac-4851-9fbf-c75b0e82e4c5"
}
}
}
74 changes: 74 additions & 0 deletions dist/azure/updateTasks.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env node
import { readFile, writeFile } from 'node:fs/promises'
import { glob } from 'glob'
import path from 'node:path'
import { parseArgs } from 'node:util'

import tasks from './tasks.json' assert { type: 'json' }

// Function to read JSON file
const readJsonFile = async (filePath) => {
const rawData = await readFile(filePath, 'utf8')
return JSON.parse(rawData)
}

// Function to write JSON file
const writeJsonFile = async (filePath, data) => {
const jsonData = JSON.stringify(data, null, 2)
await writeFile(filePath, jsonData)
}

// Function to update JSON fields
const updateJsonFields = async (filePath, versionStr, mode) => {
const data = await readJsonFile(filePath)

const parentDir = path.basename(path.dirname(filePath))
const grandParentDir = path.basename(path.dirname(path.dirname(filePath)))

const version = versionStr.split('.').map(Number)
const id = mode === 'prod' ? tasks[grandParentDir][parentDir].prod : tasks[grandParentDir][parentDir].test
let updates = {
id: id,
minimumAgentVersion: "3.224.0",
version: {
Major: version[0],
Minor: version[1],
Patch: version[2]
}
}

// Update the fields
for (let key in updates) {
if (data.hasOwnProperty(key)) {
data[key] = updates[key]
}
}

console.log(`Updating ${filePath} with version ${versionStr} and mode ${mode}`)
await writeJsonFile(filePath, data)
}

// Function to find and update all task.json files
const updateTasks = async (pattern, version, mode) => {
try {
const files = await glob(pattern)
await Promise.all(files.map(file => updateJsonFields(file, version, mode)))
console.log('All task.json files updated successfully.')
} catch (err) {
console.error('Error finding files:', err)
}
}

// Glob pattern to find task.json files
const pattern = './**/task.json'

const { version, mode } = parseArgs({
options: {
version: { type: 'string', short: 'v', default: '0.0.1' },
mode: { type: 'string', short: 'm', default: 'test' }
}
}).values


// Update all task.json files
await updateTasks(pattern, version, mode)
Loading

0 comments on commit eae305d

Please sign in to comment.