Skip to content

Commit c94ccd3

Browse files
authored
fix(ci): Auto release (#969)
## What does this do? Cleans up release and sets up auto release
1 parent 49191fd commit c94ccd3

File tree

2 files changed

+39
-25
lines changed

2 files changed

+39
-25
lines changed

.github/workflows/release-please.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ jobs:
1616
release_created: ${{ steps.release.outputs.release_created }}
1717
version: ${{ steps.release.outputs.version }}
1818
steps:
19+
- name: Generate Deploy Bot token
20+
id: generate-token
21+
uses: actions/create-github-app-token@v1
22+
with:
23+
app-id: ${{ secrets.DEPLOYMENT_APP_ID }}
24+
private-key: ${{ secrets.DEPLOYMENT_APP_PRIVATE_KEY }}
1925
- name: Checkout
2026
uses: actions/checkout@v6
2127
with:
@@ -24,5 +30,6 @@ jobs:
2430
id: release
2531
uses: googleapis/release-please-action@v4
2632
with:
33+
token: ${{ steps.generate-token.outputs.token }}
2734
release-type: node
28-
config-file: release-please-config.json
35+
config-file: ./release-please-config.json

.github/workflows/release.yml

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,39 @@ on:
55
types: [published]
66
workflow_dispatch:
77

8+
permissions:
9+
contents: read
10+
811
jobs:
912
deploy:
1013
name: Deploy Changes (Update Database)
1114
runs-on: ubuntu-latest
12-
if: ${{ github.repository == '5e-bits/5e-database' }}
15+
if: github.repository == '5e-bits/5e-database'
16+
outputs:
17+
tag: ${{ steps.tag.outputs.tag }}
1318
steps:
19+
- name: Determine Release Tag
20+
id: tag
21+
run: |
22+
if [ "${{ github.event_name }}" = "release" ]; then
23+
echo "tag=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
24+
else
25+
# For workflow_dispatch, get the latest release tag
26+
LATEST_TAG=$(gh api repos/${{ github.repository }}/releases/latest --jq .tag_name)
27+
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
28+
fi
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1431
- name: Checkout repository
1532
uses: actions/checkout@v6
1633
with:
34+
ref: ${{ steps.tag.outputs.tag }}
1735
fetch-depth: 2
1836
- name: Set up Node.js 22.x
1937
uses: actions/setup-node@v6
2038
with:
2139
node-version: 22.x
22-
cache: 'npm'
40+
cache: "npm"
2341
- name: Install dependencies
2442
run: npm ci
2543
- name: Run Database Update Script
@@ -31,7 +49,7 @@ jobs:
3149
name: Container Release
3250
runs-on: ubuntu-latest
3351
needs: [deploy]
34-
if: ${{ github.repository == '5e-bits/5e-database' }}
52+
if: github.repository == '5e-bits/5e-database'
3553
env:
3654
REGISTRY: ghcr.io
3755
IMAGE_NAME: ${{ github.repository }}
@@ -42,18 +60,7 @@ jobs:
4260
- name: Checkout repository
4361
uses: actions/checkout@v6
4462
with:
45-
fetch-depth: 0
46-
- name: Get version from package.json
47-
id: version
48-
run: |
49-
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.version }}" ]; then
50-
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
51-
elif [ "${{ github.event_name }}" = "release" ]; then
52-
echo "version=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
53-
else
54-
VERSION=$(node -p "require('./package.json').version")
55-
echo "version=$VERSION" >> $GITHUB_OUTPUT
56-
fi
63+
ref: ${{ needs.deploy.outputs.tag }}
5764
- name: Log in to the Container registry
5865
uses: docker/login-action@v3
5966
with:
@@ -65,24 +72,24 @@ jobs:
6572
with:
6673
context: .
6774
push: true
68-
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
69-
labels: version=${{ steps.version.outputs.version }}
75+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.deploy.outputs.tag }},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
76+
labels: version=${{ needs.deploy.outputs.tag }}
7077

7178
trigger-downstream:
7279
name: Trigger Downstream
7380
runs-on: ubuntu-latest
7481
needs: [deploy, container-release]
75-
if: ${{ github.repository == '5e-bits/5e-database' }}
82+
if: github.repository == '5e-bits/5e-database'
7683
steps:
77-
- name: Generate GitHub App Token
78-
id: generate_token
79-
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a
84+
- name: Generate Deploy Bot token
85+
id: generate-token
86+
uses: actions/create-github-app-token@v1
8087
with:
81-
app_id: ${{ secrets.DEPLOYMENT_APP_ID }}
82-
private_key: ${{ secrets.DEPLOYMENT_APP_PRIVATE_KEY }}
88+
app-id: ${{ secrets.DEPLOYMENT_APP_ID }}
89+
private-key: ${{ secrets.DEPLOYMENT_APP_PRIVATE_KEY }}
8390
- name: Trigger downstream
8491
uses: peter-evans/repository-dispatch@v4
8592
with:
86-
token: ${{ steps.generate_token.outputs.token }}
93+
token: ${{ steps.generate-token.outputs.token }}
8794
repository: 5e-bits/5e-srd-api
8895
event-type: build_application

0 commit comments

Comments
 (0)