Event Submission #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: Create new event branch | |
# run: | | |
# git config --global user.name 'GitHub Action' | |
# git config --global user.email 'action@github.com' | |
# branch_name="event-${{ github.event.inputs.title }}" | |
# git checkout -b $branch_name | |
- name: Process image and detect format | |
run: | | |
mkdir -p "public/photos/events/${{ github.event.inputs.by }}" | |
curl "${{ github.event.inputs.image_url }}" > temp_image | |
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/${{ github.event.inputs.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 newEvent = { | |
id: Math.max(...events.map(e => e.id)) + 1, | |
title: "${{ github.event.inputs.title }}", | |
by: "${{ github.event.inputs.by }}", | |
avatar: `/photos/clubs/${${{ github.event.inputs.by }}.toLowerCase()}.jpg`, | |
date: "${{ github.event.inputs.date }}", | |
registrationLink: "${{ github.event.inputs.registrationLink }}", | |
description: `${{ github.event.inputs.description }}`, | |
image: `/photos/events/${${{ github.event.inputs.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: event-${{ github.event.inputs.title }} | |
branch: main # Work on prod | |
# delete-branch: true |