Skip to content

Commit baf6ab1

Browse files
Update release.yml
1 parent 1486cc1 commit baf6ab1

1 file changed

Lines changed: 38 additions & 15 deletions

File tree

.github/workflows/release.yml

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,64 @@ permissions:
1010
contents: write
1111

1212
jobs:
13-
build:
13+
release:
1414
runs-on: ubuntu-latest
1515

1616
steps:
1717
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
1820

1921
- uses: dtolnay/rust-toolchain@stable
2022

2123
- uses: Swatinem/rust-cache@v2
24+
with:
25+
cache-all-crates: true
26+
cache-workspaces: |
27+
. -> target
28+
29+
- name: Get version
30+
id: version
31+
run: |
32+
VERSION=$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[0].version')
33+
echo "version=v$VERSION" >> "$GITHUB_OUTPUT"
2234
23-
- name: Run tests
35+
- name: Create tag
36+
if: github.event_name == 'workflow_dispatch'
37+
run: |
38+
if git rev-parse "${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
39+
echo "Tag already exists."
40+
else
41+
git config user.name github-actions
42+
git config user.email github-actions@github.com
43+
git tag "${{ steps.version.outputs.version }}"
44+
git push origin "${{ steps.version.outputs.version }}"
45+
fi
46+
47+
- name: Test
2448
run: cargo test --workspace --locked
2549

2650
- name: Build
2751
run: cargo build --workspace --release --locked
2852

2953
- name: Package
3054
run: |
31-
mkdir -p dist/oops-${{ github.ref_name }}/systemd
32-
mkdir -p dist/oops-${{ github.ref_name }}/shell-hooks
55+
mkdir -p dist/oops-${{ steps.version.outputs.version }}/systemd
56+
mkdir -p dist/oops-${{ steps.version.outputs.version }}/shell-hooks
3357
34-
cp target/release/oops dist/oops-${{ github.ref_name }}/
35-
cp systemd/oopsd.service dist/oops-${{ github.ref_name }}/systemd/
36-
cp oops/shell-hooks/* dist/oops-${{ github.ref_name }}/shell-hooks/
37-
cp README.md LICENSE dist/oops-${{ github.ref_name }}/
58+
cp target/release/oops dist/oops-${{ steps.version.outputs.version }}/
59+
cp systemd/oopsd.service dist/oops-${{ steps.version.outputs.version }}/systemd/
60+
cp oops/shell-hooks/* dist/oops-${{ steps.version.outputs.version }}/shell-hooks/
61+
cp README.md LICENSE dist/oops-${{ steps.version.outputs.version }}/
3862
3963
tar -C dist \
40-
-czf oops-${{ github.ref_name }}-x86_64-unknown-linux-gnu.tar.gz \
41-
oops-${{ github.ref_name }}
42-
43-
- name: Verify package
44-
run: ls -lh oops-*.tar.gz
64+
-czf oops-${{ steps.version.outputs.version }}-x86_64-unknown-linux-gnu.tar.gz \
65+
oops-${{ steps.version.outputs.version }}
4566
46-
- name: Create GitHub Release
67+
- name: Create or Update Release
4768
uses: softprops/action-gh-release@v2
4869
with:
49-
files: oops-*.tar.gz
70+
tag_name: ${{ steps.version.outputs.version }}
71+
files: oops-${{ steps.version.outputs.version }}-x86_64-unknown-linux-gnu.tar.gz
72+
overwrite_files: true
5073

0 commit comments

Comments
 (0)