Skip to content

Commit

Permalink
Set up CI for plugins
Browse files Browse the repository at this point in the history
This will lint, test, and publish individual plugins.
  • Loading branch information
code-asher committed Feb 24, 2024
1 parent f2b82a1 commit deac4f3
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 5 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Publish

# This workflow will publish releases published on GitHub to NPM.

on:
release:
types:
- released
workflow_dispatch:
inputs:
tag:
description: The tag to publish (for example "coder/v0.0.0")
type: string
required: true

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
npm:
runs-on: ubuntu-latest
steps:
- uses: robinraju/release-downloader@v1.9
with:
tag: ${{ github.event.inputs.tag || github.ref_name }}
fileName: "*.tgz"
- run: yarn publish *.tgz
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
54 changes: 54 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Release

# This workflow will draft a release for a plugin when tagged.
# The tag format is <name>/v<version> without the backstage-plugin- prefix.

on:
push:
tags:
- "*/v*"

permissions:
contents: write # For creating releases.

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
split-tag:
runs-on: ubuntu-latest
outputs:
plugin: ${{ steps.split.outputs.plugin }}
version: ${{ steps.split.outputs.version }}
steps:
- env:
TAG: ${{ github.ref_name }}
id: split
run: |
parts=(${TAG//\/v/ })
echo "plugin=${parts[0]}" >> $GITHUB_OUTPUT
echo "version=${parts[1]}" >> $GITHUB_OUTPUT
plugin:
needs: split-tag
runs-on: ubuntu-latest
defaults:
run:
working-directory: plugins/backstage-plugin-${{ needs.split-tag.outputs.plugin }}
name: ${{ needs.split-tag.outputs.plugin }} v${{ needs.split-tag.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: yarn
- run: yarn install --frozen-lockfile
- run: yarn lint
- run: yarn tsc
- run: yarn test
- run: yarn build
# Version it with the version in the tag and upload it to a draft release.
- run: yarn version --new-version ${{ needs.split-tag.outputs.version }}
- run: yarn pack
- uses: softprops/action-gh-release@v1
with:
draft: true
files: plugins/backstage-plugin-${{ needs.split-tag.outputs.plugin }}/*.tgz
63 changes: 63 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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: |
coder:
- ".github/workflows/build.yaml"
- "plugins/backstage-plugin-coder/**"
plugin:
needs: changes
runs-on: ubuntu-latest
strategy:
matrix:
plugin: ${{ fromJSON(needs.changes.outputs.plugins) }}
name: ${{ matrix.plugin }}
defaults:
run:
working-directory: plugins/backstage-plugin-${{ 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
- run: yarn lint
- run: yarn tsc
- run: yarn test
- run: yarn build
# Version it with the SHA and upload to the run as an artifact in case
# someone needs to download it for testing.
- run: yarn version --new-version "0.0.0-devel+$GITHUB_SHA"
- run: yarn pack
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.plugin }}
path: plugins/backstage-plugin-${{ matrix.plugin }}/*.tgz
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18.19.0
4 changes: 4 additions & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# We add the tags ourselves and do not commit the version bump; prevent Yarn
# from trying to do so.
version-git-tag false
version-commit-hooks false
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
# [Backstage](https://backstage.io)

This is your newly scaffolded Backstage App, Good Luck!
## Contributing

To start the app, run:
To start the app:

```sh
yarn install
yarn dev
```

To run an individual plugin:

```sh
cd plugins/backstage-plugin-$name
yarn install
yarn start
```

## Releasing

To draft a release for a plugin push a tag named `$name/v$version` without the
`backstage-plugin-` prefix. For example:

```sh
git tag -a coder/v0.0.0 -m "coder v0.0.0"
git push origin coder/v0.0.0
```

This will kick off an action that will create a draft release for the plugin.
Once you have reviewed the release you can publish it and another action will
publish the plugin to NPM.
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@backstage/plugin-techdocs-react": "^1.1.15",
"@backstage/plugin-user-settings": "^0.8.0",
"@backstage/theme": "^0.5.0",
"@coder/backstage-plugin-coder": "^0.1.0",
"@coder/backstage-plugin-coder": "^0.0.0",
"@material-ui/core": "^4.12.2",
"@material-ui/icons": "^4.9.1",
"history": "^5.0.0",
Expand Down
2 changes: 1 addition & 1 deletion plugins/backstage-plugin-coder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coder/backstage-plugin-coder",
"version": "0.1.0",
"version": "0.0.0",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9571,7 +9571,7 @@ anymatch@^3.0.3, anymatch@~3.1.2:
"@backstage/plugin-techdocs-react" "^1.1.15"
"@backstage/plugin-user-settings" "^0.8.0"
"@backstage/theme" "^0.5.0"
"@coder/backstage-plugin-coder" "^0.1.0"
"@coder/backstage-plugin-coder" "^0.0.0"
"@material-ui/core" "^4.12.2"
"@material-ui/icons" "^4.9.1"
history "^5.0.0"
Expand Down

0 comments on commit deac4f3

Please sign in to comment.