-
Notifications
You must be signed in to change notification settings - Fork 1
145 lines (124 loc) · 4.9 KB
/
share-new-blog-posts.yml
File metadata and controls
145 lines (124 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
---
name: Share new blog posts
on:
workflow_dispatch:
inputs:
#checkov:skip=CKV_GHA_7: required
post-folder:
description: "Blog post folder name under application/src/data/post/<folder>"
required: true
type: string
workflow_call:
permissions:
contents: read
pages: read
jobs:
announce:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
fetch-depth: 0
- name: Detect new blog posts (changed-files)
id: changes
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files: |
application/src/data/post/**/common.yaml
since_last_remote_commit: true
- name: Detect new blog posts
id: detect
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
ADDED_FILES: ${{ steps.changes.outputs.added_files }}
MANUAL_POST_FOLDER: ${{ github.event.inputs.post-folder }}
with:
script: |
const addedFilesRaw = process.env.ADDED_FILES || '';
const manualPostFolderRaw = process.env.MANUAL_POST_FOLDER || '';
const uniquePreserveOrder = (items) => {
const seen = new Set();
const result = [];
for (const item of items) {
if (!item || seen.has(item)) continue;
seen.add(item);
result.push(item);
}
return result;
};
const parseManualPostFolder = (raw) => {
const folder = `${raw || ''}`.trim();
if (!folder) return [];
return uniquePreserveOrder([folder]);
};
const parseFoldersFromChangedFiles = (raw) => {
const lines = raw
.split(/\r?\n/)
.map((line) => line.trim())
.filter(Boolean);
const folders = [];
const folderRegex = /\/post\/([^/]+)\/common\.yaml$/;
for (const filePath of lines) {
const match = filePath.match(folderRegex);
if (match) {
folders.push(match[1]);
}
}
return uniquePreserveOrder(folders);
};
const manualPosts = parseManualPostFolder(manualPostFolderRaw);
const detectedPosts = parseFoldersFromChangedFiles(addedFilesRaw);
const posts = manualPosts.length > 0 ? manualPosts : detectedPosts;
core.setOutput('posts', posts.join('\n'));
core.setOutput('count', `${posts.length}`);
- name: Resolve site base URL
id: site
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const { owner, repo } = context.repo;
const normalizeUrl = (value) => {
const url = `${value || ''}`.trim();
if (!url) return '';
if (!/^https?:\/\//i.test(url)) {
throw new Error(`Resolved site URL must start with http(s)://, got: ${url}`);
}
return url.replace(/\/$/, '');
};
let siteBaseUrl = '';
try {
const { data } = await github.rest.repos.getPages({ owner, repo });
siteBaseUrl = data?.html_url || '';
core.info(`Using GitHub Pages URL: ${siteBaseUrl}`);
} catch (error) {
core.info('No GitHub Pages URL found via API; falling back to repository homepage.');
}
if (!siteBaseUrl) {
const { data: repoData } = await github.rest.repos.get({ owner, repo });
siteBaseUrl = repoData?.homepage || '';
if (siteBaseUrl) {
core.info(`Using repository homepage URL: ${siteBaseUrl}`);
}
}
siteBaseUrl = normalizeUrl(siteBaseUrl);
if (!siteBaseUrl) {
core.setFailed(
'Unable to resolve site base URL from GitHub Pages or repository homepage. Enable GitHub Pages or set the repository homepage URL.'
);
return;
}
core.setOutput('site-base-url', siteBaseUrl);
- name: Share posts via Postiz
if: steps.detect.outputs.count != '0'
uses: ./.github/actions/share-blog-post
with:
language: fr
posts: ${{ steps.detect.outputs.posts }}
site-base-url: ${{ steps.site.outputs.site-base-url }}
blog-base-path: /blog
openai-api-key: ${{ secrets.COPILOT_MCP_OPENAI_API_KEY }}
postiz-api-url: ${{ vars.POSTIZ_API_URL }}
postiz-api-key: ${{ secrets.POSTIZ_API_KEY }}
postiz-integrations: ${{ vars.POSTIZ_INTEGRATIONS }}