Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions .github/workflows/calendar-release.yml
Original file line number Diff line number Diff line change
@@ -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}`);