Skip to content

Event Submission

Event Submission #5

name: Event Submission
on:
workflow_dispatch:
inputs:
title:
description: 'Event Title'
required: true
date:
description: 'Event Date (DD Month YYYY)'
required: true
by:
description: 'Organizing Club/Department'
required: true
registrationLink:
description: 'Registration Link'
required: true
description:
description: 'Event Description (as HTML is appreciated)'
required: true
category:
description: 'Categories (comma-separated)'
required: true
display:
description: 'Display sections (1 - Trending, 2 - Latest, 3 - Department)'
required: true
image_url:
description: 'Event image URL (Link from postimages.org)'
required: true
jobs:
add-event:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Process image and detect format
run: |
# Convert "by" field to lowercase
LOWER_BY=$(echo "${{ github.event.inputs.by }}" | tr '[:upper:]' '[:lower:]')
mkdir -p "public/photos/events/$LOWER_BY"
curl -o temp_image "${{ github.event.inputs.image_url }}"
FILE_TYPE=$(file -b --mime-type temp_image)
if [ "$FILE_TYPE" = "image/jpeg" ]; then
EXTENSION="jpg"
elif [ "$FILE_TYPE" = "image/png" ]; then
EXTENSION="png"
else
echo "Error: Unsupported image format. Only JPG and PNG are supported."
exit 1
fi
mv temp_image "public/photos/events/$LOWER_BY/${{ github.event.inputs.title }}.$EXTENSION"
echo "IMAGE_EXTENSION=$EXTENSION" >> $GITHUB_ENV
- name: Update events data
run: |
node -e '
const fs = require("fs");
const path = require("path");
const eventsPath = "src/data/event.ts";
const eventsFile = fs.readFileSync(eventsPath, "utf8");
const events = require("./src/data/event.ts").EventDatas;
const LOWER_BY = "${{ github.event.inputs.by }}".toLowerCase();
const newEvent = {
id: Math.max(...events.map(e => e.id)) + 1,
title: "${{ github.event.inputs.title }}",
by: "${{ github.event.inputs.by }}",
avatar: `/photos/clubs/${LOWER_BY}.jpg`,
date: "${{ github.event.inputs.date }}",
registrationLink: "${{ github.event.inputs.registrationLink }}",
description: `${{ github.event.inputs.description }}`,
image: `/photos/events/${LOWER_BY}/${{ github.event.inputs.title }}.${process.env.IMAGE_EXTENSION}`,
category: "${{ github.event.inputs.category }}".split(",").map(c => c.trim()),
display: "${{ github.event.inputs.display }}".split(",").map(d => parseInt(d.trim()))
};
events.unshift(newEvent);
const newContent = `import { EventData } from "./interface";\n\nconst EventDatas: EventData[] = ${JSON.stringify(events, null, 2)};\n\nexport { EventDatas };`;
fs.writeFileSync(eventsPath, newContent);
'
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
title: 'New Event: ${{ github.event.inputs.title }}'
body: |
New event submission from ${{ github.event.inputs.by }}
- Title: ${{ github.event.inputs.title }}
- Date: ${{ github.event.inputs.date }}
- Categories: ${{ github.event.inputs.category }}
Please review and approve this event submission.
branch: main # Work on prod