Skip to content

chore: update CI workflow to pack plugin with custom output filename #471

chore: update CI workflow to pack plugin with custom output filename

chore: update CI workflow to pack plugin with custom output filename #471

Workflow file for this run

name: Test
# This workflow will lint and test a plugin whenever it or CI changes.
on:
push:
branches:
- main
pull_request:
branches:
- main
# Cancel in-progress runs for pull requests when developers push changes.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
changes:
runs-on: ubuntu-latest
outputs:
plugins: ${{ steps.filter.outputs.changes }}
steps:
# Pull requests do not need to check out the code to detect changes
# because the action fetches changed files through the API.
- uses: actions/checkout@v4
if: github.event_name != 'pull_request'
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
backstage-plugin-coder:
- ".github/workflows/test.yaml"
- "yarn.lock"
- "plugins/backstage-plugin-coder/**"
backstage-plugin-devcontainers-backend:
- ".github/workflows/test.yaml"
- "yarn.lock"
- "plugins/backstage-plugin-devcontainers-backend/**"
backstage-plugin-devcontainers-react:
- ".github/workflows/test.yaml"
- "yarn.lock"
- "plugins/backstage-plugin-devcontainers-react/**"
auth-backend-module-coder-provider:
- ".github/workflows/test.yaml"
- "yarn.lock"
- "plugins/auth-backend-module-coder-provider/**"
plugin:
needs: changes
if: ${{ needs.changes.outputs.plugins != '' && toJson(fromJson(needs.changes.outputs.plugins)) != '[]' }}
runs-on: ubuntu-latest
strategy:
matrix:
plugin: ${{ fromJSON(needs.changes.outputs.plugins) }}
name: ${{ matrix.plugin }}
defaults:
run:
working-directory: plugins/${{ matrix.plugin }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: yarn
- run: yarn install --frozen-lockfile
# The Prettier command is in the root package.json.
- run: yarn prettier --check plugins/${{ matrix.plugin }}
id: fmt
working-directory: .
- run: yarn lint
id: lint
# It could be annoying to not see the test results because of formatting
# errors, so keep running even on failures (we will catch failures at
# the end of the job). continue-on-error would be ideal but that marks
# the step as successful which is not what we want.
if: success() || failure()
- run: yarn test
id: test
if: success() || failure()
# Run tsc from repository root to generate shared .d.ts files for all plugins
- run: yarn tsc
working-directory: ${{ github.workspace }}
if: success() || failure()
# Build the plugin
- run: yarn build
id: build
if: success() || failure()
# Version it with the SHA and upload to the run as an artifact in case
# someone needs to download it for testing.
- name: Set development version
id: version
run: |
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
node -e "const fs=require('fs'); const pkg=JSON.parse(fs.readFileSync('package.json')); pkg.version='dev-${SHORT_SHA}'; fs.writeFileSync('package.json', JSON.stringify(pkg,null,2)+'\n');"
echo "Set version to dev-${SHORT_SHA}"
- name: Pack plugin
id: pack
run: yarn pack --out '%s-%v.tgz'
- uses: actions/upload-artifact@v4
id: upload
with:
name: ${{ matrix.plugin }}
path: plugins/${{ matrix.plugin }}/*.tgz
# Since we continued on failures above, fail now if there were errors. We
# allow skipped jobs to pass, but not failed or cancelled jobs.
- name: Check required
if: success() || failure()
run: |
echo "- fmt: ${{ steps.fmt.outcome }}"
echo "- lint: ${{ steps.lint.outcome }}"
echo "- test: ${{ steps.test.outcome }}"
echo "- build: ${{ steps.build.outcome }}"
echo "- version: ${{ steps.version.outcome }}"
echo "- pack: ${{ steps.pack.outcome }}"
echo "- upload: ${{ steps.upload.outcome }}"
if [[ "${{ contains(steps.*.outcome, 'failure') }}" == "true" || "${{ contains(steps.*.outcome, 'cancelled') }}" == "true" ]]; then
echo "One or more required checks have failed or have been cancelled"
exit 1
fi
echo "Required checks have passed"