-
Notifications
You must be signed in to change notification settings - Fork 1.1k
171 lines (154 loc) · 6.14 KB
/
Copy pathCI-build-macos-macos-13.yml
File metadata and controls
171 lines (154 loc) · 6.14 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
name: CI-build-macos-macos-13
run-name: '${{ github.ref_name }} ${{ github.workflow }} ${{ github.sha }}'
on:
workflow_dispatch:
permissions:
contents: write
checks: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
jobs:
init_release:
runs-on: ubuntu-latest
# No concurrency group: GitHub's "1 running + 1 pending" rule causes
# mass cancellations when many workflows share a group. Instead we
# run all init jobs in parallel and converge via a race-tolerant
# find-or-create loop; all workers deterministically pick the
# lowest-id draft matching this SHA+tag.
outputs:
release_id: ${{ steps.release.outputs.release_id }}
release_name: ${{ steps.release.outputs.release_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
ref: ${{ github.sha }}
fetch-depth: 0
- name: Find or create draft release
id: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
GIT_DESC=$(git describe --long --abbrev=7 --tags)
TAG_NAME="${{ github.ref_name }}-head"
RELEASE_NAME="${TAG_NAME} - ${GIT_DESC}"
REPO="${{ github.repository }}"
SHA="${{ github.sha }}"
echo "Target: $RELEASE_NAME (sha $SHA)"
sleep $(( RANDOM % 10 ))
RELEASE_ID=""
for attempt in 1 2 3 4 5 6; do
IDS=$(gh api "repos/${REPO}/releases" --paginate \
--jq ".[] | select(.draft==true and .target_commitish==\"${SHA}\" and .tag_name==\"${TAG_NAME}\") | .id" \
| sort -n)
if [ -n "$IDS" ]; then
RELEASE_ID=$(echo "$IDS" | head -1)
NDUPES=$(echo "$IDS" | wc -l)
echo "attempt ${attempt}: found ${NDUPES} draft(s); using lowest id=${RELEASE_ID}"
break
fi
echo "attempt ${attempt}: no matching draft; creating"
gh api -X POST "repos/${REPO}/releases" \
-f tag_name="${TAG_NAME}" \
-f name="${RELEASE_NAME}" \
-f target_commitish="${SHA}" \
-F draft=true -F prerelease=true >/dev/null 2>&1 || true
sleep $(( (RANDOM % 4) + 2 ))
done
if [ -z "$RELEASE_ID" ]; then
echo "ERROR: could not find or create draft release after retries" >&2
exit 1
fi
echo "release_id=${RELEASE_ID}" >> "$GITHUB_OUTPUT"
echo "release_name=${RELEASE_NAME}" >> "$GITHUB_OUTPUT"
build:
needs: init_release
runs-on: macos-13
env:
ARCH: x86_64
MATRIX: '(macos-x86_64)'
BRANCH: ${{ github.ref_name }}
RELEASE_ID: ${{ needs.init_release.outputs.release_id }}
PROXYSQL31: "0"
PROXYSQLGENAI: "0"
PKG_CONFIG_PATH: "/usr/local/opt/openssl@3/lib/pkgconfig"
OPENSSL_ROOT_DIR: "/usr/local/opt/openssl@3"
steps:
- uses: LouisBrunner/checks-action@v2.0.0
id: checks
if: always()
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: '${{ github.workflow }} / ${{ github.job }} ${{ env.MATRIX }}'
repo: ${{ github.repository }}
sha: ${{ github.sha }}
status: 'in_progress'
details_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
- name: Install dependencies
run: |
brew install automake bzip2 cmake gpatch gnutls libtool openssl@3 icu4c pkg-config libiconv zlib
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
ref: ${{ github.sha }}
fetch-depth: 0
- name: Build ProxySQL
run: |
export PATH="/usr/local/bin:$PATH"
make -j$(sysctl -n hw.ncpu)
- name: Package binary
run: |
set -euo pipefail
# Mirror Makefile tier-version bump so tarball matches the built binary's version.
BASE=$(git describe --long --abbrev=7 --tags | sed 's/^v//')
if [ "${PROXYSQLGENAI:-0}" = "1" ]; then
VERSION=$(echo "$BASE" | awk -F. '{printf "%d.%s", $1+1, substr($0, length($1)+2)}')
elif [ "${PROXYSQL31:-0}" = "1" ]; then
VERSION=$(echo "$BASE" | awk -F. '{printf "%s.%d.%s", $1, $2+1, substr($0, length($1)+length($2)+3)}')
else
VERSION="$BASE"
fi
echo "Packaging as version: $VERSION"
tar -C src -czf proxysql-${VERSION}-macos-x86_64.tar.gz proxysql
shasum -a 256 proxysql-${VERSION}-macos-x86_64.tar.gz > proxysql-${VERSION}-macos-x86_64.tar.gz.sha256
- name: Upload to release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
shopt -s nullglob
uploaded=0
for f in proxysql-*-macos-x86_64.tar.gz proxysql-*-macos-x86_64.tar.gz.sha256; do
FNAME=$(basename "$f")
EXISTING=$(gh api "repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" \
--jq ".[] | select(.name==\"${FNAME}\") | .id" | head -1)
if [ -n "$EXISTING" ]; then
echo "Replacing existing asset ${FNAME} (id=${EXISTING})"
gh api -X DELETE "repos/${{ github.repository }}/releases/assets/${EXISTING}"
fi
echo "Uploading ${FNAME}"
gh api --method POST \
"https://uploads.github.com/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets?name=${FNAME}" \
--header "Content-Type: application/octet-stream" \
--input "$f"
uploaded=$((uploaded+1))
done
if [ "$uploaded" -eq 0 ]; then
echo "ERROR: no macOS tarballs matched proxysql-*-macos-x86_64.tar.gz[.sha256]" >&2
ls -la || true
exit 1
fi
echo "Uploaded $uploaded asset(s) to release id=${RELEASE_ID}"
- uses: LouisBrunner/checks-action@v2.0.0
if: always()
with:
token: ${{ secrets.GITHUB_TOKEN }}
check_id: ${{ steps.checks.outputs.check_id }}
repo: ${{ github.repository }}
sha: ${{ github.sha }}
conclusion: ${{ job.status }}
details_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'