-
Notifications
You must be signed in to change notification settings - Fork 95
226 lines (196 loc) · 8.44 KB
/
linear-release.yml
File metadata and controls
226 lines (196 loc) · 8.44 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
name: Linear Release
run-name: Linear release for ${{ github.event_name == 'workflow_dispatch' && inputs.tag_name || github.ref_name }}
on:
push:
tags:
- "**"
workflow_dispatch:
inputs:
tag_name:
description: "Existing tag to sync to Linear"
required: true
type: string
permissions:
contents: read
pull-requests: read
concurrency:
group: linear-release-${{ github.event_name == 'workflow_dispatch' && inputs.tag_name || github.ref_name }}
cancel-in-progress: false
jobs:
linear-release:
if: github.repository == 'unraid/webgui'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout tag
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ github.event_name == 'workflow_dispatch' && github.ref || github.ref_name }}
fetch-depth: 0
- name: Resolve tag
id: tag
run: |
set -Eeuo pipefail
IFS=$'\n\t'
git fetch --force --tags origin
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG_NAME="${{ inputs.tag_name }}"
else
TAG_NAME="${GITHUB_REF_NAME}"
fi
if [ -z "$TAG_NAME" ]; then
echo "Tag name is required" >&2
exit 1
fi
if ! git rev-parse -q --verify "refs/tags/${TAG_NAME}" >/dev/null; then
echo "Tag '${TAG_NAME}' does not exist in this repository" >&2
exit 1
fi
if [[ "$TAG_NAME" == *"-"* ]]; then
RELEASE_CHANNEL="internal"
RELEASE_NAME="$TAG_NAME"
elif [[ "$TAG_NAME" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
RELEASE_CHANNEL="public"
RELEASE_NAME="Unraid OS ${TAG_NAME} Stable"
else
echo "Unsupported release tag format: ${TAG_NAME}" >&2
exit 1
fi
TAG_SHA="$(git rev-list -n 1 "$TAG_NAME")"
SEMVER_TAGS="$(
git tag --list '[0-9]*' \
| grep -E '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z]+(\.[0-9A-Za-z]+)*)?$' \
| sort -V
)"
PREVIOUS_TAG="$(
printf '%s\n' "$SEMVER_TAGS" \
| awk -v tag="$TAG_NAME" '$0 == tag { print previous; exit } { previous = $0 }'
)"
if [ -n "$PREVIOUS_TAG" ]; then
RANGE_SPEC="${PREVIOUS_TAG}..${TAG_NAME}"
elif git rev-parse -q --verify "${TAG_NAME}^" >/dev/null; then
RANGE_SPEC="${TAG_NAME}^..${TAG_NAME}"
else
RANGE_SPEC="$TAG_NAME"
fi
{
echo "tag_name=${TAG_NAME}"
echo "tag_sha=${TAG_SHA}"
echo "previous_tag=${PREVIOUS_TAG}"
echo "range_spec=${RANGE_SPEC}"
echo "release_name=${RELEASE_NAME}"
echo "release_channel=${RELEASE_CHANNEL}"
} >> "$GITHUB_OUTPUT"
- name: Collect Linear issue IDs from release commits
id: issues
env:
GH_TOKEN: ${{ github.token }}
RANGE_SPEC: ${{ steps.tag.outputs.range_spec }}
run: |
set -Eeuo pipefail
IFS=$'\n\t'
LOG_PATH="${RUNNER_TEMP}/linear-release-commit-text.txt"
PR_TEXT_PATH="${RUNNER_TEMP}/linear-release-pr-text.txt"
ISSUE_IDS_PATH="${RUNNER_TEMP}/linear-release-issue-ids.txt"
FEATUREOS_URLS_PATH="${RUNNER_TEMP}/linear-release-featureos-urls.txt"
GITHUB_PR_URLS_PATH="${RUNNER_TEMP}/linear-release-github-pr-urls.txt"
: > "$LOG_PATH"
: > "$PR_TEXT_PATH"
: > "$ISSUE_IDS_PATH"
: > "$FEATUREOS_URLS_PATH"
: > "$GITHUB_PR_URLS_PATH"
git log --format='%B%n' "$RANGE_SPEC" > "$LOG_PATH"
PR_NUMBERS="$(
grep -Eo 'Merge pull request #[0-9]+' "$LOG_PATH" \
| grep -Eo '[0-9]+' \
| sort -u || true
)"
for PR_NUMBER in $PR_NUMBERS; do
echo "${GITHUB_SERVER_URL:-https://github.com}/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" >> "$GITHUB_PR_URLS_PATH"
curl -fsSL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GH_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"${GITHUB_API_URL:-https://api.github.com}/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}" \
| jq -r '[.title, .body, .head.ref, .base.ref] | map(select(. != null and . != "")) | .[]' \
>> "$PR_TEXT_PATH"
done
{
grep -Eoh '\b[A-Z][A-Z0-9]+-[0-9]+\b' "$LOG_PATH" "$PR_TEXT_PATH" || true
} | sort -u > "$ISSUE_IDS_PATH"
{
grep -Eoh 'https://product\.unraid\.net/p/[^[:space:]<>)"]+' "$LOG_PATH" "$PR_TEXT_PATH" || true
} | sed 's/[.,;:]*$//' | sort -u > "$FEATUREOS_URLS_PATH"
{
echo "issue_ids_path=${ISSUE_IDS_PATH}"
echo "featureos_urls_path=${FEATUREOS_URLS_PATH}"
echo "github_pr_urls_path=${GITHUB_PR_URLS_PATH}"
echo "issue_count=$(wc -l < "$ISSUE_IDS_PATH" | tr -d ' ')"
echo "featureos_url_count=$(wc -l < "$FEATUREOS_URLS_PATH" | tr -d ' ')"
echo "github_pr_url_count=$(wc -l < "$GITHUB_PR_URLS_PATH" | tr -d ' ')"
} >> "$GITHUB_OUTPUT"
- name: Validate Linear API key
env:
LINEAR_API_KEY: ${{ secrets.LINEAR_API_KEY }}
run: |
set -Eeuo pipefail
IFS=$'\n\t'
if [ -z "$LINEAR_API_KEY" ]; then
echo "Missing GitHub Actions secret: LINEAR_API_KEY" >&2
echo "This workflow now uses the Linear GraphQL API directly so it can sync release issue membership." >&2
exit 1
fi
- name: Sync Linear release and issue membership
id: sync
env:
LINEAR_API_KEY: ${{ secrets.LINEAR_API_KEY }}
RELEASE_CHANNEL: ${{ steps.tag.outputs.release_channel }}
RELEASE_NAME: ${{ steps.tag.outputs.release_name }}
TAG_NAME: ${{ steps.tag.outputs.tag_name }}
TAG_SHA: ${{ steps.tag.outputs.tag_sha }}
PREVIOUS_TAG: ${{ steps.tag.outputs.previous_tag }}
RANGE_SPEC: ${{ steps.tag.outputs.range_spec }}
ISSUE_IDS_PATH: ${{ steps.issues.outputs.issue_ids_path }}
FEATUREOS_URLS_PATH: ${{ steps.issues.outputs.featureos_urls_path }}
GITHUB_PR_URLS_PATH: ${{ steps.issues.outputs.github_pr_urls_path }}
run: node .github/scripts/sync-linear-release.mjs
- name: Summarize Linear release
if: always()
env:
JOB_STATUS: ${{ job.status }}
RELEASE_CHANNEL: ${{ steps.tag.outputs.release_channel }}
TAG_NAME: ${{ steps.tag.outputs.tag_name }}
PREVIOUS_TAG: ${{ steps.tag.outputs.previous_tag }}
RELEASE_URL: ${{ steps.sync.outputs.release_url }}
RELEASE_NAME: ${{ steps.sync.outputs.release_name }}
RELEASE_VERSION: ${{ steps.sync.outputs.release_version }}
SYNCED_ISSUES: ${{ steps.sync.outputs.synced_issue_identifiers }}
SKIPPED_ISSUES: ${{ steps.sync.outputs.skipped_issue_identifiers }}
ISSUE_COUNT: ${{ steps.issues.outputs.issue_count }}
FEATUREOS_URL_COUNT: ${{ steps.issues.outputs.featureos_url_count }}
GITHUB_PR_URL_COUNT: ${{ steps.issues.outputs.github_pr_url_count }}
run: |
set -Eeuo pipefail
IFS=$'\n\t'
{
echo "## Linear release"
echo
echo "- Tag: \`${TAG_NAME}\`"
echo "- Previous tag: \`${PREVIOUS_TAG:-none}\`"
echo "- Channel: \`${RELEASE_CHANNEL}\`"
if [ "$JOB_STATUS" != "success" ]; then
echo "- Release: sync did not complete for \`${TAG_NAME}\` (job status: \`${JOB_STATUS}\`)"
elif [ -n "$RELEASE_URL" ]; then
echo "- Release: synced [${RELEASE_NAME:-$RELEASE_VERSION}](${RELEASE_URL})"
echo "- Version: \`${RELEASE_VERSION}\`"
else
echo "- Release: no Linear release was created or updated"
fi
echo "- Linear issue IDs found: \`${ISSUE_COUNT:-0}\`"
echo "- FeatureOS links found: \`${FEATUREOS_URL_COUNT:-0}\`"
echo "- GitHub PR links checked in Linear: \`${GITHUB_PR_URL_COUNT:-0}\`"
echo "- Issues attached: ${SYNCED_ISSUES:-none}"
echo "- Issues skipped: ${SKIPPED_ISSUES:-none}"
} >> "$GITHUB_STEP_SUMMARY"