-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (97 loc) · 3.48 KB
/
release-drafter.yml
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
name: Release Drafter
on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- deploy/production
permissions:
contents: read
jobs:
update_release_draft:
permissions:
# write permission is required to create a github release
contents: write
# write permission is required for autolabeler
# otherwise, read permission is required at least
pull-requests: read
runs-on: ubuntu-latest
steps:
- name: Get current date
id: get-date
run: |
export CURRENT_DATE=$(TZ=":America/Los_Angeles" date "+%Y-%m-%d")
echo "current_date=${CURRENT_DATE}" >> $GITHUB_OUTPUT
echo "Current date set to ${CURRENT_DATE}"
- name: Get number of releases for the current date
id: get-release-count
run: |
export RELEASE_COUNT=$(gh release list \
--repo ${{ github.repository }} \
--json tagName \
--exclude-drafts \
--jq "map(select(.tagName | startswith(\"${CURRENT_DATE}\")))|length" \
)
echo "release_count=${RELEASE_COUNT}" >> $GITHUB_OUTPUT
echo "Found ${RELEASE_COUNT} releases"
env:
CURRENT_DATE: ${{ steps.get-date.outputs.current_date }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare release version
id: get-version
run: |
export VERSION="${CURRENT_DATE}"
if [ $RELEASE_COUNT -gt 0 ]; then
echo "Release already exists for version ${VERSION}"
echo "Appending release count to version"
export VERSION="${CURRENT_DATE}-${RELEASE_COUNT}"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Version set to ${VERSION}"
env:
CURRENT_DATE: ${{ steps.get-date.outputs.current_date }}
RELEASE_COUNT: ${{ steps.get-release-count.outputs.release_count }}
- name: Check that version doesn't exist
id: check-release
run: |
echo "Checking version ${VERSION}"
export CHECK=$(gh release list \
--repo ${{ github.repository }} \
--json tagName \
--exclude-drafts \
--jq "map(select(.tagName == \"${VERSION}\"))|length" \
)
echo "Found ${CHECK} releases"
if [ $CHECK -gt 0 ]; then
echo "Release already exists for version ${VERSION}"
exit 1
fi
env:
VERSION: ${{ steps.get-version.outputs.version }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check that tag doesn't exist
id: check-tag
run: |
echo "Checking tag for version ${VERSION}"
# Query the API for this tag.
export CHECK=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/tags \
--jq "map(select(.name == \"${VERSION}\"))|length" \
)
echo "Found ${CHECK} tags"
if [ $CHECK -gt 0 ]; then
echo "Tag already exists for version ${VERSION}"
exit 1
fi
env:
VERSION: ${{ steps.get-version.outputs.version }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: release-drafter/release-drafter@v6
with:
commitish: deploy/production
tag: ${{ steps.get-version.outputs.version }}
name: ${{ steps.get-version.outputs.version }}
version: ${{ steps.get-version.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}