|
6 | 6 |
|
7 | 7 | jobs: |
8 | 8 | generate-newsletter: |
9 | | - if: contains(github.event.issue.title, 'Newsletter Draft:') |
| 9 | + if: contains(github.event.issue.title, 'Newsletter Draft') |
10 | 10 | runs-on: ubuntu-latest |
11 | 11 |
|
12 | 12 | steps: |
13 | 13 | - name: Checkout repository |
14 | 14 | uses: actions/checkout@v3 |
15 | 15 |
|
16 | | - - name: Extract inputs from issue body |
| 16 | + - name: Extract values from issue body |
17 | 17 | id: vars |
18 | 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:]') |
| 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}" |
23 | 25 | filename="_posts/${date}-newsletter.md" |
24 | 26 |
|
25 | 27 | echo "month=$month" >> $GITHUB_OUTPUT |
| 28 | + echo "month_num=$month_num" >> $GITHUB_OUTPUT |
26 | 29 | echo "year=$year" >> $GITHUB_OUTPUT |
27 | 30 | echo "date=$date" >> $GITHUB_OUTPUT |
| 31 | + echo "branch=$branch" >> $GITHUB_OUTPUT |
28 | 32 | echo "filename=$filename" >> $GITHUB_OUTPUT |
29 | 33 |
|
30 | | - - name: Generate newsletter file from template |
| 34 | + - name: Create feature branch from develop |
31 | 35 | 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 |
34 | 38 |
|
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 }}" |
38 | 45 |
|
39 | | - - name: Commit and push draft |
| 46 | + - name: Commit and push |
40 | 47 | run: | |
41 | | - branch="draft-newsletter-${{ steps.vars.outputs.month }}-${{ steps.vars.outputs.year }}" |
42 | | - git checkout -b "$branch" |
43 | 48 | git config user.name "github-actions[bot]" |
44 | 49 | 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 }}" |
46 | 51 | 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 }}" |
48 | 53 |
|
49 | | - - name: Comment on issue |
| 54 | + - name: Comment on issue with branch details |
50 | 55 | env: |
51 | 56 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
52 | 57 | run: | |
53 | 58 | 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