Repository navigation
163 lines (143 loc) · 6.17 KB
/
Copy pathupdate-bindings.yml
File metadata and controls
163 lines (143 loc) · 6.17 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
name: Update API bindings
on:
workflow_dispatch:
inputs:
version:
description: "Binding version (leave blank to auto-increment the patch version)"
required: false
type: string
schedule:
# Daily at 06:00 UTC
- cron: "0 6 * * *"
permissions:
contents: read
defaults:
run:
shell: bash
jobs:
update-bindings:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Require bot credentials
env:
BOT_TOKEN: ${{ secrets.CLOUDSMITH_BOT_TOKEN }}
BOT_SIGNING_KEY: ${{ secrets.CLOUDSMITH_BOT_SSH_SIGNING_KEY }}
BOT_EMAIL: ${{ secrets.CLOUDSMITH_BOT_EMAIL }}
run: |
if [ -z "$BOT_TOKEN" ] || [ -z "$BOT_SIGNING_KEY" ] || [ -z "$BOT_EMAIL" ]; then
echo "::error::Configure CLOUDSMITH_BOT_TOKEN, CLOUDSMITH_BOT_SSH_SIGNING_KEY, and CLOUDSMITH_BOT_EMAIL before running this workflow."
exit 1
fi
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
token: ${{ secrets.CLOUDSMITH_BOT_TOKEN }}
persist-credentials: false
- name: Set up tools
uses: jdx/mise-action@d5574b52816a478f9d4e6529a3f6ff17a8a36785 # v5.2.8
- name: Generate bindings
run: mise run build
- name: Detect changes
id: detect
env:
INPUT_VERSION: ${{ inputs.version }}
run: |
if [ -n "$INPUT_VERSION" ] || [ -n "$(git status --porcelain)" ]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "Bindings already match the current API; no PR needed."
fi
- name: Bump version and regenerate
if: steps.detect.outputs.changed == 'true'
id: versions
env:
INPUT_VERSION: ${{ inputs.version }}
run: |
api_version=$(curl -s --max-time 30 "https://api.cloudsmith.io/status/check/basic/" | jq -r '.version')
if [ -z "$api_version" ] || [ "$api_version" = "null" ]; then
echo "Could not fetch CloudSmith API version" >&2
exit 1
fi
current_version=$(grep -E '^package_version=' scripts/common.sh | cut -d'"' -f2)
if [ -n "$INPUT_VERSION" ]; then
new_version="$INPUT_VERSION"
else
IFS='.' read -r major minor patch <<< "$current_version"
new_version="${major}.${minor}.$((patch + 1))"
fi
sed -i -E "s/^package_version=.*/package_version=\"${new_version}\"/" scripts/common.sh
mise run build
echo "api_version=$api_version" >> "$GITHUB_OUTPUT"
echo "new_version=$new_version" >> "$GITHUB_OUTPUT"
- name: Configure bot commit signing
if: steps.detect.outputs.changed == 'true'
env:
BOT_SIGNING_KEY: ${{ secrets.CLOUDSMITH_BOT_SSH_SIGNING_KEY }}
BOT_EMAIL: ${{ secrets.CLOUDSMITH_BOT_EMAIL }}
run: |
umask 077
key="$RUNNER_TEMP/cloudsmith-bot-signing-key"
signers="$RUNNER_TEMP/cloudsmith-bot-allowed-signers"
printf '%s\n' "$BOT_SIGNING_KEY" > "$key"
public_key=$(ssh-keygen -y -P "" -f "$key")
printf '%s namespaces="git" %s\n' "$BOT_EMAIL" "$public_key" > "$signers"
git config --local gpg.format ssh
git config --local user.signingkey "$key"
git config --local gpg.ssh.allowedSignersFile "$signers"
git config --local commit.gpgsign true
- name: Close stale automated binding PRs
if: steps.detect.outputs.changed == 'true'
env:
GH_TOKEN: ${{ secrets.CLOUDSMITH_BOT_TOKEN }}
NEW_VERSION: ${{ steps.versions.outputs.new_version }}
run: |
keep="automated/update-bindings-v${NEW_VERSION}"
gh pr list --state open --json number,headRefName \
--jq '.[]
| select(.headRefName | startswith("automated/update-bindings-"))
| select(.headRefName != "'"$keep"'")
| .number' \
| while read -r number; do
[ -n "$number" ] || continue
gh pr close "$number" --delete-branch \
--comment "Superseded by automated bindings update v${NEW_VERSION}."
done
- name: Create pull request
if: steps.detect.outputs.changed == 'true'
id: pull-request
uses: peter-evans/create-pull-request@3ffccacd46053766916f087ce41d627c0b8cf2d1 # v8.1.3
with:
token: ${{ secrets.CLOUDSMITH_BOT_TOKEN }}
author: cloudsmith-bot <${{ secrets.CLOUDSMITH_BOT_EMAIL }}>
committer: cloudsmith-bot <${{ secrets.CLOUDSMITH_BOT_EMAIL }}>
# Sign locally with the SSH key; API signing does not support PATs.
sign-commits: false
branch: automated/update-bindings-v${{ steps.versions.outputs.new_version }}
base: master
title: "feat: update bindings to v${{ steps.versions.outputs.new_version }} (API v${{ steps.versions.outputs.api_version }})"
commit-message: "feat: update bindings to v${{ steps.versions.outputs.new_version }} (API v${{ steps.versions.outputs.api_version }})"
body: |
Automated API bindings update.
- Binding version: `${{ steps.versions.outputs.new_version }}`
- CloudSmith API version: `${{ steps.versions.outputs.api_version }}`
Generated by the **Update API bindings** workflow.
labels: |
bindings
automated
delete-branch: true
- name: Require a verified commit signature
if: steps.pull-request.outputs.pull-request-number != ''
env:
VERIFIED: ${{ steps.pull-request.outputs.pull-request-commits-verified }}
run: |
if [ "$VERIFIED" != "true" ]; then
echo "::error::GitHub did not verify the commit signature. Register the SSH signing public key and verify the configured email on cloudsmith-bot."
exit 1
fi
- name: Remove bot signing key
if: always()
run: |
rm -f "$RUNNER_TEMP/cloudsmith-bot-signing-key" \
"$RUNNER_TEMP/cloudsmith-bot-allowed-signers"