-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
65 lines (55 loc) · 2.16 KB
/
action.yml
File metadata and controls
65 lines (55 loc) · 2.16 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
name: Release GitHub Action
description: Bumps version, creates semver tags (vX.Y.Z, vX.Y, vX), and publishes a GitHub Release
inputs:
github-token:
description: Token for the GitHub API (`secrets.GITHUB_TOKEN`)
required: true
runs:
using: composite
steps:
- name: Read version and compute tags
id: version
shell: bash
run: |
VERSION=$(jq -r '.version' package.json)
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Invalid semver in package.json: '${VERSION}'"
exit 1
fi
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
echo "version=v${VERSION}" >> "$GITHUB_OUTPUT"
echo "minor=v${MAJOR}.${MINOR}" >> "$GITHUB_OUTPUT"
echo "major=v${MAJOR}" >> "$GITHUB_OUTPUT"
- name: Check if tag already exists
id: check
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token }}
run: |
if gh api "repos/${{ github.repository }}/git/ref/tags/${{ steps.version.outputs.version }}" &>/dev/null; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "::notice::Tag ${{ steps.version.outputs.version }} already exists, skipping."
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Create tags and release
if: steps.check.outputs.exists == 'false'
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token }}
run: |
VERSION="${{ steps.version.outputs.version }}"
MINOR="${{ steps.version.outputs.minor }}"
MAJOR="${{ steps.version.outputs.major }}"
REPO="${{ github.repository }}"
SHA="$(git rev-parse HEAD)"
gh api -X POST "repos/${REPO}/git/refs" \
-f ref="refs/tags/${VERSION}" -f sha="${SHA}"
# Upsert floating tags (vX.Y, vX)
for TAG in "$MINOR" "$MAJOR"; do
gh api -X PATCH "repos/${REPO}/git/refs/tags/${TAG}" \
-f sha="${SHA}" -F force=true 2>/dev/null \
|| gh api -X POST "repos/${REPO}/git/refs" \
-f ref="refs/tags/${TAG}" -f sha="${SHA}"
done
gh release create "${VERSION}" --title "${VERSION}" --generate-notes --latest