Skip to content

Commit

Permalink
Merge branch 'main' into revert-7-revert-5-roads-audio
Browse files Browse the repository at this point in the history
  • Loading branch information
tadaspetra committed Dec 6, 2024
2 parents 09e34a2 + 954d7cf commit b05e749
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions .github/workflows/create-discussions.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,75 @@
name: Create GitHub Discussions

on:
pull_request:
types: [closed]
push:
branches:
- main
paths:
- 'src/content/apps/**'
- "src/content/apps/**"
workflow_dispatch:
inputs:
name:
description: 'App Name'
description: "App Name"
required: true
type: string
author:
description: 'App Author'
description: "App Author"
required: true
type: string
description:
description: 'App Description'
description: "App Description"
required: true
type: string

jobs:
create-discussion:
if: github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
runs-on: ubuntu-latest
permissions:
discussions: write
pull-requests: read
contents: read
steps:
- uses: actions/checkout@v4

- name: Get App Data
id: app-data
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
# For manual triggers, use the input parameters
echo "name=${{ inputs.name }}" >> $GITHUB_OUTPUT
echo "author=${{ inputs.author }}" >> $GITHUB_OUTPUT
echo "description=${{ inputs.description }}" >> $GITHUB_OUTPUT
else
# Get the changed file path from the PR
CHANGED_FILE=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep '^src/content/apps/.*\.md$')
# For push events, get the changed files
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | grep '^src/content/apps/.*\.md$' || true)
# Check if we found any changed files
if [ -z "$CHANGED_FILES" ]; then
echo "No relevant files changed"
exit 0
fi
# Use the first changed file
CHANGED_FILE=$(echo "$CHANGED_FILES" | head -n 1)
# Verify file exists
if [ ! -f "$CHANGED_FILE" ]; then
echo "File $CHANGED_FILE not found"
exit 1
fi
# Extract data using grep and sed
# Extract data using grep and sed with error checking
NAME=$(grep -m 1 '^name: ' "$CHANGED_FILE" | sed 's/^name: "\(.*\)"$/\1/')
AUTHOR=$(grep -m 1 '^author: ' "$CHANGED_FILE" | sed 's/^author: "\(.*\)"$/\1/')
DESCRIPTION=$(grep -m 1 '^description: ' "$CHANGED_FILE" | sed 's/^description: "\(.*\)"$/\1/')
# Verify we got all required data
if [ -z "$NAME" ] || [ -z "$AUTHOR" ] || [ -z "$DESCRIPTION" ]; then
echo "Failed to extract required metadata from $CHANGED_FILE"
exit 1
fi
echo "name=$NAME" >> $GITHUB_OUTPUT
echo "author=$AUTHOR" >> $GITHUB_OUTPUT
echo "description=$DESCRIPTION" >> $GITHUB_OUTPUT
Expand All @@ -59,7 +82,7 @@ jobs:
title: "Vote ${{ steps.app-data.outputs.year }}: ${{ steps.app-data.outputs.name }} by ${{ steps.app-data.outputs.author }}"
body: |
**Vote for this app by giving it an upvote!**
${{ steps.app-data.outputs.description }}
repository-id: ${{ secrets.REPO_ID }}
category-id: ${{ secrets.CAT_ID }}
Expand Down

0 comments on commit b05e749

Please sign in to comment.