Skip to content

Commit ca6ded6

Browse files
committed
Publish pre-releases on every commit to main
1 parent 6d49fc1 commit ca6ded6

5 files changed

Lines changed: 147 additions & 15 deletions

File tree

‎.github/workflows/release-dev.yaml‎

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: Publish a pre-release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
concurrency:
9+
group: release-pre-release
10+
# Do not cancel a run after it may have begun replacing release assets.
11+
cancel-in-progress: false
12+
13+
jobs:
14+
check-tag:
15+
name: Check for a version tag
16+
runs-on: ubuntu-latest
17+
outputs:
18+
is_tagged: ${{ steps.check.outputs.is_tagged }}
19+
steps:
20+
- uses: actions/checkout@v6
21+
with:
22+
fetch-depth: 0
23+
24+
- id: check
25+
name: Detect version tag
26+
run: |
27+
is_tagged=false
28+
29+
if [[ -n "$(git tag --points-at "$GITHUB_SHA" --list 'v*')" ]]; then
30+
is_tagged=true
31+
echo "$GITHUB_SHA has a version tag; the stable workflow will publish it"
32+
fi
33+
34+
echo "is_tagged=$is_tagged" >> "$GITHUB_OUTPUT"
35+
36+
build:
37+
name: Build for ${{ matrix.package }}
38+
needs: check-tag
39+
if: needs.check-tag.outputs.is_tagged == 'false'
40+
runs-on: ${{ matrix.runner }}
41+
strategy:
42+
matrix:
43+
include:
44+
# - package: aarch64-linux
45+
# runner: ubuntu-latest
46+
- package: x86_64-linux
47+
runner: ubuntu-latest
48+
# - package: aarch64-darwin
49+
# runner: macos-14
50+
# - package: x86_64-darwin
51+
# runner: macos-14
52+
steps:
53+
- uses: actions/checkout@v6
54+
55+
- name: Install Nix
56+
uses: NixOS/nix-installer-action@main
57+
58+
- name: Build package
59+
run: nix build ".#${{ matrix.package }}"
60+
61+
- name: Stage artifact
62+
run: |
63+
cp result/bin/cache-action "cache-action-${{ matrix.package }}"
64+
gzip -9n "cache-action-${{ matrix.package }}"
65+
66+
- name: Upload artifact
67+
uses: actions/upload-artifact@v7
68+
with:
69+
name: cache-action-${{ matrix.package }}.gz
70+
path: cache-action-${{ matrix.package }}.gz
71+
if-no-files-found: error
72+
73+
release-dev:
74+
name: Publish pre-release
75+
needs:
76+
- check-tag
77+
- build
78+
if: needs.check-tag.outputs.is_tagged == 'false'
79+
runs-on: ubuntu-latest
80+
permissions:
81+
contents: write
82+
env:
83+
RELEASE_TAG: pre-release
84+
steps:
85+
- name: Download artifacts
86+
uses: actions/download-artifact@v8
87+
with:
88+
pattern: cache-action-*
89+
path: dist
90+
merge-multiple: true
91+
92+
- name: Create or update pre-release
93+
env:
94+
GH_TOKEN: ${{ github.token }}
95+
run: |
96+
if gh api \
97+
"repos/$GITHUB_REPOSITORY/git/ref/tags/$RELEASE_TAG" \
98+
>/dev/null 2>&1; then
99+
gh api --method PATCH \
100+
"repos/$GITHUB_REPOSITORY/git/refs/tags/$RELEASE_TAG" \
101+
--raw-field sha="$GITHUB_SHA" \
102+
--field force=true \
103+
--silent
104+
else
105+
gh api --method POST \
106+
"repos/$GITHUB_REPOSITORY/git/refs" \
107+
--raw-field ref="refs/tags/$RELEASE_TAG" \
108+
--raw-field sha="$GITHUB_SHA" \
109+
--silent
110+
fi
111+
112+
command=create
113+
114+
if gh release view "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
115+
command=edit
116+
fi
117+
118+
gh release "$command" "$RELEASE_TAG" \
119+
--repo "$GITHUB_REPOSITORY" \
120+
--title "$RELEASE_TAG" \
121+
--notes "Pre-release for commit $GITHUB_SHA" \
122+
--prerelease \
123+
--latest=false \
124+
--target "$GITHUB_SHA" \
125+
--verify-tag
126+
127+
- name: Upload release artifacts
128+
env:
129+
GH_TOKEN: ${{ github.token }}
130+
run: gh release upload "$RELEASE_TAG" dist/* --clobber --repo "$GITHUB_REPOSITORY"
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name: Publish Release Artifacts
1+
name: Publish a stable release
22

33
on:
44
push:
55
tags:
6-
- "*"
6+
- "v*"
77

88
jobs:
99
build:
@@ -24,9 +24,7 @@ jobs:
2424
- uses: actions/checkout@v6
2525

2626
- name: Install Nix
27-
uses: nixbuild/nix-quick-install-action@v34
28-
with:
29-
nix_version: 2.29.2
27+
uses: NixOS/nix-installer-action@main
3028

3129
- name: Build package
3230
run: nix build ".#${{ matrix.package }}"
@@ -43,8 +41,8 @@ jobs:
4341
path: cache-action-${{ matrix.package }}.gz
4442
if-no-files-found: error
4543

46-
publish:
47-
name: Publish release artifacts
44+
release-stable:
45+
name: Publish stable release
4846
needs: build
4947
runs-on: ubuntu-latest
5048
permissions:
@@ -63,21 +61,24 @@ jobs:
6361
env:
6462
GH_TOKEN: ${{ github.token }}
6563
run: |
66-
exists=false
6764
command=create
6865
6966
if gh release view "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
70-
exists=true
7167
command=edit
7268
fi
7369
7470
args=(
7571
"$RELEASE_TAG"
7672
--title "$RELEASE_TAG"
7773
--notes ""
78-
--latest
7974
)
8075
76+
if [[ "$RELEASE_TAG" == *-* ]]; then
77+
args+=(--prerelease --latest=false)
78+
else
79+
args+=(--latest)
80+
fi
81+
8182
gh release "$command" --repo "$GITHUB_REPOSITORY" "${args[@]}"
8283
8384
- name: Upload release artifacts

‎Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cache-action"
3-
version = "0.0.19"
3+
version = "0.0.20-pre"
44
edition = "2024"
55

66
[features]

‎js/main.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,15 +415,16 @@ const main = async () => {
415415
const assetName = `${BINARY_NAME}-${target}.gz`;
416416
const actionRef =
417417
core.getInput("action-ref") || requiredEnv("GITHUB_ACTION_REF");
418+
const releaseRef = actionRef === "main" ? "pre-release" : actionRef;
418419

419-
const assetRequest = isCommitSha(actionRef)
420+
const assetRequest = isCommitSha(releaseRef)
420421
? await githubApiReleaseAssetRequest(
421422
releaseRepository,
422-
actionRef,
423+
releaseRef,
423424
assetName,
424425
githubToken,
425426
)
426-
: directReleaseAssetRequest(releaseRepository, actionRef, assetName);
427+
: directReleaseAssetRequest(releaseRepository, releaseRef, assetName);
427428

428429
core.info(`Downloading '${assetName}' from '${assetRequest.url}'`);
429430
await downloadGzipFile(assetRequest.url, binaryPath, assetRequest.headers);

0 commit comments

Comments
 (0)