Skip to content

Print tag_name before getting URL. #8

Print tag_name before getting URL.

Print tag_name before getting URL. #8

Workflow file for this run

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