-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathaction.yml
More file actions
208 lines (176 loc) Β· 6.84 KB
/
Copy pathaction.yml
File metadata and controls
208 lines (176 loc) Β· 6.84 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
name: "Craft Prepare Release"
description: "Prepare a new release using Craft"
inputs:
version:
description: >
Version to release. Can be a semver string (e.g., "1.2.3"),
a bump type ("major", "minor", "patch"), or "auto" for automatic detection.
required: false
merge_target:
description: Target branch to merge into. Uses the default branch as a fallback.
required: false
force:
description: Force a release even when there are release-blockers
required: false
default: "false"
blocker_label:
description: Label that blocks releases
required: false
default: "release-blocker"
publish_repo:
description: Repository for publish issues (owner/repo format)
required: false
git_user_name:
description: Git committer name
required: false
git_user_email:
description: Git committer email
required: false
path:
description: The path that Craft will run inside
required: false
default: "."
craft_config_from_merge_target:
description: Use the craft config from the merge target branch
required: false
default: "false"
outputs:
version:
description: The resolved version being released
value: ${{ steps.craft.outputs.version }}
branch:
description: The release branch name
value: ${{ steps.craft.outputs.branch }}
sha:
description: The commit SHA on the release branch
value: ${{ steps.craft.outputs.sha }}
previous_tag:
description: The tag before this release (for diff links)
value: ${{ steps.craft.outputs.previous_tag }}
changelog:
description: The changelog for this release
value: ${{ steps.craft.outputs.changelog }}
runs:
using: "composite"
steps:
- id: killswitch
name: Check release blockers
shell: bash
run: |
if [[ '${{ inputs.force }}' != 'true' ]] && gh issue list -l '${{ inputs.blocker_label }}' -s open | grep -q '^[0-9]\+[[:space:]]'; then
echo "::error::Open release-blocking issues found (label: ${{ inputs.blocker_label }}), cancelling release..."
gh api -X POST repos/:owner/:repo/actions/runs/$GITHUB_RUN_ID/cancel
fi
- name: Set git user
shell: bash
run: |
# Use provided values or fall back to triggering actor
GIT_USER_NAME='${{ inputs.git_user_name }}'
GIT_USER_EMAIL='${{ inputs.git_user_email }}'
if [[ -z "$GIT_USER_NAME" ]]; then
GIT_USER_NAME="${GITHUB_ACTOR}"
fi
if [[ -z "$GIT_USER_EMAIL" ]]; then
GIT_USER_EMAIL="${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com"
fi
echo "GIT_COMMITTER_NAME=${GIT_USER_NAME}" >> $GITHUB_ENV
echo "GIT_AUTHOR_NAME=${GIT_USER_NAME}" >> $GITHUB_ENV
echo "EMAIL=${GIT_USER_EMAIL}" >> $GITHUB_ENV
- name: Install Craft
uses: ./install
- name: Craft Prepare
id: craft
shell: bash
env:
CRAFT_LOG_LEVEL: Debug
working-directory: ${{ inputs.path }}
run: |
# Ensure we have origin/HEAD set
git remote set-head origin --auto
# Build command with optional flags
CRAFT_ARGS=""
if [[ '${{ inputs.craft_config_from_merge_target }}' == 'true' && -n '${{ inputs.merge_target }}' ]]; then
CRAFT_ARGS="--config-from ${{ inputs.merge_target }}"
fi
# Version is optional - if not provided, Craft uses versioning.policy from config
VERSION_ARG=""
if [[ -n '${{ inputs.version }}' ]]; then
VERSION_ARG="${{ inputs.version }}"
fi
craft prepare $VERSION_ARG $CRAFT_ARGS
- 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: 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
# Use resolved version from Craft output
RESOLVED_VERSION="${{ steps.craft.outputs.version }}"
if [[ -z "$RESOLVED_VERSION" ]]; then
echo "::error::Craft did not output a version. This is unexpected."
exit 1
fi
title="publish: ${GITHUB_REPOSITORY}${subdirectory}@${RESOLVED_VERSION}"
# Determine publish repo
PUBLISH_REPO='${{ inputs.publish_repo }}'
if [[ -z "$PUBLISH_REPO" ]]; then
PUBLISH_REPO="${GITHUB_REPOSITORY_OWNER}/publish"
fi
# Check if issue already exists
# GitHub only allows search with the "in" operator and this issue search can
# return non-exact matches. We extract the titles and check with grep -xF
if gh -R "$PUBLISH_REPO" 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
# Use Craft outputs for git info
RELEASE_BRANCH="${{ steps.craft.outputs.branch }}"
RELEASE_SHA="${{ steps.craft.outputs.sha }}"
PREVIOUS_TAG="${{ steps.craft.outputs.previous_tag }}"
# Fall back to HEAD if no previous tag
if [[ -z "$PREVIOUS_TAG" ]]; then
PREVIOUS_TAG="HEAD"
fi
# Build changelog section if available
CHANGELOG='${{ steps.craft.outputs.changelog }}'
if [[ -n "$CHANGELOG" ]]; then
CHANGELOG_SECTION="
---
<details>
<summary>π Changelog</summary>
${CHANGELOG}
</details>"
else
CHANGELOG_SECTION=""
fi
body="Requested by: @${GITHUB_ACTOR}
Merge target: ${merge_target}
Quick links:
- [View changes](https://github.com/${GITHUB_REPOSITORY}/compare/${PREVIOUS_TAG}...${RELEASE_BRANCH})
- [View check runs](https://github.com/${GITHUB_REPOSITORY}/commit/${RELEASE_SHA}/checks/)
Assign the **accepted** label to this issue to approve the release.
To retract the release, the person requesting it must leave a comment containing \`#retract\` on a line by itself under this issue.
### Targets
${{ steps.craft-targets.outputs.targets }}
Checked targets will be skipped (either already published or user-requested skip). Uncheck to retry a target.
${CHANGELOG_SECTION}"
gh issue create -R "$PUBLISH_REPO" --title "$title" --body "$body"