All checks were successful
Sync Upstream Release / sync (push) Successful in 5s
98 lines
3.2 KiB
YAML
98 lines
3.2 KiB
YAML
name: Sync Upstream Release
|
|
|
|
on:
|
|
schedule:
|
|
- cron: "0 */6 * * *"
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
jobs:
|
|
sync:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Fetch upstream release metadata
|
|
id: upstream
|
|
run: |
|
|
RELEASE=$(curl -sf https://api.github.com/repos/muxi1/switch-cheats-db/releases/latest)
|
|
|
|
TAG=$(echo "$RELEASE" | jq -r '.tag_name')
|
|
NAME=$(echo "$RELEASE" | jq -r '.name // empty')
|
|
BODY=$(echo "$RELEASE" | jq -r '.body // empty')
|
|
|
|
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
|
|
|
|
if [ -z "$NAME" ]; then
|
|
echo "name=$TAG" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "name=$NAME" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
{
|
|
echo "$BODY"
|
|
echo ""
|
|
echo "---"
|
|
echo "**WICHTIG:** Die Inhalte stammen von [muxi](https://github.com/muxi1) und sind ursprünglich für amsPLUS erstellt worden."
|
|
} > /tmp/release_body.md
|
|
|
|
echo "$RELEASE" | jq -r '.assets[].browser_download_url' > /tmp/asset_urls.txt
|
|
|
|
- name: Check if release already exists
|
|
id: check
|
|
run: |
|
|
TAG="${{ steps.upstream.outputs.tag }}"
|
|
API_URL="${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/tags/${TAG}"
|
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
|
"$API_URL")
|
|
if [ "$HTTP_CODE" = "200" ]; then
|
|
echo "exists=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "exists=false" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Download assets
|
|
if: steps.check.outputs.exists == 'false'
|
|
run: |
|
|
mkdir -p /tmp/assets
|
|
while IFS= read -r url; do
|
|
echo "Downloading $url"
|
|
curl -fL -o "/tmp/assets/$(basename "$url")" "$url"
|
|
done < /tmp/asset_urls.txt
|
|
|
|
- name: Create release with assets
|
|
if: steps.check.outputs.exists == 'false'
|
|
run: |
|
|
TAG="${{ steps.upstream.outputs.tag }}"
|
|
NAME="${{ steps.upstream.outputs.name }}"
|
|
BODY=$(cat /tmp/release_body.md)
|
|
API_URL="${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases"
|
|
|
|
RESPONSE=$(curl -sf \
|
|
-X POST \
|
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$(jq -n --arg tag "$TAG" --arg name "$NAME" --arg body "$BODY" \
|
|
'{tag_name: $tag, name: $name, body: $body}')" \
|
|
"$API_URL")
|
|
|
|
RELEASE_ID=$(echo "$RESPONSE" | jq -r '.id')
|
|
echo "Created release $RELEASE_ID"
|
|
|
|
UPLOAD_URL="${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets"
|
|
|
|
for f in /tmp/assets/*; do
|
|
FILENAME=$(basename "$f")
|
|
echo "Uploading $FILENAME"
|
|
curl -sf \
|
|
-X POST \
|
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
|
-H "Content-Type: application/octet-stream" \
|
|
--data-binary "@$f" \
|
|
"${UPLOAD_URL}?name=${FILENAME}"
|
|
echo " -> done"
|
|
done
|