Skip to content

Commit c9c30f4

Browse files
committed
Rework the build process
1 parent e9d5303 commit c9c30f4

18 files changed

Lines changed: 29738 additions & 109 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Artifact Exists
2+
description: Check if a specific artifact exists in the workflow run.
3+
4+
inputs:
5+
artifact_name:
6+
description: The name of the artifact to check for.
7+
required: true
8+
github_token:
9+
description: "Your GitHub Access Token"
10+
required: true
11+
default: ${{ github.token }}
12+
13+
outputs:
14+
exists:
15+
description: Indicates whether the artifact exists or not.
16+
value: ${{ steps.check.outputs.exists }}
17+
18+
runs:
19+
using: "composite"
20+
21+
steps:
22+
- name: Check if artifact exists
23+
shell: bash
24+
id: check
25+
run: |
26+
if gh api /repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/artifacts \
27+
| jq -e ".artifacts[] | select(.name == \"$ARTIFACT_NAME\")" > /dev/null; then
28+
echo "exists=true" >> "$GITHUB_OUTPUT"
29+
else
30+
echo "exists=false" >> "$GITHUB_OUTPUT"
31+
fi
32+
env:
33+
GH_TOKEN: ${{ inputs.github_token }}
34+
ARTIFACT_NAME: ${{ inputs.artifact_name }}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Download Build
2+
description: Download the OpenAPI and Webpack build artifacts.
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Remove Existing Files
8+
shell: bash
9+
run: |
10+
rm -rf openapi.yaml openapi.dereferenced.yaml dist
11+
- name: Download OpenAPI artifact
12+
uses: actions/download-artifact@v4
13+
with:
14+
name: openapi.yaml
15+
- name: Download OpenAPI Dereferenced artifact
16+
uses: actions/download-artifact@v4
17+
with:
18+
name: openapi.dereferenced.yaml
19+
- name: Download OpenAPI Webpack artifact
20+
uses: actions/download-artifact@v4
21+
with:
22+
name: webpack
23+
path: dist

.github/actions/pnpm/action.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: PNPM
2+
description: Initialize PNPM, install dependencies, and set up caching.
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- uses: actions/checkout@v4
8+
- uses: pnpm/action-setup@v2
9+
with:
10+
version: latest
11+
- name: Get store directory
12+
shell: bash
13+
run: |
14+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
15+
- uses: actions/cache@v3
16+
name: Setup cache
17+
with:
18+
path: ${{ env.STORE_PATH }}
19+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
20+
restore-keys: |
21+
${{ runner.os }}-pnpm-store-
22+
- name: Install Dependencies
23+
shell: bash
24+
run: pnpm i --frozen-lockfile --ignore-scripts

.github/workflows/build.yml

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,78 @@
11
name: Build
22
on:
3-
push:
4-
branches:
5-
- master
6-
pull_request:
7-
branches:
8-
- master
93
workflow_dispatch:
4+
workflow_call:
5+
6+
permissions:
7+
actions: write
8+
contents: read
109

1110
jobs:
12-
build-openapi:
11+
pre:
1312
runs-on: ubuntu-latest
14-
name: Build OpenAPI
13+
name: Check Artifacts
14+
outputs:
15+
openapi: ${{ steps.openapi.outputs.exists }}
16+
openapi_dereferenced: ${{ steps.openapi_dereferenced.outputs.exists }}
17+
webpack: ${{ steps.webpack.outputs.exists }}
1518
steps:
16-
- uses: actions/checkout@v3
17-
- uses: pnpm/action-setup@v2
19+
- uses: actions/checkout@v4
20+
- uses: ./.github/actions/artifact-exists
21+
id: openapi
22+
with:
23+
artifact_name: openapi.yaml
24+
- uses: ./.github/actions/artifact-exists
25+
id: openapi_dereferenced
1826
with:
19-
version: latest
20-
- name: Install Dependencies
21-
run: pnpm i --frozen-lockfile --ignore-scripts
27+
artifact_name: openapi.dereferenced.yaml
28+
- uses: ./.github/actions/artifact-exists
29+
id: webpack
30+
with:
31+
artifact_name: webpack
32+
33+
openapi:
34+
runs-on: ubuntu-latest
35+
name: Build OpenAPI
36+
needs: pre
37+
if: needs.pre.outputs.openapi != 'true' || needs.pre.outputs.openapi_dereferenced != 'true'
38+
steps:
39+
- uses: actions/checkout@v4
40+
- uses: ./.github/actions/pnpm
2241
- name: Build
2342
run: pnpm run build:openapi
24-
build-webpack:
43+
- name: Upload OpenAPI
44+
uses: actions/upload-artifact@v4
45+
with:
46+
path: openapi.yaml
47+
overwrite: true
48+
if-no-files-found: error
49+
compression-level: 0
50+
name: openapi.yaml
51+
# dereferencing catches circular reference issues
52+
- name: Build (Dereferenced)
53+
run: pnpm run build:openapi:dereferenced
54+
- name: Upload OpenAPI
55+
uses: actions/upload-artifact@v4
56+
with:
57+
path: openapi.dereferenced.yaml
58+
overwrite: true
59+
if-no-files-found: error
60+
compression-level: 0
61+
name: openapi.dereferenced.yaml
62+
webpack:
2563
runs-on: ubuntu-latest
2664
name: Build Webpack
65+
needs: pre
66+
if: needs.pre.outputs.webpack != 'true'
2767
steps:
28-
- uses: actions/checkout@v3
29-
- uses: pnpm/action-setup@v2
30-
with:
31-
version: latest
32-
- name: Install Dependencies
33-
run: pnpm i --frozen-lockfile --ignore-scripts
68+
- uses: actions/checkout@v4
69+
- uses: ./.github/actions/pnpm
3470
- name: Build
35-
run: pnpm run build:webpack
71+
run: NODE_ENV=production pnpm run build:webpack
72+
- name: Upload Webpack
73+
uses: actions/upload-artifact@v4
74+
with:
75+
path: dist
76+
overwrite: true
77+
if-no-files-found: error
78+
name: webpack

.github/workflows/deploy.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
name: Deploy Github Pages
22
on:
3-
push:
4-
branches:
5-
- master
63
workflow_dispatch:
4+
workflow_call:
5+
inputs:
6+
commit:
7+
type: string
78

89
jobs:
910
build:
1011
runs-on: ubuntu-latest
1112
steps:
12-
- uses: actions/checkout@v3
13-
- uses: pnpm/action-setup@v2
13+
- uses: actions/checkout@v4
1414
with:
15-
version: latest
16-
- name: Install Dependencies
17-
run: pnpm i --frozen-lockfile --ignore-scripts
18-
- name: Build
19-
run: pnpm run build:production
15+
ref: ${{ inputs.commit || github.ref_name }}
16+
- uses: ./.github/actions/pnpm
17+
- name: Build Webpack
18+
run: pnpm run build:webpack:production
2019
- name: Upload Build
2120
uses: actions/upload-pages-artifact@v3
2221
with:

.github/workflows/lint.yml

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,38 @@
11
name: Lint
22
on:
3-
push:
4-
branches:
5-
- master
6-
pull_request:
7-
branches:
8-
- master
93
workflow_dispatch:
4+
workflow_call:
105

116
jobs:
12-
lint:
7+
build:
8+
uses: ./.github/workflows/build.yml
9+
code:
1310
runs-on: ubuntu-latest
1411
name: Lint Code
12+
needs: build
1513
steps:
16-
- uses: actions/checkout@v3
17-
- uses: pnpm/action-setup@v2
18-
with:
19-
version: latest
20-
- name: Install Dependencies
21-
run: pnpm i --frozen-lockfile --ignore-scripts
22-
- name: Build
23-
run: pnpm run build
14+
- uses: actions/checkout@v4
15+
- uses: ./.github/actions/pnpm
16+
- uses: ./.github/actions/download-build
2417
- name: Lint
2518
run: pnpm run lint
26-
lint-api:
19+
api:
2720
runs-on: ubuntu-latest
2821
name: Lint API
22+
needs: build
2923
steps:
30-
- uses: actions/checkout@v3
31-
- uses: pnpm/action-setup@v2
32-
with:
33-
version: latest
34-
- name: Install Dependencies
35-
run: pnpm i --frozen-lockfile --ignore-scripts
36-
- name: Build
37-
run: pnpm run build
24+
- uses: actions/checkout@v4
25+
- uses: ./.github/actions/pnpm
26+
- uses: ./.github/actions/download-build
3827
- name: Lint
3928
run: pnpm run lint:api
29+
validate:
30+
runs-on: ubuntu-latest
31+
name: Validate API
32+
needs: build
33+
steps:
34+
- uses: actions/checkout@v4
35+
- uses: ./.github/actions/pnpm
36+
- uses: ./.github/actions/download-build
37+
- name: Lint
38+
run: pnpm run lint:validate

.github/workflows/pull_request.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Pull Request
2+
on:
3+
pull_request:
4+
branches:
5+
- master
6+
7+
jobs:
8+
build:
9+
name: Build
10+
uses: ./.github/workflows/build.yml
11+
lint:
12+
name: Lint
13+
needs: build
14+
uses: ./.github/workflows/lint.yml

.github/workflows/push.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Push
2+
on:
3+
push:
4+
branches:
5+
- master
6+
7+
jobs:
8+
build:
9+
name: Build
10+
uses: ./.github/workflows/build.yml
11+
lint:
12+
needs: [build]
13+
name: Lint
14+
uses: ./.github/workflows/lint.yml
15+
update-api-version:
16+
name: Update API Version
17+
uses: ./.github/workflows/update-api-version.yml
18+
needs: [lint]
19+
deploy:
20+
name: Deploy
21+
uses: ./.github/workflows/deploy.yml
22+
needs: [update-api-version]
23+
with:
24+
commit: ${{ needs.update-api-version.outputs.commit }}
Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,53 @@
11
name: Update API Version
22

33
on:
4-
push:
5-
branches:
6-
- master
4+
workflow_call:
5+
outputs:
6+
commit:
7+
value: ${{ jobs.update-api-version.outputs.commit }}
78
workflow_dispatch:
89

910
jobs:
1011
update-api-version:
12+
name: Update API Version
1113
runs-on: ubuntu-latest
12-
if: github.actor != 'github-actions[bot]'
1314
permissions:
1415
contents: write
16+
outputs:
17+
commit: ${{ steps.commit.outputs.commit_hash }}
1518
steps:
16-
- uses: actions/checkout@v3
17-
- uses: pnpm/action-setup@v2
19+
- uses: actions/checkout@v4
1820
with:
19-
version: latest
20-
- name: Install Dependencies
21-
run: pnpm i --frozen-lockfile --ignore-scripts
22-
# https://github.com/mikefarah/yq/issues/515 - yq strips whitespace
23-
# https://github.com/mikefarah/yq/issues/515#issuecomment-1050637663
21+
fetch-depth: 0
22+
- uses: ./.github/actions/pnpm
23+
- name: Set Version
24+
shell: bash
25+
run: |
26+
SHA=$(git rev-parse --short $GITHUB_REF_NAME)
27+
echo "API_VERSION=${SHA}" >> $GITHUB_ENV
2428
- name: Update API Version
2529
uses: mikefarah/yq@v4
2630
with:
2731
cmd: |
28-
apk add --no-cache git patch
29-
SHA=$(git rev-parse --short master) yq ".info.version = strenv(SHA)" api/api.yaml > api/new.yaml
32+
yq ".info.version = strenv(API_VERSION)" api/api.yaml > api/new.yaml
3033
yq '.' api/api.yaml > api/noblanks.yaml
31-
diff -B api/noblanks.yaml api/new.yaml > api/new.patch
32-
patch api/api.yaml api/new.patch
34+
# https://github.com/mikefarah/yq/issues/515 - yq strips whitespace
35+
# https://github.com/mikefarah/yq/issues/515#issuecomment-1050637663
36+
- name: Apply Version
37+
run: |
38+
diff -B api/noblanks.yaml api/new.yaml > api/new.patch || true # diff exits with 1 if the files have differences
39+
patch api/api.yaml api/new.patch
40+
- name: Build OpenAPI
41+
run: pnpm run build:openapi
42+
- name: Build OpenAPI (Dereferenced)
43+
run: pnpm run build:openapi:dereferenced
3344
- name: Commit Changes
45+
id: commit
3446
uses: stefanzweifel/git-auto-commit-action@v6
3547
with:
3648
commit_message: "Update API Version"
37-
file_pattern: "api/api.yaml"
49+
file_pattern: "api/api.yaml openapi.yaml openapi.dereferenced.yaml"
3850
disable_globbing: true
51+
commit_user_name: "github-actions[bot]"
52+
commit_user_email: "41898282+github-actions[bot]@users.noreply.github.com"
53+
commit_author: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
node_modules
22
dist
33
compile-doc.sh
4-
_build
4+
_build
5+
.vscode
6+
.idea

0 commit comments

Comments
 (0)