-
Notifications
You must be signed in to change notification settings - Fork 119
201 lines (199 loc) · 7.32 KB
/
build-microzig.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
name: Build Microzig
on:
push:
branches: [main]
paths:
- .github/**
- build.zig*
- tools/**
- core/**
- bsp/**
- examples/**
pull_request:
branches: [main]
paths:
- build.zig*
- tools/**
- core/**
- bsp/**
- examples/**
jobs:
build-microzig:
<<<<<<< HEAD
if: |
${{
( github.event_name == 'pull_request' && github.base_ref == 'main' )
|| github.ref_name == 'main'
}}
name: Build
uses: ./.github/workflows/build-base.yml
with:
zig-version: ${{ vars.MZ_TARGET_ZIG_VERSION }}
get-submodules: true
is-packaged: true
zig-args: -Doptimize=ReleaseSmall
secrets:
downloads-url: ${{ secrets.DOWNLOADS_URL }}
# If this is a push to main we want to create an automatic test against the
# zig-master branch. To do this, we need to create a PR and while we could
# just go directly from main to zig-master, this would mean that if the tests
# with zig-master fail, the main branch will also display the failure (this
# is because github action results are saved based on the commit). To solve
# that issue, we create a new branch with a new commit in it, then create
# the PR based on that.
#
# Creates the branch that we will use for the PR to zig-master
=======
if: ${{ ( github.event_name == 'pull_request' && github.base_ref == 'main' ) || github.ref_name == 'main' }}
name: Build
uses: ./.github/workflows/zig-build-base.yml
with:
zig-version: 0.13.0
get-submodules: true
is-packaged: true
artifact-output-paths: boxzer-out
secrets:
downloads-url: ${{ secrets.DOWNLOADS_URL }}
>>>>>>> ea386ec (ci: implement build pipeline and patch to zig master)
create-branch:
if: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
name: Create Patch Branch
needs:
- build-microzig
runs-on: ubuntu-latest
outputs:
branch: master-patch/${{ github.sha }}
permissions:
contents: write
pull-requests: write
steps:
<<<<<<< HEAD
# First we checkout the repository
- uses: actions/checkout@v4
# Check if the branch exsits. This will be used in future steps to
# conditionally execute them.
=======
- uses: actions/checkout@v4
>>>>>>> ea386ec (ci: implement build pipeline and patch to zig master)
- id: cbe
name: Check branch exists
# The list remote returns nothing if the branch does not exist.
# So, if there is nothing in the command output, it does not exist
run: |
<<<<<<< HEAD
if [[ -z "$(git ls-remote \
--heads origin master-patch/${{ github.sha }})" ]]; then
=======
if [[ -z "$(git ls-remote --heads origin master-patch/${{ github.sha }})" ]]; then
>>>>>>> ea386ec (ci: implement build pipeline and patch to zig master)
echo "exists=false" >> "$GITHUB_OUTPUT"
else
echo "exists=true" >> "$GITHUB_OUTPUT"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
<<<<<<< HEAD
# If the branch doesn't already exist, we create a new one. We use the
# username and email of the last commit.
=======
>>>>>>> ea386ec (ci: implement build pipeline and patch to zig master)
- name: Create Branch
if: steps.cbe.outputs.exists == 'false'
run: |
git config user.name "$(git log -1 --pretty=format:'%an')"
git config user.email "$(git log -1 --pretty=format:'%ae')"
git checkout -b "master-patch/${{ github.sha }}"
git push -u origin "master-patch/${{ github.sha }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
<<<<<<< HEAD
# Checkout to the new branch
=======
>>>>>>> ea386ec (ci: implement build pipeline and patch to zig master)
- name: checkout
uses: actions/checkout@v4
with:
ref: master-patch/${{ github.sha }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
<<<<<<< HEAD
# Create an empty commit that will be used to save the ci results
# against (For more details see "create-branch" comment)
=======
>>>>>>> ea386ec (ci: implement build pipeline and patch to zig master)
- name: add-commit
run: |
git config user.name "$(git log -1 --pretty=format:'%an')"
git config user.email "$(git log -1 --pretty=format:'%ae')"
<<<<<<< HEAD
git commit \
--author "ZEG Github Action <>" \
-m "chore: commit for zig master build ci" \
--allow-empty
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Now that a branch exists, we can create our PR. To do this we will use the
# github command line tool.
create-pr:
if: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
name: Create Pull Request
runs-on: ubuntu-latest
needs: create-branch
permissions:
pull-requests: read
contents: read
steps:
- uses: actions/checkout@v4
# Check if the PR already exists, this will be used to conditionally
# create the PR.
=======
git commit --author "ZEG Github Action <>" -m "feat: added commit file" --allow-empty
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
>>>>>>> ea386ec (ci: implement build pipeline and patch to zig master)
- id: cpe
name: check pr exists
# github actions pr only outputs when the query find something.
# So, if the output is empty, pr does not exist
run: |
<<<<<<< HEAD
gh pr list -B zig-master \
-H "${{ needs.create-branch.outputs.branch }}" 2> check-exists-out
if [[ -z "$(cat check-exists-out)" ]]; then
=======
gh pr list -B zig-master -H "master-patch/${{ github.sha }}" 2> check-pr-exists-output
if [[ -z "$(cat check-pr-exists-output)" ]]; then
>>>>>>> ea386ec (ci: implement build pipeline and patch to zig master)
echo "exists=false" >> "$GITHUB_OUTPUT"
else
echo "exists=true" >> "$GITHUB_OUTPUT"
fi
<<<<<<< HEAD
cat check-exists-out
rm check-exists-out
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Create the actual PR if it doesn't already exist
- name: create pull request,
if: steps.cpe.outputs.exists == 'false'
run: |
gh pr create -B zig-master -H master-patch/${{ github.sha }} \
--title 'Testing commit ${{ github.sha }} with zig master' \
--body 'Created by Github action'
env:
# We use a custom TOKEN to enable triggering other workflows.
# See: https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/triggering-a-workflow#triggering-a-workflow-from-a-workflow
GITHUB_TOKEN: ${{ secrets.PR_CREATE_TOKEN }}
=======
rm check-pr-exists-output
env:
GITHUB_TOKEN: ${{ secrets.PR_CREATE_PAT }}
- name: create pull request,
if: steps.cpe.outputs.exists == 'false'
run: |
gh pr create -B zig-master -H master-patch/${{ github.sha }} --title 'Testing commit ${{ github.sha }} with zig master' --body 'Created by Github action'
env:
GITHUB_TOKEN: ${{ secrets.PR_CREATE_PAT }}
>>>>>>> ea386ec (ci: implement build pipeline and patch to zig master)