-
Notifications
You must be signed in to change notification settings - Fork 146
141 lines (123 loc) · 5.43 KB
/
Copy pathcheck_error_codes.yml
File metadata and controls
141 lines (123 loc) · 5.43 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
name: Check UR ErrorCodes version
on:
workflow_dispatch:
schedule:
- cron: '0 6 * * *' # Every night at 06:00 UTC
pull_request:
paths:
- '.github/workflows/check_error_codes.yml'
jobs:
check_error_codes:
name: Check UR ErrorCodes JSON version
runs-on: ubuntu-latest
permissions:
contents: write # push update branch
issues: write # open notification issue
pull-requests: write # open PR with the regenerated header
steps:
- uses: actions/checkout@v7
- name: Check error codes version
id: check
# continue-on-error so subsequent steps can still run and open a PR/issue
continue-on-error: true
run: |
python3 scripts/generate_error_codes.py \
--check \
--header include/ur_client_library/ur/error_code_texts.h
- name: Extract versions
if: steps.check.outcome == 'failure'
id: versions
run: |
COMMITTED=$(python3 -c "
import re
m = re.search(r'ERROR_CODE_JSON_VERSION\s*=\s*\"([^\"]+)\"',
open('include/ur_client_library/ur/error_code_texts.h').read())
print(m.group(1) if m else 'unknown')
")
UPSTREAM=$(python3 -c "
import urllib.request, json
data = json.loads(urllib.request.urlopen(
'https://www.universal-robots.com/manuals/EN/PDF/Shared/ErrorCodes/ErrorCodes.json'
).read())
print(data.get('version', 'unknown'))
")
# Validate both versions match N.N.N before using them in branch
# names, PR titles, and commit messages. An unexpected format
# (e.g. containing '/', '"', or newlines) would otherwise allow
# injection into those fields.
VERSION_RE='^[0-9]+\.[0-9]+\.[0-9]+$'
if ! echo "$COMMITTED" | grep -qE "$VERSION_RE"; then
echo "ERROR: committed version '$COMMITTED' does not match expected N.N.N format" >&2
exit 1
fi
if ! echo "$UPSTREAM" | grep -qE "$VERSION_RE"; then
echo "ERROR: upstream version '$UPSTREAM' does not match expected N.N.N format" >&2
exit 1
fi
echo "committed=$COMMITTED" >> "$GITHUB_OUTPUT"
echo "upstream=$UPSTREAM" >> "$GITHUB_OUTPUT"
- name: Ensure label exists
if: >-
github.event_name != 'pull_request' &&
steps.check.outcome == 'failure' &&
steps.versions.outcome == 'success'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh label create "error-codes-outdated" \
--description "Upstream UR ErrorCodes JSON has a newer version than the committed header" \
--color "e4e669" \
--force
- name: Regenerate header and open PR
if: >-
github.event_name != 'pull_request' &&
steps.check.outcome == 'failure' &&
steps.versions.outcome == 'success'
id: pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMITTED: ${{ steps.versions.outputs.committed }}
UPSTREAM: ${{ steps.versions.outputs.upstream }}
PR_BODY: |
The upstream UR ErrorCodes JSON has been updated. This PR regenerates `error_code_texts.h` automatically.
| | Version |
|---|---|
| Previous header (`ERROR_CODE_JSON_VERSION`) | `${{ steps.versions.outputs.committed }}` |
| Upstream JSON | `${{ steps.versions.outputs.upstream }}` |
**Workflow run:** ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
> [!NOTE]
> Only `include/ur_client_library/ur/error_code_texts.h` is updated here.
> If you have pending entries in `scripts/error_code_overrides.json`, verify
> they are still correct against the new JSON before merging.
run: |
BRANCH="auto/update-error-codes-v${UPSTREAM}"
# Skip if a PR for exactly this branch is already open
OPEN_PR=$(gh pr list \
--label "error-codes-outdated" \
--state open \
--json headRefName \
--jq "[.[] | select(.headRefName == \"$BRANCH\")] | length")
if [ "$OPEN_PR" -gt 0 ]; then
echo "PR for branch $BRANCH already open — skipping."
echo "pr_url=" >> "$GITHUB_OUTPUT"
else
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b "$BRANCH"
python3 scripts/generate_error_codes.py \
--overlay scripts/error_code_overrides.json \
--output include/ur_client_library/ur/error_code_texts.h
git add include/ur_client_library/ur/error_code_texts.h
git commit -m "chore: update error_code_texts.h to UR ErrorCodes JSON v${UPSTREAM}"
git push origin "$BRANCH"
PR_URL=$(gh pr create \
--title "chore: update error_code_texts.h to UR ErrorCodes JSON v${UPSTREAM}" \
--label "error-codes-outdated" \
--base "${{ github.event.repository.default_branch }}" \
--head "$BRANCH" \
--body "$PR_BODY")
echo "pr_url=$PR_URL" >> "$GITHUB_OUTPUT"
fi
- name: Fail if version mismatch
if: steps.check.outcome == 'failure'
run: exit 1