This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
|
||||
name: Build and Publish Slides
|
||||
|
||||
on:
|
||||
@@ -21,6 +22,7 @@ jobs:
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "22"
|
||||
|
||||
- name: Install Google Chrome
|
||||
run: |
|
||||
sudo apt-get update
|
||||
@@ -40,7 +42,8 @@ jobs:
|
||||
|
||||
npx --yes @marp-team/marp-cli@latest \
|
||||
--html slides.md -o dist/slides.html
|
||||
- name: Create Gitea release
|
||||
|
||||
- name: Create or get Gitea release
|
||||
id: release
|
||||
env:
|
||||
BASE_URL: ${{ secrets.TARGET_BASE_URL }}
|
||||
@@ -52,18 +55,45 @@ jobs:
|
||||
set -euo pipefail
|
||||
|
||||
API="${BASE_URL%/}/api/v1/repos/${OWNER}/${REPO}"
|
||||
AUTH=(-H "Authorization: token $TOKEN")
|
||||
|
||||
RESPONSE=$(curl --fail-with-body --silent --show-error \
|
||||
-X POST "$API/releases" \
|
||||
-H "Authorization: token $TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n \
|
||||
--arg tag "$TAG" \
|
||||
--arg name "Slides $TAG" \
|
||||
'{tag_name:$tag,name:$name,draft:false}')")
|
||||
# Check for existing release
|
||||
HTTP_CODE=$(curl -sS \
|
||||
"${AUTH[@]}" \
|
||||
-o /tmp/release.json \
|
||||
-w "%{http_code}" \
|
||||
"$API/releases/tags/$TAG")
|
||||
|
||||
echo "release_id=$(echo "$RESPONSE" | jq -r '.id')" \
|
||||
>> "$GITHUB_OUTPUT"
|
||||
if [ "$HTTP_CODE" = "200" ]; then
|
||||
RELEASE_ID=$(jq -r '.id' /tmp/release.json)
|
||||
echo "Using existing release: $RELEASE_ID"
|
||||
|
||||
elif [ "$HTTP_CODE" = "404" ]; then
|
||||
echo "Creating release..."
|
||||
|
||||
curl --fail-with-body --silent --show-error \
|
||||
-X POST "$API/releases" \
|
||||
"${AUTH[@]}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n \
|
||||
--arg tag "$TAG" \
|
||||
--arg name "Slides $TAG" \
|
||||
'{tag_name:$tag,name:$name,draft:false}')" \
|
||||
-o /tmp/release.json
|
||||
|
||||
RELEASE_ID=$(jq -r '.id' /tmp/release.json)
|
||||
else
|
||||
echo "Failed to check release (HTTP $HTTP_CODE)"
|
||||
cat /tmp/release.json
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$RELEASE_ID" ] || [ "$RELEASE_ID" = "null" ]; then
|
||||
echo "Could not obtain release ID"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "release_id=$RELEASE_ID" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Upload slides to Gitea release
|
||||
env:
|
||||
@@ -76,12 +106,48 @@ jobs:
|
||||
set -euo pipefail
|
||||
|
||||
API="${BASE_URL%/}/api/v1/repos/${OWNER}/${REPO}"
|
||||
AUTH=(-H "Authorization: token $TOKEN")
|
||||
|
||||
# Get existing release assets
|
||||
curl --fail-with-body --silent --show-error \
|
||||
"${AUTH[@]}" \
|
||||
"$API/releases/$RELEASE_ID/assets" \
|
||||
-o /tmp/assets.json
|
||||
|
||||
for file in dist/*; do
|
||||
NAME=$(basename "$file")
|
||||
|
||||
# Remove old asset if it exists
|
||||
ASSET_ID=$(jq -r \
|
||||
--arg name "$NAME" \
|
||||
'.[] | select(.name == $name) | .id' \
|
||||
/tmp/assets.json | head -n 1)
|
||||
|
||||
if [ -n "$ASSET_ID" ]; then
|
||||
echo "Deleting old asset: $NAME"
|
||||
|
||||
curl --fail-with-body --silent --show-error \
|
||||
-X DELETE \
|
||||
"${AUTH[@]}" \
|
||||
"$API/releases/$RELEASE_ID/assets/$ASSET_ID"
|
||||
fi
|
||||
|
||||
# Upload new asset
|
||||
echo "Uploading $NAME..."
|
||||
|
||||
curl --fail-with-body --silent --show-error \
|
||||
-X POST \
|
||||
"$API/releases/$RELEASE_ID/assets?name=$(basename "$file")" \
|
||||
-H "Authorization: token $TOKEN" \
|
||||
"$API/releases/$RELEASE_ID/assets?name=$NAME" \
|
||||
"${AUTH[@]}" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary "@$file"
|
||||
|
||||
echo "Uploaded $NAME"
|
||||
done
|
||||
|
||||
- name: Summary
|
||||
run: |
|
||||
echo "## Slides published successfully" >> "$GITHUB_STEP_SUMMARY"
|
||||
echo "- PDF: slides.pdf" >> "$GITHUB_STEP_SUMMARY"
|
||||
echo "- HTML: slides.html" >> "$GITHUB_STEP_SUMMARY"
|
||||
echo "- Tag: ${{ github.ref_name }}" >> "$GITHUB_STEP_SUMMARY"
|
||||
|
||||
Reference in New Issue
Block a user