-
-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (61 loc) · 2.28 KB
/
prepare-release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
name: Prepare Release
permissions:
"contents": "write"
"actions": "write"
on: push
jobs:
release-if-needed:
runs-on: "ubuntu-20.04"
# Only run if tests passed and the branch is main.
if: ${{ github.ref == 'refs/heads/main' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Check if version in Cargo.toml has changed
id: project
run: |
git diff-tree -r -G'^version ?= ?"*"' --exit-code HEAD Cargo.toml || : "${VERSION_CHANGED:=1}" && : "${VERSION_CHANGED:=0}"
echo "VERSION_CHANGED=${VERSION_CHANGED}" >> "$GITHUB_OUTPUT"
- name: Run tests
if: steps.project.outputs.VERSION_CHANGED == '1'
run: cargo test
- name: Install jq
if: steps.project.outputs.VERSION_CHANGED == '1'
run: |
sudo apt-get update
sudo apt-get install -y jq
- name: Get version from Cargo.toml
id: version
if: steps.project.outputs.VERSION_CHANGED == '1'
run: |
VERSION=$(cargo metadata --format-version 1 | jq --raw-output '.packages[] | select(.name == "stayfocused").version')
echo "TAG=v${VERSION}" >> "$GITHUB_OUTPUT"
- name: Create Tag
if: steps.project.outputs.VERSION_CHANGED == '1'
uses: actions/github-script@v7
with:
script: |
github.rest.git.createTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: '${{ steps.version.outputs.TAG }}',
message: 'Version ${{ steps.version.outputs.TAG }}',
object: context.sha,
type: 'commit'
})
- name: Trigger cargo-dist release workflow
if: steps.project.outputs.VERSION_CHANGED == '1'
uses: actions/github-script@v7
with:
script: |
github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ steps.version.outputs.TAG }}',
workflow_id: 'release.yml',
inputs: {'tag': '${{ steps.version.outputs.TAG }}'},
})