-
Notifications
You must be signed in to change notification settings - Fork 3
242 lines (202 loc) · 8.25 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
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
# SPDX-FileCopyrightText: © Sebastian Thomschke and contributors
# SPDX-FileContributor: Sebastian Thomschke
# SPDX-License-Identifier: MIT
# SPDX-ArtifactOfProjectHomePage: https://github.com/sebthom/more-clink-completions
#
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
name: Build
on:
schedule:
- cron: '0 15 1 * *'
push:
branches-ignore: # build all branches except:
- 'dependabot/**' # prevent GHA triggered twice (once for commit to the branch and once for opening/syncing the PR)
tags-ignore: # don't build tags
- '**'
paths-ignore:
- '**/*.adoc'
- '**/*.md'
- '.editorconfig'
- '.git*'
- '.github/*.yml'
- '.github/workflows/stale.yml'
- 'tools'
pull_request:
paths-ignore:
- '**/*.adoc'
- '**/*.md'
- '.editorconfig'
- '.git*'
- '.github/*.yml'
- 'tools'
workflow_dispatch:
# https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
inputs:
debug-with-ssh:
description: "Start an SSH session for debugging purposes at the end of the build:"
default: never
type: choice
options: [ always, on_failure, on_failure_or_cancelled, never ]
debug-with-ssh-only-for-actor:
description: "Limit access to the SSH session to the GitHub user that triggered the job."
default: true
type: boolean
debug-with-ssh-only-jobs-matching:
description: "Only start an SSH session for jobs matching this regex pattern:"
default: ".*"
type: string
defaults:
run:
shell: bash
jobs:
###########################################################
build:
###########################################################
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
#- os: ubuntu-latest
# haxe: nightly
# may_create_release: false
- os: ubuntu-latest
haxe: latest
may_create_release: true
steps:
- name: "Show: GitHub context"
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo $GITHUB_CONTEXT
- name: "Show: environment variables"
run: env | sort
- name: Git Checkout
uses: actions/checkout@v4 # https://github.com/actions/checkout
- name: "Install: Haxe and Haxelibs"
uses: vegardit/haxe-reusable-workflows/.github/actions/setup-haxe@dev
with:
haxe-reusable-workflows-version: dev
haxe-version: ${{ matrix.haxe }}
haxe-libs: |
clink-externs@git:https://github.com/vegardit/haxe-clink-externs
no-spoon@git:https://github.com/back2dos/no-spoon
- name: "Run: Haxe compile"
run: |
set -eux
haxe build.hxml
- name: "Install: Lua"
id: setup-haxe-targets
uses: vegardit/haxe-reusable-workflows/.github/actions/setup-haxe-targets@dev
with:
haxe-reusable-workflows-version: dev
setup-lua: 5.2
- name: "Run: Lua minify"
run: |
set -eux
lua tools/luapack-*/luapack.lua target/more-clink-completions.lua
# Add version info
git_log=$(git log ${{ github.sha }} --pretty=format:"%H%d %aI %s")
prefix="-- $git_log
-- SPDX-FileCopyrightText: © Sebastian Thomschke and contributors
-- SPDX-License-Identifier: MIT
-- SPDX-ArtifactOfProjectHomePage: https://github.com/sebthom/more-clink-completions"
(echo "$prefix"; cat target/more-clink-completions.lua) > target/more-clink-completions.debug.lua
(echo "$prefix"; cat target/more-clink-completions.packed.lua) > target/more-clink-completions.lua
- name: "Determine release name"
id: release
if: matrix.may_create_release && !env.ACT
run: |
case "$GITHUB_REF_NAME" in
v2)
echo "name=$GITHUB_REF_NAME" >>"$GITHUB_OUTPUT"
echo "branch=${GITHUB_REF_NAME}-releases" >>"$GITHUB_OUTPUT"
;;
esac
- name: Deploy release branch
if: ${{ steps.release.outputs.name != '' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -eux
last_commit_message=$(git log --pretty=format:"%s (%h)" -1)
release_branch="${{ steps.release.outputs.branch }}"
github_repo_url="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}"
cd /tmp
if curl --output /dev/null -sf --head "$github_repo_url/tree/$release_branch"; then
git clone $github_repo_url --single-branch --branch "$release_branch" releasebranch
cd releasebranch
# https://github.community/t/github-actions-bot-email-address/17204
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git reset --hard HEAD^
else
git clone $github_repo_url releasebranch
cd releasebranch
git checkout --orphan "$release_branch"
git rm -rf .
cat <<EOF > README.md
# more-clink-completions ${GITHUB_REF_NAME} release repo
Please consult https://github.com/sebthom/more-clink-completions for more information.
EOF
git add README.md
cp "$GITHUB_WORKSPACE/LICENSE.txt" .
git add LICENSE.txt
# https://github.community/t/github-actions-bot-email-address/17204
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -m "Initialize branch"
fi
cp "$GITHUB_WORKSPACE/target/more-clink-completions.lua" .
# check if file is new or modified
if ! git ls-files --error-unmatch more-clink-completions.lua &>/dev/null || ! git diff --quiet --exit-code more-clink-completions.lua; then
git add more-clink-completions.lua
git commit -m "$last_commit_message"
git push origin "$release_branch" --force
fi
- name: "Delete previous 'latest-${{ steps.release.outputs.name }}' release"
if: ${{ steps.release.outputs.name != '' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_NAME: ${{ steps.release.outputs.name }}
# https://cli.github.com/manual/gh_release_delete
run: GH_DEBUG=1 gh release delete "$RELEASE_NAME" --yes --cleanup-tag || true
- name: "Create 'latest-${{ env.RELEASE_BRANCH }}' release"
if: ${{ steps.release.outputs.name != '' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_NAME: ${{ steps.release.outputs.name }}
COMMIT_MSG: ${{ github.event.head_commit.message }} # https://stackoverflow.com/a/78420438/5116073
# https://cli.github.com/manual/gh_release_create
run: |
GH_DEBUG=1 gh release create "$RELEASE_NAME" \
--title "$RELEASE_NAME" \
--latest \
--notes "$COMMIT_MSG" \
--target "${{ github.sha }}" \
target/more-clink-completions.lua \
target/more-clink-completions.debug.lua
##################################################
# Setup SSH debug session
##################################################
- name: "SSH session for debugging: check"
id: DEBUG_SSH_SESSSION_CHECK
if: always()
run: |
set -eu
job_filter_pattern="${{ inputs.debug-with-ssh-only-jobs-matching }}"
echo "job_filter: $job_filter_pattern"
job_info=$(echo "$GITHUB_JOB ${{ runner.os }} haxe-${{ matrix.haxe-version }}" | tr -d '\n')
echo "job_info: $job_info"
when="${{ inputs.debug-with-ssh }}"
if [[ $when == "always" ]] || [[ "$job_info" =~ .*$job_filter_pattern.* ]] && case "${{ job.status }}" in
success) [[ $when == "always" ]] ;;
cancelled) [[ $when == "on_failure_or_cancelled" ]] ;;
failure) [[ $when == "on_failure"* ]] ;;
esac; then
echo "start_ssh_session=true" | tee -a "$GITHUB_OUTPUT"
fi
- name: "SSH session for debugging: start"
uses: mxschmitt/action-tmate@v3 # https://github.com/mxschmitt/action-tmate
if: always() && steps.DEBUG_SSH_SESSSION_CHECK.outputs.start_ssh_session
with:
limit-access-to-actor: ${{ inputs.debug-with-ssh-only-for-actor }}