Skip to content

Commit 73b1e6d

Browse files
Create generate-newsletter.yml
1 parent 1c2b3af commit 73b1e6d

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Generate Newsletter File
2+
3+
on:
4+
issues:
5+
types: [opened]
6+
7+
jobs:
8+
generate-newsletter:
9+
if: contains(github.event.issue.title, 'Newsletter Draft:')
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v3
15+
16+
- name: Extract inputs from issue body
17+
id: vars
18+
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:]')
23+
filename="_posts/${date}-newsletter.md"
24+
25+
echo "month=$month" >> $GITHUB_OUTPUT
26+
echo "year=$year" >> $GITHUB_OUTPUT
27+
echo "date=$date" >> $GITHUB_OUTPUT
28+
echo "filename=$filename" >> $GITHUB_OUTPUT
29+
30+
- name: Generate newsletter file from template
31+
run: |
32+
mkdir -p _posts
33+
cp _template/newsletter-template.md ${{ steps.vars.outputs.filename }}
34+
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 }}
38+
39+
- name: Commit and push draft
40+
run: |
41+
branch="draft-newsletter-${{ steps.vars.outputs.month }}-${{ steps.vars.outputs.year }}"
42+
git checkout -b "$branch"
43+
git config user.name "github-actions[bot]"
44+
git config user.email "github-actions[bot]@users.noreply.github.com"
45+
git add ${{ steps.vars.outputs.filename }}
46+
git commit -m "Add newsletter draft for ${{ steps.vars.outputs.month }} ${{ steps.vars.outputs.year }}"
47+
git push origin "$branch"
48+
49+
- name: Comment on issue
50+
env:
51+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
run: |
53+
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}\`"

0 commit comments

Comments
 (0)