Skip to content

Commit 8c7ed30

Browse files
Update generate-newsletter.yml
1 parent 1bd13a7 commit 8c7ed30

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

.github/workflows/generate-newsletter.yml

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,60 @@ on:
66

77
jobs:
88
generate-newsletter:
9-
if: contains(github.event.issue.title, 'Newsletter Draft:')
9+
if: contains(github.event.issue.title, 'Newsletter Draft')
1010
runs-on: ubuntu-latest
1111

1212
steps:
1313
- name: Checkout repository
1414
uses: actions/checkout@v3
1515

16-
- name: Extract inputs from issue body
16+
- name: Extract values from issue body
1717
id: vars
1818
run: |
19-
month=$(echo "${{ github.event.issue.body }}" | grep -i "Month" -A 1 | tail -n 1 | xargs)
20-
year=$(echo "${{ github.event.issue.body }}" | grep -i "Year" -A 1 | tail -n 1 | xargs)
21-
date="${year}-$(date +%m)-01"
22-
slug_month=$(echo "$month" | tr '[:upper:]' '[:lower:]')
19+
month=$(echo "${{ github.event.issue.body }}" | grep -i "Newsletter Month" -A 1 | tail -n 1 | xargs)
20+
year=$(echo "${{ github.event.issue.body }}" | grep -i "Newsletter Year" -A 1 | tail -n 1 | xargs)
21+
# Convert month name to MM
22+
month_num=$(date -d "$month 1" '+%m')
23+
date="${year}-${month_num}-01"
24+
branch="feature/newsletter-${year}-${month_num}"
2325
filename="_posts/${date}-newsletter.md"
2426
2527
echo "month=$month" >> $GITHUB_OUTPUT
28+
echo "month_num=$month_num" >> $GITHUB_OUTPUT
2629
echo "year=$year" >> $GITHUB_OUTPUT
2730
echo "date=$date" >> $GITHUB_OUTPUT
31+
echo "branch=$branch" >> $GITHUB_OUTPUT
2832
echo "filename=$filename" >> $GITHUB_OUTPUT
2933
30-
- name: Generate newsletter file from template
34+
- name: Create feature branch from develop
3135
run: |
32-
mkdir -p _posts
33-
cp _template/newsletter-template.md ${{ steps.vars.outputs.filename }}
36+
git fetch origin develop
37+
git checkout -b "${{ steps.vars.outputs.branch }}" origin/develop
3438
35-
sed -i "s/{{ month }}/${{ steps.vars.outputs.month }}/g" ${{ steps.vars.outputs.filename }}
36-
sed -i "s/{{ year }}/${{ steps.vars.outputs.year }}/g" ${{ steps.vars.outputs.filename }}
37-
sed -i "s/{{ date }}/${{ steps.vars.outputs.date }}/g" ${{ steps.vars.outputs.filename }}
39+
- name: Generate newsletter draft from template
40+
run: |
41+
cp _template/newsletter-template.md "${{ steps.vars.outputs.filename }}"
42+
sed -i "s/{{ month }}/${{ steps.vars.outputs.month }}/g" "${{ steps.vars.outputs.filename }}"
43+
sed -i "s/{{ year }}/${{ steps.vars.outputs.year }}/g" "${{ steps.vars.outputs.filename }}"
44+
sed -i "s/{{ date }}/${{ steps.vars.outputs.date }}/g" "${{ steps.vars.outputs.filename }}"
3845
39-
- name: Commit and push draft
46+
- name: Commit and push
4047
run: |
41-
branch="draft-newsletter-${{ steps.vars.outputs.month }}-${{ steps.vars.outputs.year }}"
42-
git checkout -b "$branch"
4348
git config user.name "github-actions[bot]"
4449
git config user.email "github-actions[bot]@users.noreply.github.com"
45-
git add ${{ steps.vars.outputs.filename }}
50+
git add "${{ steps.vars.outputs.filename }}"
4651
git commit -m "Add newsletter draft for ${{ steps.vars.outputs.month }} ${{ steps.vars.outputs.year }}"
47-
git push origin "$branch"
52+
git push origin "${{ steps.vars.outputs.branch }}"
4853
49-
- name: Comment on issue
54+
- name: Comment on issue with branch details
5055
env:
5156
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5257
run: |
5358
gh issue comment ${{ github.event.issue.number }} \
54-
--body "✅ Draft created: [${{ steps.vars.outputs.filename }}](https://github.com/${{ github.repository }}/blob/${branch}/${{ steps.vars.outputs.filename }}) in branch \`${branch}\`"
59+
--body "✅ Draft file created for **${{ steps.vars.outputs.month }} ${{ steps.vars.outputs.year }}** at \`${{ steps.vars.outputs.filename }}\` in branch \`${{ steps.vars.outputs.branch }}\`.
60+
61+
You can now:
62+
1. Open the branch in VS Code using GitFlow (`feature/newsletter-${{ steps.vars.outputs.year }}-${{ steps.vars.outputs.month_num }}`)
63+
2. Edit and review the draft
64+
3. Open a PR into \`develop\` when ready
65+
"

0 commit comments

Comments
 (0)