-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
159 lines (147 loc) · 6.49 KB
/
action.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: "Prepare Release"
description: "Common setup for craft/prepare"
inputs:
version:
description: Version to release (optional)
required: false
calver:
description: Use automatic CalVer versioning
required: true
default: false
merge_target:
description: Target branch to merge into. Uses the default branch as a fallback (optional)
required: false
force:
description: Force a release even when there are release-blockers (optional)
required: false
craft_version:
description: The craft version to use, defaults to "latest" (optional)
required: true
default: latest
path:
description: The path that Craft will run inside. Defaults to `.`
required: true
default: "."
craft_config_from_merge_target:
description: Use the craft config from the merge target branch. Defaults to the repository's default branch
default: false
runs:
using: "composite"
steps:
- id: killswitch
name: Check release blockers
shell: bash
run: |
if [[ -z '${{ inputs.force }}' ]] && gh issue list -l release-blocker -s open | grep -q '^[0-9]\+[[:space:]]'; then
echo "Open release-blocking issues found, cancelling release...";
gh api -X POST repos/:owner/:repo/actions/runs/$GITHUB_RUN_ID/cancel;
fi
- name: Determine version
shell: bash
run: |
if [[ -n '${{ inputs.version }}' ]]; then
echo 'RELEASE_VERSION=${{ inputs.version }}' >> $GITHUB_ENV;
elif [[ '${{ inputs.calver }}' = 'true' ]]; then
# Our releases are on 15th of each month so go back 14 days (a fortnight)
DATE_PART=$(date -d '-1 fortnight' +'%y.%-m')
declare -i PATCH_VERSION=0
while gh api --silent "repos/:owner/:repo/git/ref/tags/$DATE_PART.$PATCH_VERSION" 2>/dev/null; do
PATCH_VERSION+=1
done
echo "RELEASE_VERSION=${DATE_PART}.${PATCH_VERSION}" >> $GITHUB_ENV;
else
echo "You need to provide a version to release.";
exit 1;
fi
- name: Set git user to getsentry-bot
shell: bash
run: |
echo "GIT_COMMITTER_NAME=getsentry-bot" >> $GITHUB_ENV;
echo "GIT_AUTHOR_NAME=getsentry-bot" >> $GITHUB_ENV;
echo "[email protected]" >> $GITHUB_ENV;
- name: Install Craft
shell: bash
run: |
craft_url=$(curl -s https://api.github.com/repos/getsentry/craft/releases/${{ inputs.craft_version }} | jq -r '.assets[].browser_download_url | select(endswith("/craft"))')
sudo curl -sL -o /usr/local/bin/craft "$craft_url"
sudo chmod +x /usr/local/bin/craft
- name: Checkout merge target branch
if: inputs.craft_config_from_merge_target == 'true' && inputs.merge_target
shell: bash
run: |
git fetch origin ${{ inputs.merge_target }}
git checkout ${{ inputs.merge_target }}
- name: Craft Prepare
id: craft
shell: bash
env:
CRAFT_LOG_LEVEL: Warn
working-directory: ${{ inputs.path }}
run: |
# Ensure we have origin/HEAD set
git remote set-head origin --auto
CRAFT_LOG_LEVEL=Debug craft prepare "${{ env.RELEASE_VERSION }}"
- name: Checkout merge target branch
# We need to check out the merge target branch again because at the end of `craft prepare`
# craft checks out the default branch
if: inputs.craft_config_from_merge_target == 'true' && inputs.merge_target
shell: bash
run: |
git checkout ${{ inputs.merge_target }}
- name: Read Craft Targets
id: craft-targets
shell: bash
working-directory: ${{ inputs.path }}
env:
CRAFT_LOG_LEVEL: Warn
run: |
targets=$(craft targets | jq -r '.[]|" - [ ] \(.)"')
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
echo "targets<<EOF" >> "$GITHUB_OUTPUT"
echo "$targets" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Get Release Git Info
id: release-git-info
shell: bash
run: |
# craft switches back to `main` but we want info on the release branch
# if we previously checked out the merge target branch (craft_config_from_merge_target)
# we need to go back 2 checkouts, otherwise 1
git checkout ${{ inputs.craft_config_from_merge_target == 'true' && inputs.merge_target && '@{-2}' || '@{-1}' }}
echo "branch=$(git rev-parse --symbolic-full-name HEAD)" >> "$GITHUB_OUTPUT"
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
echo "last=$(git rev-parse --verify "$(git describe --tags --abbrev=0)" || echo HEAD)" >> "$GITHUB_OUTPUT"
- name: Request publish
shell: bash
run: |
if [[ '${{ inputs.path }}' == '.' ]]; then
subdirectory='';
else
subdirectory='/${{ inputs.path }}';
fi
if [[ -n '${{ inputs.merge_target }}' ]]; then
merge_target='${{ inputs.merge_target }}';
else
merge_target='(default)';
fi
title="publish: $GITHUB_REPOSITORY$subdirectory@$RELEASE_VERSION"
# So, GitHub only allows search with the "in" operator and this
# issue search can return non-exact matches. Due to this, we extract
# the titles of the returned issues and check them with `grep -xw`
# which does a non-regexp full-line match (exact match for us)
if gh -R $GITHUB_REPOSITORY_OWNER/publish issue list -S "'$title' in:title" --json title -q '.[] | .title' | grep -qxF -- "$title"; then
echo "There's already an open publish request, skipped issue creation.";
exit 0;
fi
body="Requested by: @$GITHUB_ACTOR
Merge target: $merge_target
Quick links:
- [View changes](https://github.com/$GITHUB_REPOSITORY/compare/${{ steps.release-git-info.outputs.last }}...${{ steps.release-git-info.outputs.branch }})
- [View check runs](https://github.com/$GITHUB_REPOSITORY/commit/${{ steps.release-git-info.outputs.sha }}/checks/)
Assign the **accepted** label to this issue to approve the release.
Leave a comment containing \`#retract\` under this issue to retract the release (original issuer only).
### Targets
${{ steps.craft-targets.outputs.targets }}
Targets marked with a checkbox have already been executed. Administrators can manually tick a checkbox to force craft to skip it.
"
gh issue create -R "$GITHUB_REPOSITORY_OWNER/publish" --title "$title" --body "$body"