-
Notifications
You must be signed in to change notification settings - Fork 14
70 lines (63 loc) · 2.14 KB
/
Copy pathauto-release.yml
File metadata and controls
70 lines (63 loc) · 2.14 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
name: Create Release
on:
push:
branches: [master]
permissions:
contents: write
jobs:
create_release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get version from build.gradle
id: version
run: |
VERSION=$(grep "^version = " build.gradle | sed "s/version = '\(.*\)'/\1/")
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Check if tag exists
id: check
run: |
VERSION="${{ steps.version.outputs.version }}"
if git rev-parse "v${VERSION}" >/dev/null 2>&1; then
echo "Tag v${VERSION} already exists, skipping release"
echo "should_release=false" >> $GITHUB_OUTPUT
else
echo "Tag v${VERSION} does not exist, will create release"
echo "should_release=true" >> $GITHUB_OUTPUT
fi
- name: Extract changelog notes for this version
id: notes
if: steps.check.outputs.should_release == 'true'
run: |
VERSION="${{ steps.version.outputs.version }}"
NOTES=""
if [ -f CHANGELOG.md ]; then
NOTES=$(awk -v ver="$VERSION" '
$0 ~ "^## " ver {p=1; next}
p && /^## / {exit}
p {print}
' CHANGELOG.md)
fi
{
echo "notes<<EOF"
echo "$NOTES"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Create tag and release
if: steps.check.outputs.should_release == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
TAG="v${{ steps.version.outputs.version }}"
git tag "$TAG"
git push origin "$TAG"
if [ -n "$(echo "$NOTES" | tr -d '[:space:]')" ]; then
gh release create "$TAG" --title "$TAG" --notes "$NOTES"
else
gh release create "$TAG" --title "$TAG" --generate-notes
fi
env:
GITHUB_TOKEN: ${{ secrets.GOCARDLESS_CI_ROBOT_TOKEN }}
NOTES: ${{ steps.notes.outputs.notes }}