Release workflow: release on any run, fail loudly
Build and Release / build (push) Failing after 16s
Build and Release / build (push) Failing after 16s
This commit is contained in:
1 parent
9fcbc820ad
commit
205e2ad8a2
1 file changed
+16
-4
@@ -2,6 +2,8 @@ name: Build and Release
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
tags:
|
tags:
|
||||||
- "v*"
|
- "v*"
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
@@ -36,16 +38,26 @@ jobs:
|
|||||||
ls -la dist-release
|
ls -la dist-release
|
||||||
|
|
||||||
- name: Create release and upload assets
|
- name: Create release and upload assets
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
|
||||||
env:
|
env:
|
||||||
TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
|
set -eu
|
||||||
|
[ -n "${TOKEN}" ] || { echo "ERROR: secret RELEASE_TOKEN is empty or not defined"; exit 1; }
|
||||||
API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||||
|
if [ "${GITHUB_REF_TYPE:-}" = "tag" ]; then
|
||||||
TAG="${GITHUB_REF_NAME}"
|
TAG="${GITHUB_REF_NAME}"
|
||||||
RELEASE_ID=$(curl -sf -X POST "$API/releases" \
|
else
|
||||||
|
TAG="build-${GITHUB_RUN_NUMBER}"
|
||||||
|
fi
|
||||||
|
echo "Creating release ${TAG} on ${API}"
|
||||||
|
curl -sS --fail-with-body -X POST "$API/releases" \
|
||||||
-H "Authorization: token ${TOKEN}" -H "Content-Type: application/json" \
|
-H "Authorization: token ${TOKEN}" -H "Content-Type: application/json" \
|
||||||
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\"}" | sed -n 's/.*"id":\([0-9]*\).*/\1/p' | head -1)
|
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"target_commitish\":\"${GITHUB_SHA}\"}" \
|
||||||
|
-o release.json
|
||||||
|
RELEASE_ID=$(sed -n 's/.*"id":\([0-9]*\).*/\1/p' release.json | head -1)
|
||||||
|
echo "Release id: ${RELEASE_ID}"
|
||||||
for f in dist-release/*; do
|
for f in dist-release/*; do
|
||||||
curl -sf -X POST "$API/releases/${RELEASE_ID}/assets?name=$(basename "$f")" \
|
echo "Uploading $f"
|
||||||
|
curl -sS --fail-with-body -X POST "$API/releases/${RELEASE_ID}/assets?name=$(basename "$f")" \
|
||||||
-H "Authorization: token ${TOKEN}" -F "attachment=@${f}"
|
-H "Authorization: token ${TOKEN}" -F "attachment=@${f}"
|
||||||
done
|
done
|
||||||
Reference in new issue
Block a user