Skip to content

Commit

Permalink
Update CI/CD pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyskoedijk committed Nov 8, 2024
1 parent 09f7f5a commit d929e95
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 23 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: Build Extension
name: Build

on:
push:
branches: [main]
tags: ['*']
pull_request:
branches: [main]

Expand All @@ -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
3 changes: 0 additions & 3 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ on:
pull_request:
branches: [main]

permissions:
contents: read

jobs:
codespell:
name: Check for spelling errors
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -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
104 changes: 104 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
versionSpec: '6.x'

- name: Determine version
id: gitversion
uses: gittools/actions/gitversion/[email protected]
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 }}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion task/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,4 @@
"target": "index.js"
}
}
}
}
8 changes: 6 additions & 2 deletions vss-extension.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down Expand Up @@ -76,6 +79,7 @@
"path": "README.md"
}
},
"baseUri": "https://localhost:3000/",
"files": [
{
"path": "task/task.json"
Expand Down
7 changes: 3 additions & 4 deletions vss-extension.overrides.dev.json
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 5 additions & 3 deletions vss-extension.overrides.prod.json
Original file line number Diff line number Diff line change
@@ -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
}
19 changes: 19 additions & 0 deletions vss-extension.version.increment.js
Original file line number Diff line number Diff line change
@@ -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'));

0 comments on commit d929e95

Please sign in to comment.