Skip to content

Commit fd34eb3

Browse files
authored
ci: skip release when token is missing (#3)
1 parent 892d8b7 commit fd34eb3

6 files changed

Lines changed: 51 additions & 25 deletions

File tree

.github/workflows/release.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,54 @@ jobs:
2020
permissions:
2121
contents: write
2222
pull-requests: write
23+
env:
24+
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
2325
steps:
24-
- name: Require release token
25-
env:
26-
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
26+
- name: Check release token
27+
id: release-token
2728
run: |
2829
set -euo pipefail
2930
if [[ -z "${RELEASE_TOKEN}" ]]; then
30-
echo "::error::Configure RELEASE_TOKEN with permission to push release PR branches and open pull requests."
31-
exit 1
31+
echo "::notice::Skipping release preparation because RELEASE_TOKEN is not configured."
32+
echo "configured=false" >> "$GITHUB_OUTPUT"
33+
exit 0
3234
fi
35+
echo "configured=true" >> "$GITHUB_OUTPUT"
3336
3437
- name: Checkout
38+
if: steps.release-token.outputs.configured == 'true'
3539
uses: actions/checkout@v6
3640
with:
3741
fetch-depth: 0
3842
ref: main
3943

4044
- name: Set up Bun
45+
if: steps.release-token.outputs.configured == 'true'
4146
uses: oven-sh/setup-bun@v2
4247
with:
4348
bun-version: 1.3.14
4449

4550
- name: Install dependencies
51+
if: steps.release-token.outputs.configured == 'true'
4652
run: bun install --frozen-lockfile
4753

4854
- name: Configure release git author
49-
env:
50-
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
55+
if: steps.release-token.outputs.configured == 'true'
5156
run: |
5257
set -euo pipefail
5358
git config user.name "github-actions[bot]"
5459
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
5560
git remote set-url origin "https://x-access-token:${RELEASE_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
5661
5762
- name: Prepare release
63+
if: steps.release-token.outputs.configured == 'true'
5864
id: release
5965
env:
6066
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6167
run: bun run release --no-push --no-github
6268

6369
- name: Ensure release PR runs CI
64-
if: steps.release.outputs.published == 'true'
70+
if: steps.release-token.outputs.configured == 'true' && steps.release.outputs.published == 'true'
6571
run: |
6672
set -euo pipefail
6773
subject="$(git log -1 --pretty=%s)"
@@ -72,7 +78,7 @@ jobs:
7278
fi
7379
7480
- name: Open release PR
75-
if: steps.release.outputs.published == 'true'
81+
if: steps.release-token.outputs.configured == 'true' && steps.release.outputs.published == 'true'
7682
env:
7783
GH_TOKEN: ${{ secrets.RELEASE_TOKEN }}
7884
RELEASE_VERSION: ${{ steps.release.outputs.version }}

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,6 @@ jobs:
8787
8888
`actions/lint` automatically uses the PR base/head range on pull requests and
8989
`--last` on pushes. `actions/release` exposes `published`, `version`, `tag`, and
90-
`releases-json` outputs for release PR and downstream publishing jobs.
90+
`releases-json` outputs for release PR and downstream publishing jobs. Release
91+
PR preparation should be skipped until `RELEASE_TOKEN` is configured, so regular
92+
main CI stays green before release automation is enabled.

actions/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ repositories.
4141
Use `steps.release.outputs.published`, `version`, `tag`, and `releases-json`
4242
to open release PRs or gate downstream package, Docker, or archive publishing
4343
jobs. For repositories where `main` requires pull requests, use a
44-
`RELEASE_TOKEN` that can push the release branch and open the release PR.
44+
`RELEASE_TOKEN` that can push the release branch and open the release PR. Skip
45+
release preparation when that token is absent so normal main CI does not fail
46+
before release automation is enabled.

dist/cli.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,24 +1172,29 @@ jobs:
11721172
permissions:
11731173
contents: write
11741174
pull-requests: write
1175+
env:
1176+
RELEASE_TOKEN: \${{ secrets.RELEASE_TOKEN }}
11751177
steps:
1176-
- name: Require release token
1177-
env:
1178-
RELEASE_TOKEN: \${{ secrets.RELEASE_TOKEN }}
1178+
- name: Check release token
1179+
id: release-token
11791180
run: |
11801181
set -euo pipefail
11811182
if [[ -z "\${RELEASE_TOKEN}" ]]; then
1182-
echo "::error::Configure RELEASE_TOKEN with permission to push release PR branches and open pull requests."
1183-
exit 1
1183+
echo "::notice::Skipping release preparation because RELEASE_TOKEN is not configured."
1184+
echo "configured=false" >> "$GITHUB_OUTPUT"
1185+
exit 0
11841186
fi
1187+
echo "configured=true" >> "$GITHUB_OUTPUT"
11851188
11861189
- name: Checkout
1190+
if: steps.release-token.outputs.configured == 'true'
11871191
uses: actions/checkout@v6
11881192
with:
11891193
fetch-depth: 0
11901194
ref: main
11911195
11921196
- name: Prepare release
1197+
if: steps.release-token.outputs.configured == 'true'
11931198
id: release
11941199
uses: ${actionOwnerRepo}/actions/release@${actionRef}
11951200
with:
@@ -1201,7 +1206,7 @@ jobs:
12011206
install-command: bun install --frozen-lockfile
12021207
12031208
- name: Ensure release PR runs CI
1204-
if: steps.release.outputs.published == 'true'
1209+
if: steps.release-token.outputs.configured == 'true' && steps.release.outputs.published == 'true'
12051210
run: |
12061211
set -euo pipefail
12071212
subject="$(git log -1 --pretty=%s)"
@@ -1212,7 +1217,7 @@ jobs:
12121217
fi
12131218
12141219
- name: Open release PR
1215-
if: steps.release.outputs.published == 'true'
1220+
if: steps.release-token.outputs.configured == 'true' && steps.release.outputs.published == 'true'
12161221
env:
12171222
GH_TOKEN: \${{ secrets.RELEASE_TOKEN }}
12181223
RELEASE_VERSION: \${{ steps.release.outputs.version }}

src/workflow.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,29 @@ jobs:
112112
permissions:
113113
contents: write
114114
pull-requests: write
115+
env:
116+
RELEASE_TOKEN: \${{ secrets.RELEASE_TOKEN }}
115117
steps:
116-
- name: Require release token
117-
env:
118-
RELEASE_TOKEN: \${{ secrets.RELEASE_TOKEN }}
118+
- name: Check release token
119+
id: release-token
119120
run: |
120121
set -euo pipefail
121122
if [[ -z "\${RELEASE_TOKEN}" ]]; then
122-
echo "::error::Configure RELEASE_TOKEN with permission to push release PR branches and open pull requests."
123-
exit 1
123+
echo "::notice::Skipping release preparation because RELEASE_TOKEN is not configured."
124+
echo "configured=false" >> "$GITHUB_OUTPUT"
125+
exit 0
124126
fi
127+
echo "configured=true" >> "$GITHUB_OUTPUT"
125128
126129
- name: Checkout
130+
if: steps.release-token.outputs.configured == 'true'
127131
uses: actions/checkout@v6
128132
with:
129133
fetch-depth: 0
130134
ref: main
131135
132136
- name: Prepare release
137+
if: steps.release-token.outputs.configured == 'true'
133138
id: release
134139
uses: ${actionOwnerRepo}/actions/release@${actionRef}
135140
with:
@@ -141,7 +146,7 @@ jobs:
141146
install-command: bun install --frozen-lockfile
142147
143148
- name: Ensure release PR runs CI
144-
if: steps.release.outputs.published == 'true'
149+
if: steps.release-token.outputs.configured == 'true' && steps.release.outputs.published == 'true'
145150
run: |
146151
set -euo pipefail
147152
subject="$(git log -1 --pretty=%s)"
@@ -152,7 +157,7 @@ jobs:
152157
fi
153158
154159
- name: Open release PR
155-
if: steps.release.outputs.published == 'true'
160+
if: steps.release-token.outputs.configured == 'true' && steps.release.outputs.published == 'true'
156161
env:
157162
GH_TOKEN: \${{ secrets.RELEASE_TOKEN }}
158163
RELEASE_VERSION: \${{ steps.release.outputs.version }}

tests/workflow.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ describe("GitHub Actions integration", () => {
4848
expect(workflows.release).toContain("contains(github.event.workflow_run.head_commit.message, 'chore(release):')");
4949
expect(workflows.release).toContain("Prepare release PR");
5050
expect(workflows.release).toContain("RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}");
51+
expect(workflows.release).toContain("Check release token");
52+
expect(workflows.release).toContain("Skipping release preparation because RELEASE_TOKEN is not configured.");
53+
expect(workflows.release).toContain("if: steps.release-token.outputs.configured == 'true'");
54+
expect(workflows.release).toContain(
55+
"if: steps.release-token.outputs.configured == 'true' && steps.release.outputs.published == 'true'",
56+
);
5157
expect(workflows.release).toContain('push: "false"');
5258
expect(workflows.release).toContain('github: "false"');
5359
expect(workflows.release).toContain("gh pr create --base main");

0 commit comments

Comments
 (0)