-
-
Notifications
You must be signed in to change notification settings - Fork 55
116 lines (101 loc) · 3.98 KB
/
create-discussions.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: Create GitHub Discussions
on:
pull_request:
types: [closed]
branches:
- main
paths:
- "src/content/apps/**"
workflow_dispatch:
inputs:
name:
description: "App Name"
required: true
type: string
author:
description: "App Author"
required: true
type: string
description:
description: "App Description"
required: true
type: string
jobs:
create-discussion:
if: >
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'pull_request' &&
github.event.pull_request.merged == true)
runs-on: ubuntu-latest
permissions:
discussions: write
pull-requests: read
contents: read
repository-projects: read
steps:
- uses: actions/checkout@v4
with:
ref: main # Explicitly checkout main branch
fetch-depth: 0 # Fetch all history
- name: Get App Dataf
id: app-data
run: |
# Debug git status
git status
echo "Current SHA: $(git rev-parse HEAD)"
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 files changed in this PR
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep '^src/content/apps/.*\.md$' || true)
echo "Found changed files:"
echo "$CHANGED_FILES"
if [ -z "$CHANGED_FILES" ]; then
echo "No relevant files changed"
exit 1
fi
# Use the first changed file
CHANGED_FILE=$(echo "$CHANGED_FILES" | head -n 1)
echo "Processing file: $CHANGED_FILE"
echo "File contents:"
cat "$CHANGED_FILE"
# Extract metadata using yq or manual parsing
NAME=$(grep '^name: ' "$CHANGED_FILE" | cut -d'"' -f2)
AUTHOR=$(grep '^author: ' "$CHANGED_FILE" | cut -d'"' -f2)
# Extract description - capture everything between the quotes
DESCRIPTION=$(sed -n '/^description: /,/dateLaunched:/p' "$CHANGED_FILE" | \
sed '1s/^description: "//;$s/dateLaunched.*//;s/"$//' | \
tr '\n' ' ' | sed 's/ */ /g')
echo "---Extracted Name: $NAME"
echo "Extracted Author: $AUTHOR"
echo "Extracted Description: $DESCRIPTION"
# 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
# Check if app already has a discussion by looking in votes file
if grep -q "\"$NAME\":" src/data/votes_*.json; then
echo "Discussion already exists for $NAME"
exit 1
fi
# Set outputs
echo "name=$NAME" >> $GITHUB_OUTPUT
echo "author=$AUTHOR" >> $GITHUB_OUTPUT
echo "description=$DESCRIPTION" >> $GITHUB_OUTPUT
fi
echo "year=$(date +%Y)" >> $GITHUB_OUTPUT
- name: Create Discussion
uses: abirismyname/[email protected]
with:
title: "Vote 2024: ${{ 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: R_kgDONX26mg
category-id: DIC_kwDONX26ms4Ck8X2
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}