-
Notifications
You must be signed in to change notification settings - Fork 12
161 lines (123 loc) · 5.06 KB
/
update-module.yml
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
name: Update Module
run-name: ${{ github.event.inputs.module-name }} updated to ${{ github.event.inputs.git-ref }} by ${{ github.actor }}
# Controls when the workflow will run
on:
workflow_dispatch:
inputs:
module-name:
type: string
description: Name of the module (eg bmd-atem)
required: true
git-ref:
type: string
description: Git ref to build (tag/commit)
required: true
jobs:
build:
runs-on: ubuntu-latest
# The first stage is to build their module
# Remember that this is running user code, so we need to make sure not to leak any secrets
permissions:
packages: read
steps:
- name: Report info
run: |
echo "Updating **${{ github.event.inputs.module-name }}** to ${{ github.event.inputs.git-ref }} :rocket:" >> $GITHUB_STEP_SUMMARY
- name: Clone module
run: |
git clone https://github.com/bitfocus/companion-module-${{ github.event.inputs.module-name }} -b "${{ github.event.inputs.git-ref }}" "${{ github.event.inputs.module-name }}"
- name: Determine nodejs version
id: determine-nodejs
run: |
NODE_VERSION=$(jq '.runtime.type' ${{ github.event.inputs.module-name }}/companion/manifest.json)
echo "Node.js version: $NODE_VERSION"
if [ "$NODE_VERSION" == "\"node18\"" ]; then
echo "Using Node.js 18.x"
echo "version=18.x" >> $GITHUB_OUTPUT
elif [ "$NODE_VERSION" == "\"node22\"" ]; then
echo "Using Node.js 22.x"
echo "version=22.x" >> $GITHUB_OUTPUT
fi
- name: Use Node.js ${{ steps.determine-nodejs.outputs.version }}
uses: actions/setup-node@v4
with:
node-version: ${{ steps.determine-nodejs.outputs.version }}
- name: Enable corepack
run: |
corepack enable
- name: Collect info
run: |
cd ${{ github.event.inputs.module-name }}
MANIFEST_ID=$(jq '.["id"]' companion/manifest.json)
if [ ! "$MANIFEST_ID" == "\"${{ github.event.inputs.module-name }}\"" ]; then
echo "Module manifest.json id does not match github repository name"
exit 99
fi
if grep -q "companion-module-your-module-name" "companion/manifest.json"; then
echo "Module manifest contains references to companion-module-your-module-name!"
exit 99
fi
if ! jq -e '.products | arrays and length > 0' companion/manifest.json > /dev/null; then
echo "Module manifest product list is either empty or does not exist"
exit 99
fi
GIT_HASH=$(git rev-parse HEAD)
echo "git-hash=$GIT_HASH" >> $GITHUB_OUTPUT
- name: Setup Github packages auth
run: |
# TODO: support yarn3 with something like (needs a syntax check)
# yarn config set npmRegistries.//npm.pkg.github.com.npmAuthToken $NPM_AUTH_TOKEN
echo "//npm.pkg.github.com/:_authToken=${{ github.token }}" >> ~/.npmrc
- name: Prepare module
run: |
cd ${{ github.event.inputs.module-name }}
yarn install
# yarn build would be better, but lacks the --if-present property
npm run build --if-present
- name: Package module
run: |
cd ${{ github.event.inputs.module-name }}
yarn companion-module-build
- uses: actions/upload-artifact@v4
with:
name: pkg
path: ${{ github.event.inputs.module-name }}/pkg.tgz
retention-days: 1
commit:
runs-on: ubuntu-latest
needs: build
# The second stage is to commit the module to the repository
# only allow one workflow to run this step at a time
concurrency: add-module-${{ github.ref }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
path: modules
ref: ${{ github.ref_name }}
- uses: actions/download-artifact@v4
with:
name: pkg
- name: Package module
run: |
tar -xvzf pkg.tgz
UPDATE_DATE=$(date +%Y-%m-%d)
# cleanup some junk
rm -Rf pkg/.yarn || true
tee -a pkg/.build-info <<EOF
MODULE_NAME=${{ github.event.inputs.module-name }}
GIT_REF=${{ github.event.inputs.git-ref }}
RUN_URL=https://github.com/bitfocus/companion-bundled-modules/actions/runs/${{ github.run_id }}
UPDATE_DATE=$UPDATE_DATE
EOF
# TODO - verify module looks valid?
# make sure there isn't a legacy version
rm -Rf modules/_legacy/companion-module-${{ github.event.inputs.module-name }} || true
rm -Rf modules/${{ github.event.inputs.module-name }} || true
mv pkg modules/${{ github.event.inputs.module-name }}
- name: Commit updated module
uses: stefanzweifel/git-auto-commit-action@v5
with:
repository: modules
commit_message: "update ${{ github.event.inputs.module-name }} to ${{ github.event.inputs.git-ref }}"