-
Notifications
You must be signed in to change notification settings - Fork 7
149 lines (130 loc) · 5.1 KB
/
build.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
name: Build
on:
push:
branches: [ master ]
workflow_dispatch:
inputs:
base_branch:
description: 'Name of branch to base build on'
type: string
required: false
default: 'master'
build_branch:
description: 'Name of branch to commit build to'
type: string
required: false
default: 'build'
jobs:
build:
runs-on: ubuntu-latest
steps:
# Checkout the base branch of this repository with full depth
- name: Checkout this repository
uses: actions/checkout@v3
with:
token: ${{ secrets['GITHUB_TOKEN'] }}
ref: ${{ inputs.base_branch || 'master' }}
fetch-depth: 0
# Set the local git user config to use the GitHub Actions bot account
- name: Set local git config user details
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# Recheckout both the base and build branches.
# This can "fail" if the build branch doesn't exist, but we should continue anyway.
- name: (Re)checkout both branches
id: checkout
continue-on-error: true
run: |
git checkout ${{ inputs.base_branch || 'master' }}
git checkout ${{ inputs.build_branch || 'build' }}
# Attempt to start to merge the base branch into build.
# This can "error" but we want to continue regardless.
# Will only run if the checkout step was successful.
- name: Merge base into build (1)
if: ${{ steps.checkout.outcome == 'success' }}
continue-on-error: true
run: |
git merge --no-commit ${{ inputs.base_branch || 'master' }}
# Do the 2nd part of the merge. This will ignore the branch's "shared" submodule stuff.
# This can "error" if the merge commit is empty but we want to continue regardless.
# Will only run if the checkout step was successful.
- name: Merge base into build (2)
if: ${{ steps.checkout.outcome == 'success' }}
continue-on-error: true
run: |
rm -rf shared~${{ inputs.base_branch || 'master' }}
git rm --ignore-unmatch --cached -r shared~${{ inputs.base_branch || 'master' }}
git reset HEAD shared
git commit -m "Merge branch '${{ inputs.base_branch || 'master' }}' into ${{ inputs.build_branch || 'build' }}"
# Returns the submodule back so we can get the latest files to build from that.
# Will only run if the checkout step was successful.
- name: Re-add esa-layouts-shared submodule
if: ${{ steps.checkout.outcome == 'success' }}
run: |
rm -rf shared
git rm --ignore-unmatch --cached -r shared
git checkout ${{ inputs.base_branch || 'master' }} shared
git commit -m "Re-add submodule" -a --allow-empty
# Converts the esa-layouts-shared submodule into a normal directory of files.
# This is done as we want to freeze the build at a point in time and this works well.
- name: Convert esa-layouts-shared submodule to regular directory
run: |
git submodule update --init
git rm --cached shared
git config -f .git/config --remove-section submodule.shared
rm -rf shared/.git
git add shared
# Setup some Node stuff
- name: Node.js setup
uses: actions/setup-node@v3
with:
node-version: '18'
# Install pnpm
- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: 8
# Gets pnpm's store directory (for next step)
- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
# Set pnpm cache options
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
# Install pnpm dependencies
- name: Install pnpm dependencies
run: pnpm i --frozen-lockfile
# Actually build everything
- name: Build
run: |
npm run clean
npm run build
# Start committing newly built files into a temporary commit.
- name: Commit built files (1)
run: |
git add -f dashboard graphics extension
git add -f ':(glob)./shared/extension/*/dist/**'
git commit -m "Built files" -a --allow-empty
# Squash the previous 2 commits down for convenience and create the final build commit.
# Will only run if the checkout step was successful.
# This can "fail" if there are no newly changed/built files, but we should continue anyway.
- name: Commit built files (2)
continue-on-error: true
if: ${{ steps.checkout.outcome == 'success' }}
run: |
git reset --soft HEAD~2
git commit -m "Built files" -a
# Pushes the built files to a specific branch
- name: Push built files to build branch
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets['GITHUB_TOKEN'] }}
branch: ${{ inputs.build_branch || 'build' }}