Skip to content

Commit e5e0c8f

Browse files
committed
Upload artifact bundle
1 parent 16a12c8 commit e5e0c8f

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/bash
2+
3+
# This script generates an artifactbundle for protoc. This artifactbundle
4+
# is used by the Swift package manger. The script is run by a GitHub action
5+
# when a new pre-release is created for swift-protobuf.
6+
7+
set -ex
8+
9+
# Fetch the latest stable release from protocolbuffers/protobuf
10+
AUTH="Authorization: token $GITHUB_TOKEN"
11+
response=$(curl -sH "$AUTH" "https://api.github.com/repos/protocolbuffers/protobuf/releases/latest")
12+
TAG=$(echo "$response" | grep -m 1 '"tag_name":' | cut -d '"' -f 4)
13+
14+
# Remove 'v' prefix if present
15+
TAG="${TAG#v}"
16+
17+
if [[ ! "$TAG" =~ ^[0-9]+\.[0-9]+$ ]]; then
18+
echo "Error: $TAG does not match the expected pattern"
19+
exit 1
20+
fi
21+
22+
# Fetch all protoc release assets from protocolbuffers/protobuf
23+
curl -LJ --output protoc-$TAG-osx-x86_64.zip -H 'Accept: application/octet-stream' https://github.com/protocolbuffers/protobuf/releases/download/v$TAG/protoc-$TAG-osx-x86_64.zip
24+
curl -LJ --output protoc-$TAG-osx-aarch_64.zip -H 'Accept: application/octet-stream' https://github.com/protocolbuffers/protobuf/releases/download/v$TAG/protoc-$TAG-osx-aarch_64.zip
25+
curl -LJ --output protoc-$TAG-linux-aarch_64.zip -H 'Accept: application/octet-stream' https://github.com/protocolbuffers/protobuf/releases/download/v$TAG/protoc-$TAG-linux-aarch_64.zip
26+
curl -LJ --output protoc-$TAG-linux-x86_64.zip -H 'Accept: application/octet-stream' https://github.com/protocolbuffers/protobuf/releases/download/v$TAG/protoc-$TAG-linux-x86_64.zip
27+
curl -LJ --output protoc-$TAG-win64.zip -H 'Accept: application/octet-stream' https://github.com/protocolbuffers/protobuf/releases/download/v$TAG/protoc-$TAG-win64.zip
28+
29+
# Fetch and validate license from protocolbuffers/protobuf
30+
curl -LJ --output LICENSE -H 'Accept: application/vnd.github.v3.raw' https://api.github.com/repos/protocolbuffers/protobuf/contents/LICENSE
31+
LICENSE_HASH=$(sha256sum LICENSE | cut -d ' ' -f 1)
32+
EXPECTED_HASH="6e5e117324afd944dcf67f36cf329843bc1a92229a8cd9bb573d7a83130fea7d"
33+
34+
if [ "$LICENSE_HASH" != "$EXPECTED_HASH" ]; then
35+
echo "Error: License file has changed. Expected hash: $EXPECTED_HASH, Got: $LICENSE_HASH"
36+
exit 1
37+
fi
38+
39+
# Unzip all assets
40+
mkdir protoc-$TAG.artifactbundle
41+
unzip -d protoc-$TAG.artifactbundle/protoc-$TAG-osx-x86_64 protoc-$TAG-osx-x86_64.zip
42+
unzip -d protoc-$TAG.artifactbundle/protoc-$TAG-osx-aarch_64 protoc-$TAG-osx-aarch_64.zip
43+
unzip -d protoc-$TAG.artifactbundle/protoc-$TAG-linux-aarch_64 protoc-$TAG-linux-aarch_64.zip
44+
unzip -d protoc-$TAG.artifactbundle/protoc-$TAG-linux-x86_64 protoc-$TAG-linux-x86_64.zip
45+
unzip -d protoc-$TAG.artifactbundle/protoc-$TAG-win64 protoc-$TAG-win64.zip
46+
47+
# Copy license file into artifactbundle
48+
cp LICENSE protoc-$TAG.artifactbundle/
49+
50+
# Create info.json for artifactbundle
51+
cat > protoc-$TAG.artifactbundle/info.json << EOF
52+
{
53+
"schemaVersion": "1.0",
54+
"artifacts": {
55+
"protoc": {
56+
"type": "executable",
57+
"version": "$TAG",
58+
"variants": [
59+
{
60+
"path": "protoc-$TAG-linux-x86_64/bin/protoc",
61+
"supportedTriples": ["x86_64-unknown-linux-gnu"]
62+
},
63+
{
64+
"path": "protoc-$TAG-linux-aarch_64/bin/protoc",
65+
"supportedTriples": ["aarch64-unknown-linux-gnu", "arm64-unknown-linux-gnu", "aarch64-unknown-linux", "arm64-unknown-linux"]
66+
},
67+
{
68+
"path": "protoc-$TAG-osx-x86_64/bin/protoc",
69+
"supportedTriples": ["x86_64-apple-macosx"]
70+
},
71+
{
72+
"path": "protoc-$TAG-osx-aarch_64/bin/protoc",
73+
"supportedTriples": ["arm64-apple-macosx"]
74+
},
75+
{
76+
"path": "protoc-$TAG-win64/bin/protoc.exe",
77+
"supportedTriples": ["x86_64-unknown-windows"]
78+
},
79+
]
80+
}
81+
}
82+
}
83+
EOF
84+
85+
# Zip artifactbundle
86+
zip -r protoc-$TAG.artifactbundle.zip protoc-$TAG.artifactbundle
87+
88+
# Get asset upload url for the latest swift-protobuf draft release
89+
response=$(curl -sH "$AUTH" "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases")
90+
SWIFT_PROTOBUF_TAG=$(echo "$response" | jq -r '.[] | select(.draft == true) | .tag_name' | head -n 1)
91+
92+
if [ -z "$SWIFT_PROTOBUF_TAG" ]; then
93+
echo "Error: No draft release found"
94+
exit 1
95+
fi
96+
97+
release_response=$(curl -sH "$AUTH" "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases/tags/$SWIFT_PROTOBUF_TAG")
98+
eval $(echo "$release_response" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:alnum:]]=')
99+
[ "$id" ] || { echo "Error: Failed to get release id for tag: $SWIFT_PROTOBUF_TAG"; echo "$release_response\n" >&2; exit 1; }
100+
101+
# Upload asset
102+
curl --data-binary @protoc-$TAG.artifactbundle.zip -H "$AUTH" -H "Content-Type: application/octet-stream" "https://uploads.github.com/repos/$GITHUB_REPOSITORY/releases/$id/assets?name=protoc-$TAG.artifactbundle.zip"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Upload protoc artifactbundle
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
upload-artifactbundle:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: "Checkout code"
11+
uses: actions/checkout@latest
12+
- name: Upload artifactbundle
13+
env:
14+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15+
run: cd ${{ github.workspace }} && .github/scripts/upload_artifactbundle.sh
16+

0 commit comments

Comments
 (0)