-
-
Notifications
You must be signed in to change notification settings - Fork 8
118 lines (103 loc) · 3.92 KB
/
cargo_semver_checks.yaml
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Cargo Semver Checks
on:
workflow_call:
inputs:
bump-version:
type: string
required: true
workflow_dispatch:
inputs:
bump-version:
description: "Bump version: (e.g. -> 3.6.1)"
type: string
release_type:
type: choice
default: none
options:
- none
- patch
- minor
- major
jobs:
check-if-lib:
uses: ./.github/workflows/crate_type.yaml
get-baseline:
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install jql
uses: taiki-e/install-action@v2
with:
tool: jql
- name: Current versions
id: get_baseline_hash
run: |
bump_version=${{ inputs.bump-version }}
echo "bump_version: $bump_version"
tag=v$bump_version
# Check if tag exists
if git rev-parse --verify $tag >/dev/null 2>&1; then
echo "tag: $tag"
echo "tag exists."
echo "tag=$tag" >> "$GITHUB_OUTPUT";
previous_tag=$(git tag --list --sort=refname | grep -B1 "^$tag$" | head -n1);
echo "previous_tag: $previous_tag";
# Skip semver-checks if tags are equal
if [ "$previous_tag" = "$tag" ]; then
hash=''
else
hash=$(git rev-parse "$previous_tag")
fi
else
echo "Tag doesn't exist, it will use the latest crate version as the baseline tag"
latest_tag=v$(cargo metadata --format-version=1 --no-deps | jql '"packages"|>"version"<|[0]' --raw-string);
echo "baseline_tag: $latest_tag"
# This allow to skip semver-checks when there is not tags.
hash=$(git rev-parse "$latest_tag" 2>/dev/null || echo '')
fi
echo "hash: $hash";
echo "baseline=$hash" >> "$GITHUB_OUTPUT";
- name: "check-for-release-type"
run: |
- name: print if skip cargo-semver-checks
if: ${{ steps.get_baseline_hash.outputs.baseline == '' || (inputs.bump-version == '' && inputs.release_type == 'none') }}
run: |
echo "semver-checks needs a baseline. The baseline is the latest commit(hash) of the previous tag"
echo "cargo semver-checks will not run in 3 conditions:"
echo "1. There is not tags"
echo "2. There is only one tag and you bump version is that tag"
echo "3 There is not bump version and you release_type=none"
echo -e "\n"
echo "4 You are screw if you use a lower bump_version of a non existent tag"
echo "because it will run, but the baseline will be the latest tag"
echo "the check will just pass and this will not print :)"
outputs:
baseline: ${{ steps.get_baseline_hash.outputs.baseline }}
tag: ${{ steps.get_baseline_hash.outputs.tag }}
cargo-semver-checks:
needs: [check-if-lib, get-baseline]
if: ${{ needs.check-if-lib.outputs.is_lib == 'true' && needs.get-baseline.outputs.baseline != '' && (inputs.bump-version != '' || inputs.release_type != 'none') }}
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.get-baseline.outputs.tag || 'main' }}
- name: Install stable toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Install cargo-bump
uses: taiki-e/install-action@v2
with:
tool: cargo-bump
- name: Run cargo bump
run: cargo bump ${{ inputs.bump-version || inputs.release_type }}
- name: Install cargo-semver-checks
uses: taiki-e/install-action@v2
with:
tool: cargo-semver-checks
- name: Run cargo-semver-checks
run: cargo semver-checks --baseline-rev ${{ needs.get-baseline.outputs.baseline }};