From e9dac1a69e2a8c219178bf7442b8b5953894fac0 Mon Sep 17 00:00:00 2001 From: Markus Werle Date: Fri, 17 Oct 2025 23:10:25 +0200 Subject: [PATCH] Add GitHub Actions workflow for calendar release --- .github/workflows/calendar-release.yml | 117 +++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 .github/workflows/calendar-release.yml diff --git a/.github/workflows/calendar-release.yml b/.github/workflows/calendar-release.yml new file mode 100644 index 0000000..a13ecc8 --- /dev/null +++ b/.github/workflows/calendar-release.yml @@ -0,0 +1,117 @@ +name: Generate and Release Calendar + +on: + push: + paths: + - 'calendar/cpp-aachen.jsoncal' + workflow_dispatch: + +permissions: + contents: write + +jobs: + generate-calendar: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + cache: 'pip' + + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip + pip install icalendar + + - name: Download json2ical.py script + run: | + curl -o json2ical.py https://raw.githubusercontent.com/d-frey/json2ical/refs/heads/main/json2ical.py + chmod +x json2ical.py + + - name: Generate iCal file + run: | + python json2ical.py calendar/cpp-aachen.jsoncal cpp-aachen.ics + + - name: Get current timestamp + id: timestamp + run: echo "timestamp=$(date +'%Y%m%d-%H%M%S')" >> $GITHUB_OUTPUT + + - name: Create or update latest release + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const { owner, repo } = context.repo; + + // Try to get existing "latest" release + let release; + try { + const existingRelease = await github.rest.repos.getReleaseByTag({ + owner, + repo, + tag: 'latest' + }); + release = existingRelease.data; + + // Delete existing assets + const assets = await github.rest.repos.listReleaseAssets({ + owner, + repo, + release_id: release.id + }); + + for (const asset of assets.data) { + await github.rest.repos.deleteReleaseAsset({ + owner, + repo, + asset_id: asset.id + }); + } + + // Update release + await github.rest.repos.updateRelease({ + owner, + repo, + release_id: release.id, + name: 'Latest Calendar Release', + body: `Automatically generated iCal calendar file from cpp-aachen.jsoncal\\n\\nGenerated on: ${new Date().toISOString()}\\n\\nThis release is automatically updated when the calendar file changes.` + }); + + } catch (error) { + if (error.status === 404) { + // Create new release if "latest" doesn't exist + const newRelease = await github.rest.repos.createRelease({ + owner, + repo, + tag_name: 'latest', + name: 'Latest Calendar Release', + body: `Automatically generated iCal calendar file from cpp-aachen.jsoncal\\n\\nGenerated on: ${new Date().toISOString()}\\n\\nThis release is automatically updated when the calendar file changes.`, + draft: false, + prerelease: false + }); + release = newRelease.data; + } else { + throw error; + } + } + + // Upload the iCal file + const fileContent = fs.readFileSync('cpp-aachen.ics'); + + await github.rest.repos.uploadReleaseAsset({ + owner, + repo, + release_id: release.id, + name: 'cpp-aachen.ics', + data: fileContent, + headers: { + 'content-type': 'text/calendar' + } + }); + + core.info(`Successfully uploaded cpp-aachen.ics to release ${release.tag_name}`);