Skip to content

Commit a631c0a

Browse files
committed
ci: add reusable workflow to move Linear tickets to Deployed (#21)
1 parent aaf9259 commit a631c0a

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-0
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: Move Linear tickets to Deployed
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
release_body:
7+
required: true
8+
type: string
9+
team_key:
10+
required: false
11+
type: string
12+
default: 'SDK'
13+
secrets:
14+
LINEAR_GITHUB_API_KEY:
15+
required: true
16+
17+
jobs:
18+
update-linear:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Update Linear tickets to Deployed
22+
env:
23+
LINEAR_GITHUB_API_KEY: ${{ secrets.LINEAR_GITHUB_API_KEY }}
24+
TEAM_KEY: ${{ inputs.team_key }}
25+
run: |
26+
set -euo pipefail
27+
28+
RELEASE_BODY=$(cat <<'EOF'
29+
${{ inputs.release_body }}
30+
EOF
31+
)
32+
33+
TICKETS=$(echo "$RELEASE_BODY" | grep -oE "${TEAM_KEY}-[0-9]+" | sort -u)
34+
35+
if [ -z "$TICKETS" ]; then
36+
echo "No ${TEAM_KEY} tickets found in release notes"
37+
exit 0
38+
fi
39+
40+
linear_query() {
41+
local query="$1"
42+
local payload
43+
local response
44+
45+
payload=$(jq -cn --arg query "$query" '{query: $query}')
46+
response=$(curl -sS -X POST https://api.linear.app/graphql \
47+
-H "Authorization: $LINEAR_GITHUB_API_KEY" \
48+
-H "Content-Type: application/json" \
49+
-d "$payload")
50+
51+
if [ "$(echo "$response" | jq '.errors | length > 0')" = "true" ]; then
52+
echo "Linear GraphQL query failed:" >&2
53+
echo "$response" | jq '.errors' >&2
54+
return 1
55+
fi
56+
57+
echo "$response"
58+
}
59+
60+
STATE_RESPONSE=$(linear_query '{
61+
workflowStates(filter: { name: { eq: "Deployed" } }) {
62+
nodes {
63+
id
64+
name
65+
team {
66+
key
67+
}
68+
}
69+
}
70+
}')
71+
72+
STATE_ID=$(echo "$STATE_RESPONSE" | jq -r --arg team_key "$TEAM_KEY" '
73+
[.data.workflowStates.nodes[] | select(.team.key == $team_key)][0].id // empty
74+
')
75+
76+
if [ -z "$STATE_ID" ]; then
77+
echo "Unable to find a Deployed workflow state for team $TEAM_KEY" >&2
78+
echo "Available Deployed states:" >&2
79+
echo "$STATE_RESPONSE" | jq -r '
80+
.data.workflowStates.nodes[]
81+
| "- \(.team.key): \(.id)"
82+
' >&2
83+
exit 1
84+
fi
85+
86+
echo "Deployed state ID: $STATE_ID"
87+
88+
for TICKET in $TICKETS; do
89+
echo "Processing $TICKET..."
90+
91+
ISSUE_RESPONSE=$(linear_query "{
92+
issue(id: \"$TICKET\") {
93+
id
94+
title
95+
team {
96+
key
97+
}
98+
}
99+
}")
100+
101+
ISSUE_ID=$(echo "$ISSUE_RESPONSE" | jq -r --arg team_key "$TEAM_KEY" '
102+
if .data.issue and .data.issue.team.key == $team_key then
103+
.data.issue.id
104+
else
105+
empty
106+
end
107+
')
108+
109+
if [ -z "$ISSUE_ID" ]; then
110+
echo " ⚠️ $TICKET not found in Linear team $TEAM_KEY"
111+
continue
112+
fi
113+
114+
UPDATE_RESPONSE=$(linear_query "mutation {
115+
issueUpdate(id: \"$ISSUE_ID\", input: { stateId: \"$STATE_ID\" }) {
116+
success
117+
issue {
118+
identifier
119+
title
120+
state {
121+
name
122+
}
123+
}
124+
}
125+
}")
126+
127+
if [ "$(echo "$UPDATE_RESPONSE" | jq -r '.data.issueUpdate.success')" != "true" ]; then
128+
echo " ❌ Failed to move $TICKET to Deployed" >&2
129+
echo "$UPDATE_RESPONSE" | jq '.data.issueUpdate' >&2
130+
exit 1
131+
fi
132+
133+
ISSUE_STATE=$(echo "$UPDATE_RESPONSE" | jq -r '.data.issueUpdate.issue.state.name')
134+
echo " ✅ $TICKET → $ISSUE_STATE"
135+
done

.github/workflows/publish-npm-github.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ on:
1616
JSON array of package scopes/names to publish (e.g., '["com.onesignal.unity.core", "com.onesignal.unity.android"]')
1717
If empty, publishes the root package.json
1818
default: "[]"
19+
secrets:
20+
GH_PUSH_TOKEN:
21+
required: false
22+
description: GitHub token with push permissions for release creation
1923

2024
permissions:
2125
id-token: write # Required for OIDC
@@ -110,5 +114,7 @@ jobs:
110114
needs: publish
111115
if: needs.publish.outputs.version != ''
112116
uses: ./.github/workflows/github-release.yml
117+
secrets:
118+
GH_PUSH_TOKEN: ${{ secrets.GH_PUSH_TOKEN }}
113119
with:
114120
version: ${{ needs.publish.outputs.version }}

0 commit comments

Comments
 (0)