Repository navigation
118 lines (112 loc) · 4.47 KB
/
Copy pathengine-core.ci.yml
File metadata and controls
118 lines (112 loc) · 4.47 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
name: CI | Engine core | github repository
on:
workflow_dispatch:
inputs:
sync:
description: 'Trigger sync-and-deploy CD after build'
required: false
default: 'false'
type: choice
options:
- 'true'
- 'false'
message:
description: 'Commit message for the build'
required: false
default: ''
deploy_type:
description: 'CD job type to dispatch (sync-and-deploy or init)'
required: false
default: 'sync-and-deploy'
type: choice
options:
- sync-and-deploy
- init
permissions:
contents: write
packages: write
id-token: write
jobs:
pwa-microservices-template:
name: Update github repo package Jobs
runs-on: ubuntu-latest
container:
image: quay.io/rockylinux/rockylinux:9
permissions:
contents: write
packages: write
id-token: write
steps:
# Install git first. Checkout without git downloads an archive that has no .git.
- name: Install required packages
run: |
dnf install -y sudo tar gzip bzip2 git
dnf install -y curl --allowerasing
- name: Clone repository
uses: actions/checkout@v7
# The checkout belongs to another user than the container root. Git refuses it without this.
- name: Trust the checkout in git
run: git config --global --add safe.directory '*'
- name: Install Node.js
run: |
curl -fsSL https://rpm.nodesource.com/setup_24.x | bash -
dnf install nodejs -y
- name: Install dependencies
run: npm install
- name: Set git global credentials
run: |
git config --global user.name 'underpostnet'
git config --global user.email 'development@underpost.net'
- name: Build repository
env:
GITHUB_TOKEN: ${{ secrets.GIT_AUTH_TOKEN }}
GITHUB_USERNAME: ${{ github.repository_owner }}
# Never interpolated into the script: the propagated payload is multi-line and a shell
# expansion would corrupt entries holding `$` and execute anything in `$(...)`.
PROPAGATED_MESSAGE: ${{ github.event.inputs.message }}
run: |
cd .. && node engine/bin clone underpostnet/pwa-microservices-template
LAST_COMMIT_MESSAGE=$(cd engine && node bin cmt --propagate-msg 2>/dev/null || echo "")
SHOULD_CD="${{ github.event.inputs.sync }}"
DEPLOY_TYPE="${{ github.event.inputs.deploy_type }}"
if [ -z "$LAST_COMMIT_MESSAGE" ]; then
LAST_COMMIT_MESSAGE="Update engine core repository"
fi
echo "[INFO] Captured commit message: $LAST_COMMIT_MESSAGE"
echo "[INFO] Should CD: $SHOULD_CD, Deploy type: $DEPLOY_TYPE"
node engine/bin clone --bare underpostnet/engine-core
cd engine
git clone --depth 1 --no-checkout https://$GITHUB_TOKEN@github.com/underpostnet/engine-private.git ./engine-private
cd ./engine-private && git sparse-checkout set conf/dd-core && git checkout && cd ..
node bin/build dd-core development --coverage
cd ../pwa-microservices-template
rm -rf ./.git
mv ../engine-core.git ./.git
mv ../engine/engine-private ./engine-private
npm install
node bin new --default-conf --deploy-id dd-core
mv ./underpost.config.dd-core.js ./underpost.config.js
rm -rf ./engine-private
git init
git config user.name 'underpostnet'
git config user.email 'development@underpost.net'
git add .
if git diff --cached --quiet; then
echo "[INFO] No changes to publish; skipping commit and push."
else
git commit -m "$LAST_COMMIT_MESSAGE"
node ../engine/bin push . underpostnet/engine-core
fi
if [ "$SHOULD_CD" = "true" ]; then
if [ -z "$DEPLOY_TYPE" ]; then
DEPLOY_TYPE="sync-and-deploy"
fi
echo "[INFO] Dispatching engine-core CD ${DEPLOY_TYPE}"
curl -s -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GIT_AUTH_TOKEN }}" \
"https://api.github.com/repos/underpostnet/engine/actions/workflows/engine-core.cd.yml/dispatches" \
-d "{\"ref\":\"master\",\"inputs\":{\"job\":\"${DEPLOY_TYPE}\"}}"
else
echo "[INFO] Deployment skipped"
fi