-
Notifications
You must be signed in to change notification settings - Fork 10
76 lines (70 loc) · 2.73 KB
/
changelog_release.yaml
File metadata and controls
76 lines (70 loc) · 2.73 KB
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
name: Auto Release on Changelog Update
on:
push:
branches: [ main ]
paths:
- 'CHANGELOG.md'
jobs:
prepare-release:
name: Extract version & check tag
runs-on: ubuntu-latest
outputs:
version: ${{ steps.extract.outputs.version }}
should_release: ${{ steps.tagcheck.outputs.should_release }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # need tags
- name: Extract version from CHANGELOG.md
id: extract
run: |
second_h2_line=$(grep -E '^## \[' CHANGELOG.md | sed -n '2p') || true
if [ -z "$second_h2_line" ]; then
echo "Could not find second H2 header in CHANGELOG.md" >&2
exit 1
fi
# Support optional prerelease (-rc.1, -beta, etc) and build metadata (+build.5) per SemVer, no leading 'v'.
version=$(echo "$second_h2_line" | sed -E 's/^## \[([0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?)\].*/\1/')
if ! [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
echo "Parsed version '$version' is not a valid SEMVER" >&2
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "Extracted version: $version"
- name: Check if tag already exists
id: tagcheck
run: |
version_tag="v${{ steps.extract.outputs.version }}"
if git ls-remote --exit-code --tags origin "$version_tag" >/dev/null 2>&1; then
echo "Tag $version_tag already exists. Skipping release." >&2
echo "should_release=false" >> "$GITHUB_OUTPUT"
else
echo "Tag $version_tag does not exist. Will release." >&2
echo "should_release=true" >> "$GITHUB_OUTPUT"
fi
- name: Emit skip notice
if: steps.tagcheck.outputs.should_release == 'false'
run: |
echo "::notice title=Release skipped::Tag v${{ steps.extract.outputs.version }} already exists. No release will be created."
run-release:
name: Run Release workflow
needs: prepare-release
if: needs.prepare-release.outputs.should_release == 'true'
permissions:
id-token: write
contents: write
uses: ./.github/workflows/update_sdk_version.yaml
with:
version: ${{ needs.prepare-release.outputs.version }}
emergency: false
secrets: inherit
no-release:
name: No release (tag exists)
needs: prepare-release
if: needs.prepare-release.outputs.should_release == 'false'
runs-on: ubuntu-latest
steps:
- name: Summary
run: |
echo "Tag v${{ needs.prepare-release.outputs.version }} already exists. Release workflow not invoked." >> $GITHUB_STEP_SUMMARY