Files
study/.gitea/workflows/build-1sem.yml
T
timka123 de2a6bcf96
Build 1sem PDFs & update latest / build-and-release (push) Failing after 7s
initial commit
2026-11-29 23:35:05 +03:00

78 lines
2.5 KiB
YAML

name: Build 1sem PDFs & update latest
on:
push:
branches:
- '**'
workflow_dispatch:
jobs:
build-and-release:
if: startsWith(github.ref, 'refs/heads/')
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Typst
uses: typst-community/setup-typst@v4
- name: Compile 1sem PDFs
run: |
mkdir -p dist
shopt -s nullglob
files=(1sem/*.typ)
if [ ${#files[@]} -eq 0 ]; then
echo "No .typ files found in 1sem/"
exit 1
fi
for f in "${files[@]}"; do
name="$(basename "$f" .typ)"
echo "Compiling $f -> dist/${name}.pdf"
typst compile --root . "$f" "dist/${name}.pdf"
done
- name: Update latest tag
run: |
git tag -f latest "${GITHUB_SHA}"
git push -f origin refs/tags/latest
- name: Recreate latest release and upload PDFs
env:
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
API="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}"
AUTH="Authorization: token ${GITEA_TOKEN}"
# Delete existing 'latest' release if present
existing_id=$(curl -fsS -H "$AUTH" "${API}/releases/tags/latest" | jq -r '.id // empty' || true)
if [ -n "${existing_id}" ]; then
curl -fsS -X DELETE -H "$AUTH" "${API}/releases/${existing_id}"
fi
# Create new 'latest' release pointing to current commit
payload=$(jq -n \
--arg tag "latest" \
--arg sha "${GITHUB_SHA}" \
--arg name "latest" \
--arg body "Автосборка PDF из \`1sem/\` для коммита \`${GITHUB_SHA:0:7}\`" \
'{tag_name: $tag, target_commitish: $sha, name: $name, body: $body, draft: false, prerelease: false}')
release_id=$(curl -fsS -X POST \
-H "$AUTH" \
-H "Content-Type: application/json" \
-d "$payload" \
"${API}/releases" | jq -r '.id')
# Upload all compiled PDFs as release assets
for pdf in dist/*.pdf; do
filename="$(basename "$pdf")"
echo "Uploading ${filename}..."
curl -fsS -X POST \
-H "$AUTH" \
-F "attachment=@${pdf}" \
"${API}/releases/${release_id}/assets?name=${filename}" > /dev/null
done