-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (94 loc) · 3.55 KB
/
release.yml
File metadata and controls
109 lines (94 loc) · 3.55 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
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
name: Create Release
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
on:
workflow_run:
workflows:
- SDK CI
types:
- completed
workflow_dispatch:
permissions:
contents: write
concurrency:
group: release-${{ github.event_name == 'workflow_dispatch' && github.ref || github.event.workflow_run.head_branch }}
cancel-in-progress: true
jobs:
release:
if: |
(github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_run' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.head_branch == 'main')
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.event_name == 'workflow_dispatch' && github.ref || github.event.workflow_run.head_sha }}
- name: Resolve release source
id: source
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "sha=${GITHUB_SHA}" >> "$GITHUB_OUTPUT"
else
echo "sha=${{ github.event.workflow_run.head_sha }}" >> "$GITHUB_OUTPUT"
fi
- name: Read release version
id: version
run: |
version="$(tr -d '[:space:]' < VERSION)"
version="${version#v}"
if ! printf '%s' "$version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$'; then
echo "VERSION must contain a semantic version like 1.2.3 or 1.2.3-beta.1"
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "tag=v$version" >> "$GITHUB_OUTPUT"
- name: Check whether the release already exists
id: existing
env:
GH_TOKEN: ${{ github.token }}
run: |
if gh release view "${{ steps.version.outputs.tag }}" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Check whether the tag already exists
id: tag
run: |
if git ls-remote --exit-code --tags origin "refs/tags/${{ steps.version.outputs.tag }}" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Create and push version tag
if: steps.tag.outputs.exists != 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag "${{ steps.version.outputs.tag }}" "${{ steps.source.outputs.sha }}"
git push origin "refs/tags/${{ steps.version.outputs.tag }}"
- name: Create GitHub release
if: steps.existing.outputs.exists != 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
for attempt in 1 2 3; do
if gh release create "${{ steps.version.outputs.tag }}" \
--repo "$GITHUB_REPOSITORY" \
--title "TPS ${{ steps.version.outputs.tag }}" \
--verify-tag \
--generate-notes; then
exit 0
fi
if [ "$attempt" -eq 3 ]; then
echo "Failed to create GitHub release after $attempt attempts."
exit 1
fi
echo "Release creation failed on attempt $attempt. Retrying..."
sleep 5
done