Skip to content

Commit 2cd1098

Browse files
authored
Set up CI for plugins (#10)
This will lint, test, and publish individual plugins.
1 parent f2b82a1 commit 2cd1098

File tree

12 files changed

+192
-27
lines changed

12 files changed

+192
-27
lines changed

.github/workflows/publish.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Publish
2+
3+
# This workflow will publish releases published on GitHub to NPM.
4+
5+
on:
6+
release:
7+
types:
8+
- released
9+
workflow_dispatch:
10+
inputs:
11+
tag:
12+
description: The tag to publish (for example "coder/v0.0.0")
13+
type: string
14+
required: true
15+
16+
concurrency: ${{ github.workflow }}-${{ github.ref }}
17+
18+
jobs:
19+
npm:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: robinraju/release-downloader@v1.9
23+
with:
24+
tag: ${{ github.event.inputs.tag || github.ref_name }}
25+
fileName: "*.tgz"
26+
# Although we are publishing the tarball, yarn will not actually look at
27+
# the package.json in the tarball so we have to extract it first.
28+
- run: tar -xf *.tgz
29+
- run: mv package/package.json package.json
30+
- run: yarn publish *.tgz
31+
env:
32+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/release.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Release
2+
3+
# This workflow will draft a release for a plugin when tagged. The tag format
4+
# is <name>/v<version> without the backstage-plugin- prefix, e.g. coder/v0.0.0
5+
6+
on:
7+
push:
8+
tags:
9+
- "*/v*"
10+
11+
permissions:
12+
contents: write # For creating releases.
13+
14+
concurrency: ${{ github.workflow }}-${{ github.ref }}
15+
16+
jobs:
17+
split-tag:
18+
runs-on: ubuntu-latest
19+
outputs:
20+
plugin: ${{ steps.split.outputs.plugin }}
21+
version: ${{ steps.split.outputs.version }}
22+
steps:
23+
- env:
24+
TAG: ${{ github.ref_name }}
25+
id: split
26+
run: |
27+
parts=(${TAG//\/v/ })
28+
echo "plugin=${parts[0]}" >> $GITHUB_OUTPUT
29+
echo "version=${parts[1]}" >> $GITHUB_OUTPUT
30+
plugin:
31+
needs: split-tag
32+
runs-on: ubuntu-latest
33+
defaults:
34+
run:
35+
working-directory: plugins/backstage-plugin-${{ needs.split-tag.outputs.plugin }}
36+
name: ${{ needs.split-tag.outputs.plugin }} v${{ needs.split-tag.outputs.version }}
37+
steps:
38+
- uses: actions/checkout@v4
39+
- uses: actions/setup-node@v4
40+
with:
41+
node-version-file: .node-version
42+
cache: yarn
43+
- run: yarn install --frozen-lockfile
44+
- run: yarn lint
45+
- run: yarn tsc
46+
- run: yarn test
47+
- run: yarn build
48+
# Version it with the version in the tag and upload it to a draft release.
49+
- run: yarn version --new-version ${{ needs.split-tag.outputs.version }}
50+
- run: yarn pack
51+
- uses: softprops/action-gh-release@v1
52+
with:
53+
draft: true
54+
files: plugins/backstage-plugin-${{ needs.split-tag.outputs.plugin }}/*.tgz

.github/workflows/test.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Test
2+
3+
# This workflow will lint and test a plugin whenever it or CI changes.
4+
5+
on:
6+
push:
7+
branches:
8+
- main
9+
pull_request:
10+
branches:
11+
- main
12+
13+
# Cancel in-progress runs for pull requests when developers push changes.
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
17+
18+
jobs:
19+
changes:
20+
runs-on: ubuntu-latest
21+
outputs:
22+
plugins: ${{ steps.filter.outputs.changes }}
23+
steps:
24+
# Pull requests do not need to check out the code to detect changes
25+
# because the action fetches changed files through the API.
26+
- uses: actions/checkout@v4
27+
if: github.event_name != 'pull_request'
28+
- uses: dorny/paths-filter@v3
29+
id: filter
30+
with:
31+
filters: |
32+
coder:
33+
- ".github/workflows/build.yaml"
34+
- "plugins/backstage-plugin-coder/**"
35+
plugin:
36+
needs: changes
37+
runs-on: ubuntu-latest
38+
strategy:
39+
matrix:
40+
plugin: ${{ fromJSON(needs.changes.outputs.plugins) }}
41+
name: ${{ matrix.plugin }}
42+
defaults:
43+
run:
44+
working-directory: plugins/backstage-plugin-${{ matrix.plugin }}
45+
steps:
46+
- uses: actions/checkout@v4
47+
- uses: actions/setup-node@v4
48+
with:
49+
node-version-file: .node-version
50+
cache: yarn
51+
- run: yarn install --frozen-lockfile
52+
- run: yarn lint
53+
- run: yarn tsc
54+
- run: yarn test
55+
- run: yarn build
56+
# Version it with the SHA and upload to the run as an artifact in case
57+
# someone needs to download it for testing.
58+
- run: yarn version --new-version "0.0.0-devel+$GITHUB_SHA"
59+
- run: yarn pack
60+
- uses: actions/upload-artifact@v4
61+
with:
62+
name: ${{ matrix.plugin }}
63+
path: plugins/backstage-plugin-${{ matrix.plugin }}/*.tgz

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
18.19.0

.yarnrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# We add the tags ourselves and do not commit the version bump; prevent Yarn
2+
# from trying to do so.
3+
version-git-tag false
4+
version-commit-hooks false

README.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
11
# [Backstage](https://backstage.io)
22

3-
This is your newly scaffolded Backstage App, Good Luck!
3+
## Contributing
44

5-
To start the app, run:
5+
To start the app:
66

77
```sh
88
yarn install
99
yarn dev
1010
```
11+
12+
To run an individual plugin:
13+
14+
```sh
15+
cd plugins/backstage-plugin-$name
16+
yarn install
17+
yarn start
18+
```
19+
20+
Note that the Coder plugin does not support running like this as it currently
21+
uses a backend proxy that is not available when running independently of the
22+
Backstage app.
23+
24+
## Releasing
25+
26+
To draft a release for a plugin push a tag named `$name/v$version` without the
27+
`backstage-plugin-` prefix. For example:
28+
29+
```sh
30+
git tag -a coder/v0.0.0 -m "coder v0.0.0"
31+
git push origin coder/v0.0.0
32+
```
33+
34+
This will kick off an action that will create a draft release for the plugin.
35+
Once you have reviewed the release you can publish it and another action will
36+
publish the plugin to NPM.

packages/app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"@backstage/plugin-techdocs-react": "^1.1.15",
4040
"@backstage/plugin-user-settings": "^0.8.0",
4141
"@backstage/theme": "^0.5.0",
42-
"@coder/backstage-plugin-coder": "^0.1.0",
42+
"@coder/backstage-plugin-coder": "^0.0.0",
4343
"@material-ui/core": "^4.12.2",
4444
"@material-ui/icons": "^4.9.1",
4545
"history": "^5.0.0",

packages/app/src/App.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,6 @@ const app = createApp({
7979
},
8080
});
8181

82-
/**
83-
* 2024-02-13 - The version of TechDocsAddons that Backstage ships with makes
84-
* the TypeScript compiler complain when you try to render it as JSX. This seems
85-
* like it's just a type mismatch issue, and things still work at runtime
86-
*/
87-
const FixedTechDocsAddons = TechDocsAddons as React.FC<unknown>;
88-
8982
const routes = (
9083
<FlatRoutes>
9184
<Route path="/" element={<Navigate to="catalog" />} />
@@ -101,9 +94,9 @@ const routes = (
10194
path="/docs/:namespace/:kind/:name/*"
10295
element={<TechDocsReaderPage />}
10396
>
104-
<FixedTechDocsAddons>
97+
<TechDocsAddons>
10598
<ReportIssue />
106-
</FixedTechDocsAddons>
99+
</TechDocsAddons>
107100
</Route>
108101
<Route path="/create" element={<ScaffolderPage />} />
109102
<Route path="/api-docs" element={<ApiExplorerPage />} />

packages/app/src/components/catalog/EntityPage.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,11 @@ import { ReportIssue } from '@backstage/plugin-techdocs-module-addons-contrib';
6060

6161
import { CoderWorkspacesCard } from '@coder/backstage-plugin-coder';
6262

63-
/**
64-
* 2024-02-13 - The version of TechDocsAddons that Backstage ships with makes
65-
* the TypeScript compiler complain when you try to render it as JSX. This seems
66-
* like it's just a type mismatch issue, and things still work at runtime
67-
*/
68-
const FixedTechDocsAddons = TechDocsAddons as React.FC<unknown>;
69-
7063
const techdocsContent = (
7164
<EntityTechdocsContent>
72-
<FixedTechDocsAddons>
65+
<TechDocsAddons>
7366
<ReportIssue />
74-
</FixedTechDocsAddons>
67+
</TechDocsAddons>
7568
</EntityTechdocsContent>
7669
);
7770

plugins/backstage-plugin-coder/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coder/backstage-plugin-coder",
3-
"version": "0.1.0",
3+
"version": "0.0.0",
44
"main": "src/index.ts",
55
"types": "src/index.ts",
66
"license": "Apache-2.0",

plugins/backstage-plugin-coder/src/components/CoderErrorBoundary/CoderErrorBoundary.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, {
22
type ErrorInfo,
3-
type FC,
43
type ReactNode,
54
Component,
65
} from 'react';
@@ -39,7 +38,7 @@ class ErrorBoundaryCore extends Component<
3938
}
4039

4140
componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
42-
this.props.onError(error, errorInfo.componentStack);
41+
this.props.onError(error, errorInfo.componentStack || "no details");
4342
}
4443

4544
render() {
@@ -53,10 +52,10 @@ type CoderErrorBoundaryProps = {
5352
fallbackUi?: ReactNode;
5453
};
5554

56-
export const CoderErrorBoundary: FC<CoderErrorBoundaryProps> = ({
55+
export const CoderErrorBoundary = ({
5756
children,
5857
fallbackUi,
59-
}) => {
58+
}: CoderErrorBoundaryProps) => {
6059
const errorApi = useApi(errorApiRef);
6160
const fallbackContent = fallbackUi ?? <FallbackUi />;
6261

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9571,7 +9571,7 @@ anymatch@^3.0.3, anymatch@~3.1.2:
95719571
"@backstage/plugin-techdocs-react" "^1.1.15"
95729572
"@backstage/plugin-user-settings" "^0.8.0"
95739573
"@backstage/theme" "^0.5.0"
9574-
"@coder/backstage-plugin-coder" "^0.1.0"
9574+
"@coder/backstage-plugin-coder" "^0.0.0"
95759575
"@material-ui/core" "^4.12.2"
95769576
"@material-ui/icons" "^4.9.1"
95779577
history "^5.0.0"

0 commit comments

Comments
 (0)