Skip to content

Commit f0c0ade

Browse files
committed
Harden release workflow for snapshot dev builds
Only publish releases on push/manual events, not pull requests. Force-update the snapshot tag to the current commit on automatic dev builds. Clean old jar assets before upload to prevent stale version artifacts from reappearing. Expand path filters to include webui/resources/build metadata changes that affect release outputs.
1 parent b660f78 commit f0c0ade

1 file changed

Lines changed: 57 additions & 2 deletions

File tree

.github/workflows/release.yml

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@ on:
55
branches:
66
- main
77
paths:
8-
- '**.java'
8+
- '**/*.java'
9+
- 'webui/**'
10+
- 'src/main/resources/**'
11+
- 'build.gradle.kts'
12+
- 'gradle.properties'
13+
- 'gradle/libs.versions.toml'
914
- '.github/workflows/release.yml'
1015
pull_request:
1116
paths:
12-
- '**.java'
17+
- '**/*.java'
18+
- 'webui/**'
19+
- 'src/main/resources/**'
20+
- 'build.gradle.kts'
21+
- 'gradle.properties'
22+
- 'gradle/libs.versions.toml'
1323
- '.github/workflows/release.yml'
1424
workflow_dispatch:
1525
inputs:
@@ -51,6 +61,7 @@ jobs:
5161

5262
- name: Determine release metadata
5363
id: meta
64+
if: github.event_name != 'pull_request'
5465
run: |
5566
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
5667
TAG="v${{ github.event.inputs.version }}"
@@ -74,18 +85,62 @@ jobs:
7485
echo "prerelease=$PRERELEASE"
7586
} >> "$GITHUB_OUTPUT"
7687
88+
- name: Move snapshot tag to current commit
89+
if: github.event_name != 'pull_request' && github.event_name != 'workflow_dispatch'
90+
env:
91+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92+
run: |
93+
git config user.name "github-actions[bot]"
94+
git config user.email "github-actions[bot]@users.noreply.github.com"
95+
git tag -f snapshot "$GITHUB_SHA"
96+
git push --force "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" refs/tags/snapshot
97+
7798
- name: Make Gradle wrapper executable
7899
run: chmod +x ./gradlew
79100

80101
- name: Build with Gradle
81102
run: ./gradlew build --no-configuration-cache
82103

104+
- name: Remove old jar assets from target release
105+
if: github.event_name != 'pull_request'
106+
uses: actions/github-script@v7
107+
with:
108+
script: |
109+
const tag = '${{ steps.meta.outputs.tag_name }}';
110+
let release;
111+
try {
112+
release = await github.rest.repos.getReleaseByTag({
113+
owner: context.repo.owner,
114+
repo: context.repo.repo,
115+
tag
116+
});
117+
} catch (error) {
118+
if (error.status === 404) {
119+
core.info(`Release for tag ${tag} does not exist yet; skipping cleanup.`);
120+
return;
121+
}
122+
throw error;
123+
}
124+
125+
const jarAssets = release.data.assets.filter(asset => asset.name.endsWith('.jar'));
126+
for (const asset of jarAssets) {
127+
await github.rest.repos.deleteReleaseAsset({
128+
owner: context.repo.owner,
129+
repo: context.repo.repo,
130+
asset_id: asset.id
131+
});
132+
core.info(`Deleted old asset: ${asset.name}`);
133+
}
134+
83135
- name: Publish Release
136+
if: github.event_name != 'pull_request'
84137
uses: softprops/action-gh-release@v2
85138
env:
86139
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
87140
with:
88141
tag_name: ${{ steps.meta.outputs.tag_name }}
142+
target_commitish: ${{ github.sha }}
89143
name: ${{ steps.meta.outputs.release_name }}
90144
prerelease: ${{ steps.meta.outputs.prerelease }}
91145
files: build/libs/*.jar
146+
fail_on_unmatched_files: true

0 commit comments

Comments
 (0)