Skip to content

Commit d581e61

Browse files
Update post date on merge to main (#116)
* Update post date on merge to main
1 parent 5988e24 commit d581e61

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

.github/workflows/merge.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Publish article
2+
3+
on:
4+
push:
5+
branches: ['main']
6+
7+
jobs:
8+
check-unpublished:
9+
runs-on: ubuntu-latest
10+
outputs:
11+
should_publish: ${{ steps.should-publish.outputs.should_publish }}
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v3
15+
- name: Should publish
16+
id: should-publish
17+
run: echo "should_publish=$([[ -d "content/posts/unpublished" ]] && echo true || echo false)" >> "$GITHUB_OUTPUT"
18+
19+
publish:
20+
runs-on: ubuntu-latest
21+
needs: check-unpublished
22+
if: ${{ needs.check-unpublished.outputs.should_publish == 'true' }}
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v3
26+
with:
27+
token: ${{ secrets.BOSS_TOKEN }}
28+
- uses: actions/setup-node@v3
29+
with:
30+
node-version: 20
31+
- name: Move article to current date directory
32+
run: |
33+
npm ci
34+
npm run build:utils
35+
npm run posts:publish
36+
37+
- name: Commit changes
38+
run: |
39+
git config --local user.email "oss@backbase.com"
40+
git config --local user.name "backbaseoss"
41+
git add content
42+
git commit -m "[BOT] Post published"
43+
44+
- name: Push changes
45+
uses: ad-m/github-push-action@master
46+
with:
47+
github_token: ${{ secrets.BOSS_TOKEN }}
48+
branch: ${{ github.ref }}

.github/workflows/static.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,21 @@ concurrency:
2222
cancel-in-progress: false
2323

2424
jobs:
25+
check-unpublished:
26+
runs-on: ubuntu-latest
27+
outputs:
28+
should_deploy: ${{ steps.should-publish.outputs.should_deploy }}
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v3
32+
- name: Should publish
33+
id: should-publish
34+
run: echo "should_deploy=$([[ -d "content/posts/unpublished" ]] && echo false || echo true)" >> "$GITHUB_OUTPUT"
35+
2536
# Single deploy job since we're just deploying
2637
deploy:
38+
needs: check-unpublished
39+
if: ${{ needs.check-unpublished.outputs.should_deploy == 'true' }}
2740
environment:
2841
name: github-pages
2942
url: ${{ steps.deployment.outputs.page_url }}

tools/publish/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ async function moveUnpublishedDirectory(sourcePath, destinationRoot) {
6969

7070
// Remove the "unpublished" directory
7171
fs.rmdirSync(unpublishedPath);
72+
73+
if (isDirectoryEmpty(sourcePath)) {
74+
fs.rmdirSync(sourcePath);
75+
}
76+
7277
console.log('Unpublished directory removed.');
7378
} else {
7479
console.log('No "unpublished" directory found.');
@@ -90,3 +95,13 @@ main();
9095
function loadEsmModule(modulePath) {
9196
return new Function('modulePath', `return import(modulePath);`)(modulePath);
9297
}
98+
99+
function isDirectoryEmpty(path) {
100+
let empty = false;
101+
if (fs.existsSync(path)) {
102+
const files = fs.readdirSync(path);
103+
empty = !files?.length
104+
}
105+
return empty;
106+
}
107+

0 commit comments

Comments
 (0)