-
Notifications
You must be signed in to change notification settings - Fork 619
122 lines (115 loc) · 4 KB
/
build-native.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
name: Build Native
on:
workflow_dispatch:
pull_request:
types: [ opened ]
issue_comment:
types: [ created ]
jobs:
check:
name: Check conditions
runs-on: ubuntu-latest
outputs:
ref: ${{ steps.output.outputs.ref }}
repo: ${{ steps.output.outputs.repo }}
steps:
- name: Check if PR comment trigger is present
if: github.event_name != 'workflow_dispatch'
uses: khan/[email protected]
id: check
with:
trigger: '/native'
reaction: rocket
prefix_only: true
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
- name: Get PR branch
uses: gotson/pull-request-comment-branch@head-repo-owner-dist
if: steps.check.outputs.triggered == 'true'
id: comment-branch
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
# This will set the branch to use:
# - if workflow_dispatch, use the branch that was chosen when running the workflow
# - if it is a comment on a PR, and the trigger matches, use the PR branch
- name: Set job output
id: output
run: |
echo "::echo::on"
if [[ "${{ github.event_name == 'workflow_dispatch' }}" == 'true' ]]
then
echo "ref=${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "repo=${{ github.repository }}" >> $GITHUB_OUTPUT
elif [[ "${{ steps.check.outputs.triggered }}" == 'true' ]]
then
echo "ref=${{ steps.comment-branch.outputs.head_ref }}" >> $GITHUB_OUTPUT
echo "repo=${{ steps.comment-branch.outputs.head_owner }}/${{ steps.comment-branch.outputs.head_repo }}" >> $GITHUB_OUTPUT
else
echo ""
fi
matrix:
name: Build matrix
runs-on: ubuntu-latest
needs: [check]
if: needs.check.outputs.ref && needs.check.outputs.repo
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
with:
repository: ${{ needs.check.outputs.repo }}
ref: ${{ needs.check.outputs.ref }}
- name: Build matrix from Makefile
id: set-matrix
# parse the Makefile to retrieve the list of targets in 'native-all', without 'native'
run: |
matrix=$((
echo '{ "target" : ['
sed -n "/^native-all *: */ { s///; p }" Makefile | sed "s/^native\s//g" | sed 's/ /, /g' | xargs -n 1 echo | sed -r 's/^([^,]*)(,?)$/"\1"\2/'
echo " ]}"
) | jq -c .)
echo $matrix | jq .
echo "matrix=$matrix" >> $GITHUB_OUTPUT
build:
name: Build native libraries
runs-on: ubuntu-latest
needs: [check, matrix]
strategy:
matrix: ${{fromJson(needs.matrix.outputs.matrix)}}
steps:
- uses: actions/checkout@v3
with:
repository: ${{ needs.check.outputs.repo }}
ref: ${{ needs.check.outputs.ref }}
# Delete existing libs so we only upload the generated one into the artifact
- name: Delete existing native libs
run: rm -fr src/main/resources/org/sqlite/native
- name: Build native libraries
run: make ${{ matrix.target }}
env:
OCI_EXE: docker
- name: Upload native libraries
uses: actions/upload-artifact@v3
with:
name: native-libs
path: src/main/resources/org/sqlite/native/
push:
name: Push new native libraries to branch
runs-on: ubuntu-latest
needs: [check, build]
steps:
- uses: actions/checkout@v3
with:
repository: ${{ needs.check.outputs.repo }}
ref: ${{ needs.check.outputs.ref }}
- name: Download native libraries
uses: actions/download-artifact@v3
with:
name: native-libs
path: src/main/resources/org/sqlite/native/
- run: git status
- name: Commit and push
uses: EndBug/add-and-commit@v9
with:
message: 'chore: update native libraries'
default_author: github_actions