Skip to content

Commit ffd4c1c

Browse files
committed
add githu workflow
fix try
1 parent 7e64c81 commit ffd4c1c

File tree

4 files changed

+165
-78
lines changed

4 files changed

+165
-78
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
name: Build and Release Protols
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.ref }}
5+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
6+
7+
on:
8+
push:
9+
branches:
10+
- main
11+
workflow_dispatch:
12+
13+
jobs:
14+
build-and-release:
15+
strategy:
16+
matrix:
17+
os: [macos-15-large, macos-15-xlarge, ubuntu-latest]
18+
runs-on: ${{ matrix.os }}
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Set up Go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version: 1.22
27+
28+
- name: Decode and import the certificate
29+
if: ${{ matrix.os == 'macos-15-large' || matrix.os == 'macos-15-xlarge' }}
30+
run: |
31+
# Decode the base64-encoded certificate and save it as a .p12 file
32+
echo "${{ secrets.CERTIFICATE_P12_BASE64 }}" | base64 --decode > certificate.p12
33+
34+
# Import the .p12 certificate into the macOS keychain
35+
security create-keychain -p "temp-password" build.keychain
36+
security import certificate.p12 -k build.keychain -P "${{ secrets.CERTIFICATE_PASSWORD }}" -T /usr/bin/codesign
37+
38+
# Set the keychain as default and unlock it
39+
security list-keychains -s build.keychain
40+
security unlock-keychain -p "temp-password" build.keychain
41+
42+
# Set keychain settings to prevent it from locking automatically
43+
security set-keychain-settings build.keychain
44+
45+
# Pre-authorize codesign to access the certificate
46+
security set-key-partition-list -S apple-tool:,apple: -s -k "temp-password" build.keychain
47+
48+
echo "SIGN_IDENTITY=${{ secrets.SIGN_IDENTITY }}" >> $GITHUB_ENV
49+
echo "APPLE_ID=${{ secrets.APPLE_ID }}" >> $GITHUB_ENV
50+
echo "APPLE_APP_SPECIFIC_PASSWORD=${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}" >> $GITHUB_ENV
51+
echo "APPLE_TEAM_ID=${{ secrets.APPLE_TEAM_ID }}" >> $GITHUB_ENV
52+
53+
- name: Build Protols
54+
id: build_protols
55+
run: |
56+
mkdir -p release
57+
GOBIN=$PWD/release go install ./cmd/protols
58+
if [ "${{ matrix.os }}" == "macos-15-xlarge" ]; then
59+
sign_binary "$PWD/release/protols"
60+
echo "ARCH=arm64" >> $GITHUB_OUTPUT
61+
echo "FILENAME=protols-darwin-arm64.zip" >> $GITHUB_OUTPUT
62+
elif [ "${{ matrix.os }}" == "macos-15-large" ]; then
63+
sign_binary "$PWD/release/protols"
64+
echo "ARCH=amd64" >> $GITHUB_OUTPUT
65+
echo "FILENAME=protols-darwin-amd64.zip" >> $GITHUB_OUTPUT
66+
else
67+
echo "ARCH=amd64" >> $GITHUB_OUTPUT
68+
echo "FILENAME=protols-linux-amd64.zip" >> $GITHUB_OUTPUT
69+
fi
70+
71+
- name: Prepare Release Assets
72+
run: |
73+
zip -j release/${{ steps.build_protols.outputs.FILENAME }} release/protols
74+
75+
- name: Notarize and Staple
76+
if: ${{ matrix.os == 'macos-15-large' || matrix.os == 'macos-15-xlarge' }}
77+
run: |
78+
# Function to sign, notarize, and staple
79+
notarize_and_staple() {
80+
local package_path="$1"
81+
82+
# Unlock the keychain
83+
security unlock-keychain -p "$KEYCHAIN_PASSWD" ~/Library/Keychains/login.keychain
84+
85+
# Submit for notarization
86+
STATUS=$(xcrun notarytool submit "$package_path" \
87+
--team-id "$APPLE_TEAM_ID" \
88+
--apple-id "$APPLE_ID" \
89+
--password "$APPLE_APP_SPECIFIC_PASSWORD" 2>&1)
90+
91+
# Get the submission ID
92+
SUBMISSION_ID=$(echo "$STATUS" | awk -F ': ' '/id:/ { print $2; exit; }')
93+
echo "Notarization submission ID: $SUBMISSION_ID"
94+
95+
# Wait for notarization to complete
96+
xcrun notarytool wait "$SUBMISSION_ID" \
97+
--team-id "$APPLE_TEAM_ID" \
98+
--apple-id "$APPLE_ID" \
99+
--password "$APPLE_APP_SPECIFIC_PASSWORD"
100+
101+
# Check the notarization status
102+
REQUEST_STATUS=$(xcrun notarytool info "$SUBMISSION_ID" \
103+
--team-id "$APPLE_TEAM_ID" \
104+
--apple-id "$APPLE_ID" \
105+
--password "$APPLE_APP_SPECIFIC_PASSWORD" 2>&1 | \
106+
awk -F ': ' '/status:/ { print $2; }')
107+
108+
if [[ "$REQUEST_STATUS" != "Accepted" ]]; then
109+
echo "Notarization failed."
110+
exit 1
111+
fi
112+
}
113+
114+
# **Step 3: Notarize the Zip Archive**
115+
notarize_and_staple "release/${{ steps.build_protols.outputs.FILENAME }}"
116+
117+
118+
- name: Calculate SHA256 Checksums
119+
id: calculate_sha256
120+
run: |
121+
cd release
122+
echo "SHA256SUMS=$(shasum -a 256 ${{ steps.build_protols.outputs.FILENAME }} | awk '{print $1}')" >> $GITHUB_OUTPUT
123+
124+
- name: Get date
125+
id: get_date
126+
run: |
127+
echo "DATE=$(date +%Y%m%d)" >> $GITHUB_OUTPUT
128+
129+
- name: Delete Existing Release
130+
if: always()
131+
run: |
132+
tag="v${{ steps.get_date.outputs.DATE }}-${{ steps.build_protols.outputs.ARCH }}"
133+
release_id=$(gh release view "$tag" --json id -q '.id' 2>/dev/null || echo "")
134+
if [[ -n "$release_id" ]]; then
135+
gh release delete "$tag" -y
136+
fi
137+
env:
138+
GH_TOKEN: ${{ github.token }}
139+
140+
- name: Create GitHub Release
141+
id: create_release
142+
uses: actions/create-release@v1
143+
env:
144+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
145+
with:
146+
tag_name: "v${{ steps.get_date.outputs.DATE }}"
147+
release_name: "${{ steps.get_date.outputs.DATE }}"
148+
draft: false
149+
prerelease: false
150+
body: |
151+
SHA256 Checksums:
152+
```
153+
${{ steps.calculate_sha256.outputs.SHA256SUMS }}
154+
```
155+
156+
- name: Upload Release Asset
157+
uses: actions/upload-release-asset@v1
158+
env:
159+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
160+
with:
161+
upload_url: ${{ steps.create_release.outputs.upload_url }}
162+
asset_path: release/${{ steps.build_protols.outputs.FILENAME }}
163+
asset_name: ${{ steps.build_protols.outputs.FILENAME }}
164+
asset_content_type: application/zip
165+

.github/workflows/ci.yaml

Lines changed: 0 additions & 38 deletions
This file was deleted.

.github/workflows/release.yaml

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)