diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f26f07f..dacd0dd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,9 +1,8 @@ -name: Build Extension +name: Build on: push: branches: [main] - tags: ['*'] pull_request: branches: [main] @@ -23,8 +22,5 @@ jobs: - name: NPM Install run: npm install - - name: NPM Build + - name: Build extension run: npm run build - - - name: NPM Package - run: npm run package diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index a59faac..28c069c 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -6,9 +6,6 @@ on: pull_request: branches: [main] -permissions: - contents: read - jobs: codespell: name: Check for spelling errors diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml new file mode 100644 index 0000000..a3cab44 --- /dev/null +++ b/.github/workflows/prettier.yml @@ -0,0 +1,26 @@ +name: Prettier + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + prettier: + name: Check for formatting issues + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Use Node.js 18.x + uses: actions/setup-node@v4 + with: + node-version: '18.x' + + - name: NPM Install + run: npm install + + - name: NPM Format Check + run: npm run format:check diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..2862de2 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,104 @@ +name: Publish + +on: + push: + branches: [main] + tags: ['*'] + +jobs: + build: + name: Publish extension + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch all history so that GitVersion can calculate the version + + - name: Use GitVersion 6.x + uses: gittools/actions/gitversion/setup@v3.0.0 + with: + versionSpec: '6.x' + + - name: Determine version + id: gitversion + uses: gittools/actions/gitversion/execute@v3.0.0 + with: + useConfigFile: true + + - name: Update version numbers in vss-extension.overrides.json + uses: cschleiden/replace-tokens@v1 + with: + files: '["vss-extension.overrides.*.json"]' + env: + MAJOR_MINOR_PATCH: ${{ steps.gitversion.outputs.majorMinorPatch }} + BUILD_NUMBER: ${{ github.run_number }} + + - name: Update version numbers in task.json + run: | + echo "`jq '.version.Major=${{ steps.gitversion.outputs.major }}' task/task.json`" > task/task.json + echo "`jq '.version.Minor=${{ steps.gitversion.outputs.minor }}' task/task.json`" > task/task.json + echo "`jq '.version.Patch=${{ github.run_number }}' task/task.json`" > task/task.json + + - name: Use Node.js 18.x + uses: actions/setup-node@v4 + with: + node-version: '18.x' + + - name: NPM Install + run: npm install + + - name: Build extension + run: npm run build + + - name: Package extension (dev) + run: npm run package:dev + + - name: Package extension (prod) + run: npm run package:prod + + - name: Upload artifact (drop) + uses: actions/upload-artifact@v4 + with: + path: ${{ github.workspace }}/dist/* + name: drop + + publish: + runs-on: ubuntu-latest + needs: [build] + steps: + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: drop + + - name: Upload release + if: startsWith(github.ref, 'refs/tags/') + uses: ncipollo/release-action@v1 + with: + artifacts: '${{ github.workspace }}/prod/*.vsix,${{ github.workspace }}/dev/*.vsix' + token: ${{ secrets.GITHUB_TOKEN }} + draft: true + allowUpdates: true + + - name: Use Node.js 18.x + uses: actions/setup-node@v4 + with: + node-version: '18.x' + + - name: Publish to marketplace (dev) + if: github.ref == 'refs/heads/main' + run: > + npx tfx-cli extension publish + --vsix ${{ github.workspace }}/dev/*.vsix + --auth-type pat + --token ${{ secrets.AZURE_DEVOPS_EXTENSION_TOKEN }} + --share-with rhyskoedijk + + - name: Publish to marketplace (prod) + if: startsWith(github.ref, 'refs/tags/') + run: > + tfx extension publish + --vsix ${{ github.workspace }}/prod/*.vsix + --auth-type pat + --token ${{ secrets.AZURE_DEVOPS_EXTENSION_TOKEN }} diff --git a/package.json b/package.json index 1fa5311..88040d2 100644 --- a/package.json +++ b/package.json @@ -9,11 +9,11 @@ "format:check": "prettier --check '**/*.{js,ts,tsx,scss,json,yaml,yml,md,html}'", "build": "npm run build:task && npm run build:ui", "build:task": "cd task && tsc", - "build:ui": "cd ui && webpack --mode production", + "build:ui": "cd ui && webpack --mode development", "start:ui": "cd ui && webpack serve --mode development", - "package": "npx tfx-cli extension create --manifests vss-extension.json --output-path dist --overrides-file vss-extension.overrides.prod.json", - "package:dev": "node task/scripts/increment-task-version.js && npx tfx-cli extension create --manifests vss-extension.json --output-path dist --overrides-file vss-extension.overrides.dev.json --rev-version", - "publish": "npx tfx-cli extension publish --manifests vss-extension.json --vsix dist/*.vsix" + "package": "node vss-extension.version.increment.js && npx tfx-cli extension create --manifests vss-extension.json --output-path dist", + "package:dev": "npx tfx-cli extension create --manifests vss-extension.json --output-path dist/dev --overrides-file vss-extension.overrides.dev.json", + "package:prod": "npx tfx-cli extension create --manifests vss-extension.json --output-path dist/prod --overrides-file vss-extension.overrides.prod.json" }, "keywords": [ "azure", diff --git a/task/task.json b/task/task.json index 84f0c11..50d72d0 100644 --- a/task/task.json +++ b/task/task.json @@ -218,4 +218,4 @@ "target": "index.js" } } -} \ No newline at end of file +} diff --git a/vss-extension.json b/vss-extension.json index 58810d0..3b5e531 100644 --- a/vss-extension.json +++ b/vss-extension.json @@ -1,8 +1,11 @@ { "manifestVersion": 1, - "id": "sbom-tool", - "name": "SBOM Tool", + "publisher": "rhyskoedijk", + "id": "sbom-tool-local", + "name": "SBOM Tool [LOCALHOST]", "description": "SBOM Tool. Generate SPDX 2.2 compatible SBOMs from Azure DevOps repository artifacts.", + "version": "1.0.0", + "public": false, "scopes": ["vso.build"], "targets": [ { @@ -76,6 +79,7 @@ "path": "README.md" } }, + "baseUri": "https://localhost:3000/", "files": [ { "path": "task/task.json" diff --git a/vss-extension.overrides.dev.json b/vss-extension.overrides.dev.json index e372224..f2c3d52 100644 --- a/vss-extension.overrides.dev.json +++ b/vss-extension.overrides.dev.json @@ -1,8 +1,7 @@ { - "publisher": "rhyskoedijk", "id": "sbom-tool-dev", "name": "SBOM Tool [DEV]", - "version": "1.0.0", - "baseUri": "https://localhost:3000/", - "public": false + "version": "#{MAJOR_MINOR_PATCH}#.#{BUILD_NUMBER}#", + "public": false, + "baseUri": null } diff --git a/vss-extension.overrides.prod.json b/vss-extension.overrides.prod.json index 9d2887c..27ccbbf 100644 --- a/vss-extension.overrides.prod.json +++ b/vss-extension.overrides.prod.json @@ -1,5 +1,7 @@ { - "publisher": "rhyskoedijk", - "version": "1.0.0", - "public": true + "id": "sbom-tool", + "name": "SBOM Tool", + "version": "#{MAJOR_MINOR_PATCH}#.#{BUILD_NUMBER}#", + "public": true, + "baseUri": null } diff --git a/vss-extension.version.increment.js b/vss-extension.version.increment.js new file mode 100644 index 0000000..49aacbb --- /dev/null +++ b/vss-extension.version.increment.js @@ -0,0 +1,19 @@ +const fs = require('fs'); +const path = require('path'); + +function incrementPatchVersion(vssExtensionJsonPath, taskJsonPath) { + const vssExtensionJson = JSON.parse(fs.readFileSync(vssExtensionJsonPath)); + const taskJson = JSON.parse(fs.readFileSync(taskJsonPath)); + const version = taskJson.version || { Major: 1, Minor: 0, Patch: 0 }; + version.Patch += 1; + if (taskJson) { + taskJson.version = version; + fs.writeFileSync(taskJsonPath, JSON.stringify(taskJson, null, 2)); + } + if (vssExtensionJson) { + vssExtensionJson.version = taskJson.version.Major + '.' + taskJson.version.Minor + '.' + taskJson.version.Patch; + fs.writeFileSync(vssExtensionJsonPath, JSON.stringify(vssExtensionJson, null, 2)); + } +} + +incrementPatchVersion(path.join(__dirname, 'vss-extension.json'), path.join(__dirname, 'task', 'task.json'));