-
Notifications
You must be signed in to change notification settings - Fork 0
251 lines (206 loc) · 7.61 KB
/
main.yaml
File metadata and controls
251 lines (206 loc) · 7.61 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
name: CI Pipeline
on:
push:
branches: [ main ]
pull_request:
branches: [ '*' ]
workflow_dispatch:
inputs:
AUTOMATE_CONTENT:
description: "Set AUTOMATE_CONTENT to trigger automate-content job"
required: false
default: ""
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
automate-content:
if: ${{ inputs.automate_content != '' }}
runs-on: [self-hosted, macOS]
concurrency:
group: automate-content
cancel-in-progress: true
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine Skip Build Option
env:
INPUT_SKIP_BUILD: ${{ github.event.inputs.skip_build }}
run: |
if [[ "${INPUT_SKIP_BUILD}" == "true" ]]; then
echo "Build will be skipped (--skip-build option will be used)"
echo "SKIP_BUILD_OPTION=--skip-build" >> $GITHUB_ENV
else
echo "Build will NOT be skipped (--skip-build option will be empty)"
echo "SKIP_BUILD_OPTION=" >> $GITHUB_ENV
fi
- name: Import Mailchimp
env:
MAILCHIMP_API_KEY: ${{ secrets.MAILCHIMP_API_KEY }}
MAILCHIMP_LIST_ID: ${{ secrets.MAILCHIMP_LIST_ID }}
run: |
echo "Importing Mailchimp..."
swift run $SKIP_BUILD_OPTION brightdigitwg \
import mailchimp \
--mailchimp-api-key=$MAILCHIMP_API_KEY \
--mailchimp-list-id=$MAILCHIMP_LIST_ID \
--export-markdown-directory=Content/newsletters
echo "Mailchimp import finished."
- name: Import Podcast
env:
YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }}
run: |
echo "Importing Podcast..."
swift run $SKIP_BUILD_OPTION brightdigitwg \
import podcast \
--youtube-api-key=$YOUTUBE_API_KEY \
--export-markdown-directory Content/episodes
echo "Podcast import finished."
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Check Changes, Commit, and Push
run: |
# Check if there are any changes (staged or unstaged)
# git status --porcelain will output lines if there are changes
if [[ -n "$(git status --porcelain)" ]]; then
echo "Changes detected. Proceeding with commit and push."
TODAY_DATE=$(date '+%y%m%d%H%M')
CHANGES_COUNT=$(git status --porcelain | wc -l | xargs)
COMMIT_MESSAGE="Bot:- ${TODAY_DATE} - ${CHANGES_COUNT} new changes"
git add .
git commit -m "${COMMIT_MESSAGE}"
# Ensure your runner has credentials (PAT via checkout or SSH key) to push
git push origin ${{ github.head_ref }}
echo "Changes pushed successfully."
else
echo "No changes detected. Nothing to commit or push."
fi
build-linux:
runs-on: ubuntu-latest
container:
image: brightdigit/publish-xml
concurrency:
group: build
cancel-in-progress: true
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache SwiftPM Dependencies
uses: actions/cache@v4
with:
path: .build/
key: ${{ runner.os }}-build-${{ hashFiles('Package.resolved') }}
- name: Configure Architecture Prefix
run: |
export ARCH_PREFIX=$(uname -i)
echo "ARCH_PREFIX=${ARCH_PREFIX}" >> $GITHUB_ENV
- name: Build with Swift
run: swift build
- name: Run Tests with Swift
run: swift test
package-linux:
needs: build-linux
runs-on: ubuntu-latest
container:
image: brightdigit/publish-xml
concurrency:
group: package
cancel-in-progress: true
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache SwiftPM Dependencies
uses: actions/cache@v4
with:
path: .build/
key: ${{ runner.os }}-release-${{ hashFiles('Package.resolved', 'Sources/**/*.swift') }}
- name: Build Release Product
run: |
swift build -c release --product brightdigitwg
BIN_PATH=$(swift build -c release --product brightdigitwg --show-bin-path)
cp "$BIN_PATH/brightdigitwg" "brightdigitwg-$(uname)-$(arch)"
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: brightdigitwg-binaries
path: brightdigitwg-*
# build-macos:
# runs-on: [self-hosted, macOS]
# concurrency:
# group: build-macos
# cancel-in-progress: true
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Cache SwiftPM Dependencies
# uses: actions/cache@v4
# with:
# path: .build/
# key: ${{ runner.os }}-${{ hashFiles('Package.resolved') }}
# - name: Build with Swift
# run: swift build
# - name: Run Tests with Swift
# run: swift test
# package-macos:
# needs: build-macos
# runs-on: [self-hosted, macOS]
# concurrency:
# group: build
# cancel-in-progress: true
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Cache SwiftPM Dependencies
# uses: actions/cache@v4
# with:
# path: .build/
# key: ${{ runner.os }}-${{ hashFiles('Package.resolved') }}
# - name: Build Release Product
# run: |
# swift build -c release --product brightdigitwg
# BIN_PATH=$(swift build -c release --product brightdigitwg --show-bin-path)
# cp "$BIN_PATH/brightdigitwg" "brightdigitwg-$(uname)-$(arch)"
# - name: Upload Artifact
# uses: actions/upload-artifact@v4
# with:
# name: brightdigitwg-binaries
# path: brightdigitwg-*
deploy:
needs: package-linux
runs-on: ubuntu-latest
container:
image: brightdigit/publish-xml
concurrency:
group: deploy
cancel-in-progress: true
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: brightdigitwg-binaries
- name: Set Publishing Mode and Flags
id: set-publishing
run: |
if [ "${{ github.ref_name }}" = "main" ]; then
echo "PUBLISHING_MODE=production" >> $GITHUB_ENV
echo "PROD_FLAG=--prod" >> $GITHUB_ENV
else
echo "PUBLISHING_MODE=drafts" >> $GITHUB_ENV
echo "PROD_FLAG=" >> $GITHUB_ENV
fi
- name: Run Brightdigitwg
run: |
chmod +x "brightdigitwg-$(uname)-$(arch)"
./brightdigitwg-$(uname)-$(arch) publish --mode $PUBLISHING_MODE
- name: Deploy to Netlify
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_PRODUCTION_SITE_ID: ${{ secrets.NETLIFY_PRODUCTION_SITE_ID }}
run: |
netlify deploy --site $NETLIFY_PRODUCTION_SITE_ID --auth $NETLIFY_AUTH_TOKEN $PROD_FLAG