-
Notifications
You must be signed in to change notification settings - Fork 14
108 lines (83 loc) · 3.15 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
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
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: Use Node.js 18.x
uses: actions/setup-node@v3
with:
# TODO - should this be configurable?
node-version: 18.x
- name: Collect info
run: |
cd ${{ github.event.inputs.module-name }}
GIT_HASH=$(git rev-parse HEAD)
echo "git-hash=$GIT_HASH" >> $GITHUB_OUTPUT
- name: Prepare module
run: |
cd ${{ github.event.inputs.module-name }}
yarn
# 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@v3
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 }}
steps:
- uses: actions/checkout@v3
with:
path: modules
ref: ${{ github.ref_name }}
- uses: actions/download-artifact@v3
with:
name: pkg
- name: Package module
run: |
tar -xvzf pkg.tgz
UPDATE_DATE=$(date +%Y-%m-%d)
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?
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@v4
with:
repository: modules
commit_message: "update ${{ github.event.inputs.module-name }} to ${{ github.event.inputs.git-ref }}"