-
Notifications
You must be signed in to change notification settings - Fork 29
104 lines (90 loc) · 3.92 KB
/
ci-ready.yml
File metadata and controls
104 lines (90 loc) · 3.92 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
name: CI Ready Signal
on:
repository_dispatch:
types: [ci-ready]
# client_payload schema:
# repo: "getsentry/sentry-native" (full owner/repo)
# version: "0.13.4"
# sha: "abc123..." (the release branch HEAD SHA)
permissions:
contents: read
issues: read
jobs:
signal:
runs-on: ubuntu-latest
name: Process CI-ready signal
steps:
- name: Find matching publish issue
id: find-issue
env:
REPO: ${{ github.event.client_payload.repo }}
VERSION: ${{ github.event.client_payload.version }}
run: |
title="publish: ${REPO}@${VERSION}"
echo "Looking for issue: ${title}"
# Find matching open issue by exact title match.
# Use --limit 200 to handle active repos with many open issues.
issue=$(gh issue list -R "$GITHUB_REPOSITORY" \
--state open \
--limit 200 \
--json number,title,labels \
| jq -r --arg t "$title" \
'[.[] | select(.title == $t)] | first // empty')
if [[ -z "$issue" ]]; then
# Retry a few times in case the issue hasn't been created yet
for i in 1 2 3; do
echo "Issue not found, retry ${i}/3 in 10s..."
sleep 10
issue=$(gh issue list -R "$GITHUB_REPOSITORY" \
--state open \
--limit 200 \
--json number,title,labels \
| jq -r --arg t "$title" \
'[.[] | select(.title == $t)] | first // empty')
if [[ -n "$issue" ]]; then break; fi
done
fi
if [[ -z "$issue" ]]; then
echo "::warning::No open issue found with title: ${title}"
exit 0
fi
number=$(echo "$issue" | jq -r '.number')
has_ci_pending=$(echo "$issue" | jq '[.labels[].name] | any(. == "ci-pending")')
if [[ "$has_ci_pending" != "true" ]]; then
echo "::warning::Issue #${number} does not have ci-pending label. Ignoring signal."
exit 0
fi
has_accepted=$(echo "$issue" | jq '[.labels[].name] | any(. == "accepted")')
echo "number=${number}" >> "$GITHUB_OUTPUT"
echo "has_accepted=${has_accepted}" >> "$GITHUB_OUTPUT"
echo "Found issue #${number} with ci-pending label (accepted=${has_accepted})"
# Use a GitHub App token so the label change triggers publish.yml.
# GITHUB_TOKEN events are deliberately suppressed by GitHub and
# would not create new workflow runs.
- name: Get auth token
if: steps.find-issue.outputs.number
id: token
uses: actions/create-github-app-token@v2.2.1
with:
app-id: ${{ vars.SENTRY_INTERNAL_APP_ID }}
private-key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
- name: Add ci-ready label
if: steps.find-issue.outputs.number
env:
# Override the default GITHUB_TOKEN with the app token so the
# label event triggers publish.yml (GITHUB_TOKEN events are
# suppressed by GitHub and would not start new workflow runs).
GH_TOKEN: ${{ steps.token.outputs.token }}
ISSUE_NUMBER: ${{ steps.find-issue.outputs.number }}
SHA: ${{ github.event.client_payload.sha }}
REPO: ${{ github.event.client_payload.repo }}
run: |
gh issue edit "$ISSUE_NUMBER" -R "$GITHUB_REPOSITORY" \
--remove-label "ci-pending" \
--add-label "ci-ready"
if [[ "${{ steps.find-issue.outputs.has_accepted }}" == "true" ]]; then
comment="CI checks passed for ${REPO} (\`${SHA:0:8}\`). Publishing is starting now."
else
comment="CI checks passed for ${REPO} (\`${SHA:0:8}\`). Publishing will start once the **accepted** label is also present."
fi
gh issue comment "$ISSUE_NUMBER" -R "$GITHUB_REPOSITORY" --body "$comment"