-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (70 loc) · 2.83 KB
/
gh_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
# This workflow will load Python, run a script to generate assets, and then
# bundle a github release
name: Release generator
on:
pull_request:
types:
- closed
jobs:
create_release:
if: github.event.pull_request.merged && contains( github.event.pull_request.labels.*.name, 'release')
runs-on: ubuntu-latest
steps:
- name: Manual workaround for Github not having a runtime macro to check for the default branch
id: gatekeeper
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
DEFAULT_BRANCH=$(curl -H "Authorization: token $GITHUB_TOKEN" -s https://api.github.com/repos/$GITHUB_REPOSITORY | jq -rc .default_branch)
unset IS_DEFAULT_BRANCH
if [ "$GITHUB_BASE_REF" == "$DEFAULT_BRANCH" ]; then IS_DEFAULT_BRANCH='true'; fi
echo "::set-output name=IS_DEFAULT_BRANCH::$IS_DEFAULT_BRANCH"
- uses: actions/checkout@v2
if: steps.gatekeeper.outputs.IS_DEFAULT_BRANCH
- uses: actions/setup-python@v2
if: steps.gatekeeper.outputs.IS_DEFAULT_BRANCH
with:
python-version: 3.8
- name: Create tag from title and run asset script
if: steps.gatekeeper.outputs.IS_DEFAULT_BRANCH
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
id: find_tag_and_prepare_assets
run: |
TAG=$(echo ${{ github.event.pull_request.title }} | sed -E "s/^.*Release (.+\..+\..+)$/\1/g")
echo "::set-output name=tag::$TAG"
SCRIPT=.github/prepare_assets.sh
if [ -f $SCRIPT ]; then
chmod u+x $SCRIPT
$SCRIPT $TAG
fi
- name: Create Release
if: steps.gatekeeper.outputs.IS_DEFAULT_BRANCH
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.find_tag_and_prepare_assets.outputs.tag }}
release_name: ${{ github.event.pull_request.title }}
body: ${{ github.event.pull_request.body }}
draft: false
prerelease: false
- name: Add latest-release tag
if: steps.gatekeeper.outputs.IS_DEFAULT_BRANCH
run: |
git tag -f latest-release
git push -f --tags
- name: Upload Assets
if: steps.gatekeeper.outputs.IS_DEFAULT_BRANCH
run: |
upload_url=${{ steps.create_release.outputs.upload_url }}
if [ -f .github/release_assets.txt ]; then
while IFS="" read -r FILE || [ -n "$FILE" ]
do
curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: $(file -b --mime-type $FILE)" \
--data-binary "@$FILE" \
"${upload_url%\{*}?name=$(basename $FILE)"
done < .github/release_assets.txt
fi