Skip to content

Commit 0dffb33

Browse files
authored
Merge pull request #1 from SeriyBg/master
Add auto increment of event numbers
2 parents b0c1ac2 + 71ba330 commit 0dffb33

1 file changed

Lines changed: 27 additions & 14 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
inputs:
55
post_title:
66
description: 'Used for filename and post.sh name. The space will be replaced by `-` inv the file name.'
7-
default: 'Event#'
7+
default: ''
88
required: true
99
post_body:
1010
description: 'Use GitHub MD format'
@@ -24,23 +24,36 @@ jobs:
2424
runs-on: ubuntu-latest
2525

2626
env:
27-
FILENAME: ./_posts/$(date +'%Y-%m-%d')-$( echo '${{ github.event.inputs.post_title }}' | sed -r 's/[# ]+/-/g' ).md
27+
FILENAME_PREFIX: ./_posts/$(date +'%Y-%m-%d')-
2828
MESSAGE: ${{ github.event.inputs.post_body }}
29-
POST: |
30-
---
31-
layout: post
32-
title: \"${{ github.event.inputs.post_title }}\"
33-
image: /images/default.jpg
34-
tags: [${{ github.event.inputs.tags }}]
35-
date: $(date +'%Y-%m-%d %H:%M:%S %z')
36-
video:
37-
---
38-
39-
${{ github.event.inputs.post_body }}
4029
JOIN: Join us next Thursday, at 10:00 ${{ github.event.inputs.room }}
4130
steps:
4231
- name: Checkout repository
4332
uses: actions/checkout@v2
33+
34+
- name: Calculate event number
35+
run: |
36+
lastEvent=$(ls -LR1 | sed -E 's/[0-9]{4}-[0-9]{2}-[0-9]{2}-//;s/Event-//;s/-.*//;s/.md//' | sort -n | tail -1)
37+
nextEvent=$((lastEvent+1))
38+
filename=$( echo "Event-$nextEvent-${{ github.event.inputs.post_title }}" | sed -r 's/[ ]+/-/g' ).md
39+
echo "next_event=$nextEvent" >> $GITHUB_ENV
40+
echo "FILENAME=${{ env.FILENAME_PREFIX }}${filename}" >> $GITHUB_ENV
41+
42+
- name: Create post
43+
run: |
44+
date=$(date +'%Y-%m-%d %H:%M:%S %z')
45+
echo "POST<<EOF" >> $GITHUB_ENV
46+
echo "---" >> $GITHUB_ENV
47+
echo "layout: post" >> $GITHUB_ENV
48+
echo "title: \"Event#${{ env.next_event }} ${{ github.event.inputs.post_title }}\"" >> $GITHUB_ENV
49+
echo "image: /images/default.jpg" >> $GITHUB_ENV
50+
echo "tags: [${{ github.event.inputs.tags }}]" >> $GITHUB_ENV
51+
echo "date: $date" >> $GITHUB_ENV
52+
echo "video: " >> $GITHUB_ENV
53+
echo "---" >> $GITHUB_ENV
54+
echo '' >> $GITHUB_ENV
55+
echo "${{ github.event.inputs.post_body }}" >> $GITHUB_ENV
56+
echo "EOF" >> $GITHUB_ENV
4457
4558
- name: Create post file
4659
run: |
@@ -51,6 +64,6 @@ jobs:
5164
git config --global user.email "releases@lvivjavaclub.github.io"
5265
git config --global user.name "GitHub actions"
5366
git add ${{ env.FILENAME }}
54-
git commit -m 'Create ${{ github.event.inputs.post_title }}'
67+
git commit -m 'Create Event#${{ env.next_event }} ${{ github.event.inputs.post_title }}'
5568
git push
5669

0 commit comments

Comments
 (0)