forked from GoogleContainerTools/skaffold
-
Notifications
You must be signed in to change notification settings - Fork 1
98 lines (87 loc) · 3.19 KB
/
draft-release.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
name: Create Draft Release
on:
push:
branches:
- main
- v1
permissions: read-all
concurrency:
group: build-${{ github.event.pull_request.number || github.ref }}-${{github.workflow}}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
check:
name: Check if release commit
runs-on: ubuntu-latest
if: "startsWith(github.event.head_commit.message, 'release: ')"
steps:
- name: Apply release-matching regexp to commit message
id: regex-match
uses: actions-ecosystem/action-regex-match@v2
with:
text: ${{ github.event.head_commit.message }}
# Allow optional `v` prefix and GitHub PR reference suffix on first line only
# release: v1.2.3
# release: 1.2.3-beta.1
# release: v1.2.3-beta.1 (#9456)
regex: '^release: v?([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?)(\s+\(#[0-9]+\))?$'
flags: m
- name: Determine if applicable
id: check-commit-message
if: steps.regex-match.outputs.group1 != ''
run: |
echo "applicable=true" >> $GITHUB_OUTPUT
echo "This is a release commit: ${{ steps.regex-match.outputs.group1 }}"
outputs:
applicable: ${{ steps.check-commit-message.outputs.applicable }}
version: ${{ steps.regex-match.outputs.group1 }}
release:
name: Create Tag and Draft Release
needs: check
if: needs.check.outputs.applicable == 'true'
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Calculate Tag and Release names
run: |
echo TAG_NAME="v${{ needs.check.outputs.version }}" >> $GITHUB_ENV
echo RELEASE_NAME="v${{ needs.check.outputs.version }} Release" >> $GITHUB_ENV
- name: Create and push Tag
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git tag -a ${{ env.TAG_NAME }} -m "${{ env.RELEASE_NAME }}"
git push origin ${{ env.TAG_NAME }}
- name: Install gsutil
run: |
curl -Lo $HOME/gsutil.tar.gz https://storage.googleapis.com/pub/gsutil.tar.gz
tar xfz $HOME/gsutil.tar.gz -C $HOME
echo "$HOME/gsutil" >> $GITHUB_PATH
- name: Download release artifacts
run: |
# Wait up to 60m for all artifacts to be available
retries=20
found=0
while [ $found -lt 10 -a $retries -gt 0 ]
do
sleep 3m
found=$(gsutil du gs://skaffold/releases/${{ env.TAG_NAME }}/ | wc -l)
retries=$((retries-1))
done
gsutil -m cp -r gs://skaffold/releases/${{ env.TAG_NAME }}/ $HOME
- name: Create Release
shell: bash
run: |
curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1
body=$(git log -p --follow -1 CHANGELOG.md | grep '^\+' | cut -c 2- | tail -n +2)
assets=()
for asset in $HOME/${{ env.TAG_NAME }}/*; do
assets+=("-a" "$asset")
done
bin/hub release create "${assets[@]}" -m "${{ env.RELEASE_NAME }}" -m "$body" --draft ${{ env.TAG_NAME }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}