-
Notifications
You must be signed in to change notification settings - Fork 0
56 lines (45 loc) · 2.05 KB
/
release.yml
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
name: Deploy to GitHub Releases
on:
workflow_dispatch:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Build
run: make build # Assumes you have a Makefile with a 'build' target
- name: Create and Upload Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_REF_NAME: ${{ github.ref_name }}
run: |
printf "Create a release with tag_name: [%s]\n" "${GITHUB_REF_NAME}"
RESPONSE=$(curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/json" -d '{"tag_name":"'"$GITHUB_REF_NAME"'", "name":"Release '"$GITHUB_REF_NAME"'", "draft":false, "prerelease":false}' "https://api.github.com/repos/$GITHUB_REPOSITORY/releases")
printf "RESPONSE=%s\n" "${RESPONSE}"
# Extract the upload URL from the response
UPLOAD_URL=$(echo $RESPONSE | jq -r .upload_url | sed 's/{?name,label}//')
printf "UPLOAD_URL=%s\n" "${UPLOAD_URL}"
# Loop through and upload each asset in the dist/ directory
for filename in build/*; do
asset_path=${filename}
asset_name=$(basename ${filename})
FULL_UPLOAD_URL="${UPLOAD_URL}?name=${asset_name}"
echo "Uploading ${filename} to ${FULL_UPLOAD_URL}"
# Upload asset
HTTP_RESPONSE=$(curl -s -o response.txt -w "%{http_code}" -X POST -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/octet-stream" --data-binary @"${asset_path}" "${FULL_UPLOAD_URL}")
if [ "$HTTP_RESPONSE" -eq "201" ]; then
echo "Successfully uploaded ${asset_name}"
rm response.txt # Clean up the response file
else
echo "Failed to upload ${asset_name} with HTTP response $HTTP_RESPONSE"
echo "Response: $(cat response.txt)"
rm response.txt # Clean up the response file
exit 1
fi
done