Skip to content

Commit

Permalink
Print year, and get full name
Browse files Browse the repository at this point in the history
  • Loading branch information
tadaspetra committed Dec 8, 2024
1 parent 3fb9f06 commit 6ba041c
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions .github/workflows/create-discussions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,48 +63,38 @@ jobs:
exit 0
fi
# Verify file exists and show contents
# 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 more robust patterns
NAME=$(awk '/^name: / {gsub(/"/, "", $2); print $2}' "$CHANGED_FILE")
AUTHOR=$(awk '/^author: / {gsub(/"/, "", $2); print $2}' "$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 - handling multi-line content between description: and dateLaunched:
DESCRIPTION=$(awk '/^description: /{p=1;next} /^dateLaunched:/{p=0} p' "$CHANGED_FILE" | \
sed 's/^"//;s/"$//;s/^[[:space:]]*//')
# 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')
# Debug output
echo "Extracted Name: $NAME"
echo "---Extracted Name: $NAME"
echo "Extracted Author: $AUTHOR"
echo "Extracted Description: $DESCRIPTION"
# 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 0
fi
# 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
# Properly escape the values for GitHub Actions output
NAME="${NAME//'%'/'%25'}"
NAME="${NAME//$'\n'/'%0A'}"
NAME="${NAME//$'\r'/'%0D'}"
AUTHOR="${AUTHOR//'%'/'%25'}"
AUTHOR="${AUTHOR//$'\n'/'%0A'}"
AUTHOR="${AUTHOR//$'\r'/'%0D'}"
DESCRIPTION="${DESCRIPTION//'%'/'%25'}"
DESCRIPTION="${DESCRIPTION//$'\n'/'%0A'}"
DESCRIPTION="${DESCRIPTION//$'\r'/'%0D'}"
# 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 0
fi
# Set outputs
echo "name=$NAME" >> $GITHUB_OUTPUT
echo "author=$AUTHOR" >> $GITHUB_OUTPUT
echo "description=$DESCRIPTION" >> $GITHUB_OUTPUT
Expand All @@ -114,7 +104,7 @@ jobs:
- name: Create Discussion
uses: abirismyname/[email protected]
with:
title: "Vote ${{ steps.app-data.outputs.year }}: ${{ steps.app-data.outputs.name }} by ${{ steps.app-data.outputs.author }}"
title: "Vote 2024: ${{ steps.app-data.outputs.name }} by ${{ steps.app-data.outputs.author }}"
body: |
**Vote for this app by giving it an upvote!**
Expand Down

0 comments on commit 6ba041c

Please sign in to comment.