Skip to content

Commit 3f23611

Browse files
committed
feat: website*microzig publish with artifact restructuring
Ability to publish both microzig and the website based on a tag/push. The microzig boxzer artifact output is also restructured to be flatter.
1 parent 15dac2b commit 3f23611

9 files changed

+222
-56
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Reusasble Alter Microzig Artifact
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
in-gh-artifact-name:
7+
required: true
8+
type: string
9+
description: The github artifact to download the artifact from.
10+
out-gh-artifact-name:
11+
required: true
12+
type: string
13+
description: The github artifact to upload to
14+
source-path:
15+
required: false
16+
type: string
17+
default: ""
18+
description: |
19+
The path within the github artifact where the artifact is located at
20+
zig-version:
21+
required: true
22+
type: string
23+
description: The zig version to use.
24+
microzig-version:
25+
required: true
26+
type: string
27+
description: The microzig version to use
28+
29+
jobs:
30+
publish:
31+
runs-on: ubuntu-latest
32+
steps:
33+
# Download the requested github artifact
34+
- name: Download artifacts
35+
id: download
36+
uses: actions/download-artifact@v4
37+
with:
38+
name: ${{ inputs.in-gh-artifact-name }}
39+
# Get the path to where the artifact is at. This is the path to the
40+
# downloaded artifact that is relative to the github workspace with the
41+
# source-path parameter tacked on the end.
42+
- name: Get Source Path
43+
shell: bash
44+
id: get-source-path
45+
run: |
46+
echo "path=$( \
47+
realpath -s --relative-to="${{ github.workspace }}" \
48+
"${{ steps.download.outputs.download-path }}/${{ inputs.source-path }}" \
49+
)" >> $GITHUB_OUTPUT
50+
- name: Create base folder structure
51+
shell: bash
52+
id: base-folders
53+
run: |
54+
mkdir ./output
55+
mkdir "./output/zig-${{ inputs.zig-version }}/"
56+
mkdir "./output/zig-${{ inputs.zig-version }}/microzig-${{ inputs.microzig-version }}/"
57+
echo "path=./output/zig-${{ inputs.zig-version }}/microzig-${{ inputs.microzig-version }}/" >> $GITHUB_OUTPUT
58+
mkdir "./output/zig-${{ inputs.zig-version }}/microzig-${{ inputs.microzig-version }}/bsp/"
59+
mkdir "./output/zig-${{ inputs.zig-version }}/microzig-${{ inputs.microzig-version }}/build/"
60+
mkdir "./output/zig-${{ inputs.zig-version }}/microzig-${{ inputs.microzig-version }}/examples/"
61+
mkdir "./output/zig-${{ inputs.zig-version }}/microzig-${{ inputs.microzig-version }}/tools/"
62+
- name: Get glob safe base paths
63+
id: get-glob-paths
64+
shell: bash
65+
run: |
66+
echo "source-path=$(printf "%q" "${{ steps.get-source-path.outputs.path }}")" >> $GITHUB_OUTPUT
67+
echo "output-path=$(printf "%q" "${{ steps.base-folders.outputs.path }}")" >> $GITHUB_OUTPUT
68+
- name: Copy Root, Build, Core, Tools
69+
shell: bash
70+
run: |
71+
mv ${{ steps.get-glob-paths.outputs.source-path }}/microzig-*.tar.gz "${{ steps.base-folders.outputs.path }}/microzig.tar.gz"
72+
mv ${{ steps.get-glob-paths.outputs.source-path }}/microzig-*/build-*.tar.gz "${{ steps.base-folders.outputs.path }}/microzig-build.tar.gz"
73+
mv ${{ steps.get-glob-paths.outputs.source-path }}/microzig-*/core-*.tar.gz "${{ steps.base-folders.outputs.path }}/microzig-core.tar.gz"
74+
mv ${{ steps.get-glob-paths.outputs.source-path }}/microzig-*/build/definitions-*.tar.gz "${{ steps.base-folders.outputs.path }}/build/definitions.tar.gz"
75+
- name: Move examples, bsp
76+
shell: bash
77+
run: |
78+
mv ${{ steps.get-glob-paths.outputs.source-path }}/microzig-*/bsp/*/*.tar.gz "${{ steps.base-folders.outputs.path }}/bsp/"
79+
mv ${{ steps.get-glob-paths.outputs.source-path }}/microzig-*/examples/*/*.tar.gz "${{ steps.base-folders.outputs.path }}/examples/"
80+
- name: Rename examples, bsp
81+
shell: bash
82+
run: |
83+
find "${{ steps.base-folders.outputs.path }}/examples" -type f -exec sh -c 'mv "{}" "$(dirname -- "{}")/$(basename -- "{}" | sed "s/-.*\.tar\.gz/-examples.tar.gz/g")"' \;
84+
find "${{ steps.base-folders.outputs.path }}/bsp" -type f -exec sh -c 'mv "{}" "$(dirname -- "{}")/$(basename -- "{}" | sed "s/-.*\.tar\.gz/-bsp.tar.gz/g")"' \;
85+
- name: Upload Artifacts
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: ${{ inputs.out-gh-artifact-name }}
89+
path: "./output/"

.github/workflows/build-base.yml

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ on:
2727
description: |
2828
If building a sub-project only, you can specify a working directory
2929
which is the path to that sub-project.
30+
target-os:
31+
required: false
32+
type: string
33+
default: ""
34+
description: |
35+
If you need to filter which platform uploads the artifact.
3036
is-packaged:
3137
required: false
3238
type: boolean
@@ -43,7 +49,7 @@ on:
4349
description: |
4450
The name to use for the github actifact that will be uploaded.
4551
# The path that we should upload artifacts from
46-
artifact-output-paths:
52+
artifact-output-path:
4753
required: false
4854
type: string
4955
default: ""
@@ -55,6 +61,11 @@ on:
5561
type: string
5662
default: ""
5763
description: A sepcific ref to build for (i.e. a version or commit)
64+
zig-args:
65+
required: false
66+
type: string
67+
default: ""
68+
description: Arguments to add to the zig build command
5869
secrets:
5970
# The downloads url for the packaging step. This is used in boxzer to
6071
# fill in the manifest downloads location
@@ -63,13 +74,43 @@ on:
6374
description: |
6475
The download url that will be included in the boxzer manifest output.
6576
If the "is-packaged" option is false, this will not be used.
77+
outputs:
78+
issemver:
79+
description: Whether or not it was built with a semver
80+
value: ${{ jobs.build-zig.outputs.issemver }}
81+
major:
82+
description: The major version of the semver
83+
value: ${{ jobs.build-zig.outputs.major }}
84+
minor:
85+
description: The minor version of the semver
86+
value: ${{ jobs.build-zig.outputs.minor }}
87+
patch:
88+
description: The patch version of the semver
89+
value: ${{ jobs.build-zig.outputs.patch }}
90+
prerelease:
91+
description: The prerelease info of the semver
92+
value: ${{ jobs.build-zig.outputs.prerelease }}
93+
build:
94+
description: The build info of the semver
95+
value: ${{ jobs.build-zig.outputs.build }}
96+
version:
97+
description: The full semver string
98+
value: ${{ jobs.build-zig.outputs.version }}
6699

67100
jobs:
68101
build-zig:
69102
runs-on: ${{ matrix.os }}
70103
strategy:
71104
matrix:
72105
os: [ubuntu-latest, windows-latest, macos-latest]
106+
outputs:
107+
issemver: ${{ steps.semver.outputs.issemver }}
108+
major: ${{ steps.semver.outputs.major }}
109+
minor: ${{ steps.semver.outputs.minor }}
110+
patch: ${{ steps.semver.outputs.patch }}
111+
prerelease: ${{ steps.semver.outputs.prerelease }}
112+
build: ${{ steps.semver.outputs.build }}
113+
version: ${{ steps.semver.outputs.version }}
73114
steps:
74115
# If we just want to use the current commit, simply run a checkout
75116
- name: Checkout
@@ -86,10 +127,13 @@ jobs:
86127
ref: ${{ inputs.ref }}
87128
sparse-checkout: ${{ inputs.sparse-checkout-patterns }}
88129
submodules: ${{ inputs.get-submodules }}
130+
# Parse the reference and pull out the semversion information if it is semversion
89131
- name: Get Semver Details
90132
shell: bash
91133
id: semver
92134
run: |
135+
# This regex is from the semver page. Yes, I too cry at how big it is, just be glad you didn't have to get it working in bash.
136+
# https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
93137
if [[ "${{ inputs.ref }}" =~ ^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))? ]]; then
94138
echo "issemver=true" >> "$GITHUB_OUTPUT"
95139
echo "major=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT"
@@ -101,7 +145,8 @@ jobs:
101145
else
102146
echo "issemver=false" >> "$GITHUB_OUTPUT"
103147
fi
104-
# Setup zig, we use mlugg's setup because it has caching
148+
# If the reference is semver, modify all zon files to include the version from the reference
149+
# Mac needs to be done different than windows/linux (see the sed command)
105150
- name: Process Version Info
106151
if: steps.semver.outputs.issemver == 'true' && runner.os != 'macOS'
107152
shell: bash
@@ -112,26 +157,28 @@ jobs:
112157
shell: bash
113158
run: |
114159
find . -name "*.zig.zon" -exec sed -i '' 's/\(.version *= *"\)[^\s]*\(",\)/\1${{ steps.semver.outputs.version }}\2/' {} \;
160+
# Setup zig, we use mlugg's setup because it has caching
115161
- name: Setup Zig
116162
uses: mlugg/setup-zig@v1
117163
with:
118164
version: ${{ inputs.zig-version }}
119165
- name: Build
120-
run: zig build -Doptimize=ReleaseSmall
121-
working-directory: ${{ inputs.working-directory }}
166+
run: |
167+
zig build ${{ inputs.zig-args }}
168+
working-directory: ./${{ inputs.working-directory }}
122169
- name: Package
123170
if: ${{ inputs.is-packaged && runner.os == 'macOS' }}
124171
run: zig build package -- "${{ secrets.downloads-url }}"
172+
working-directory: ./${{ inputs.working-directory }}
125173
# We use whether or not an artifact output path is provided and whether
126174
# or not there is actually anything in that directory to know whether or
127175
# not there is anything to upload.
128176
- name: Get Should Upload bash
129177
id: should-upload
130178
shell: bash
131179
run: |
132-
if [[ ! -z "${{ inputs.artifact-output-paths }}" ]] \
133-
&& test -n "$(find . -maxdepth 1 \
134-
-name '${{ inputs.artifact-output-paths }}' \
180+
if [[ ! -z "${{ inputs.artifact-output-path }}" ]] \
181+
&& test -n "$(find ${{ inputs.artifact-output-path }} -maxdepth 1 \
135182
-print -quit)"; then
136183
echo "SHOULD_UPLOAD=true" >> $GITHUB_OUTPUT;
137184
else
@@ -142,8 +189,9 @@ jobs:
142189
- name: Upload Artifacts
143190
if: |
144191
steps.should-upload.outputs.SHOULD_UPLOAD == 'true'
145-
&& inputs.github-artifact-name != ''
192+
&& inputs.github-artifact-name != ''
193+
&& ( runner.os == inputs.target-os || inputs.target-os == '' )
146194
uses: actions/upload-artifact@v4
147195
with:
148196
name: ${{ inputs.github-artifact-name }}
149-
path: ${{ inputs.artifact-output-paths }}
197+
path: ${{ inputs.artifact-output-path }}

.github/workflows/build-microzig.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
zig-version: 0.13.0
3333
get-submodules: true
3434
is-packaged: true
35+
zig-args: -Doptimize=ReleaseSmall
3536
secrets:
3637
downloads-url: ${{ secrets.DOWNLOADS_URL }}
3738
# If this is a push to main we want to create an automatic test against the

.github/workflows/publish-base.yml

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ on:
1515
required: true
1616
type: string
1717
description: The github artifact to download the artifact from.
18-
artifact-name:
19-
required: true
20-
type: string
21-
description: The name of what we are publishing
2218
# The path after the target-path to publish the artifact to
2319
# {artifact | {target-path}/{target-artifact-path}
2420
target-artifact-path:
@@ -57,7 +53,7 @@ on:
5753

5854
jobs:
5955
publish:
60-
runs-on: macos-latest
56+
runs-on: ubuntu-latest
6157
steps:
6258
# If this is somehow not run from a tag, fail. This is a remainder from
6359
# when the build side and publish side were done in one workflow.
@@ -97,31 +93,6 @@ jobs:
9793
REMOTE_USER: ${{ secrets.user }}
9894
REMOTE_PORT: ${{ secrets.port }}
9995
TARGET: ${{ secrets.target-path }}/${{ inputs.target-artifact-path }}
100-
# (Not working as intented) Un-needed for now. This step would go through
101-
# every binary and folder within the source path and add it to the release
102-
# if it were a file, or compress it and then add the compressed file to
103-
# the release.
104-
# Issue: Adds things that are not desired in the output.
105-
#- name: Handle Folder Release Artifact
106-
# if: ${{ startsWith(github.ref, 'refs/tags/') && endsWith(github.ref, inputs.tag) }}
107-
# shell: bash
108-
# run: |
109-
# mkdir -p "artifacts-${{ github.sha }}"
110-
# for i in "${{ steps.download.outputs.download-path }}/${{ inputs.source-path }}"/*; do
111-
# echo "Artifact path $i"
112-
# if [[ -d "$i" ]]; then
113-
# echo "Artifact is path"
114-
# dirname="$(basename "$i")"
115-
# echo "Artifact directory $dirname. Compressing folder to ${{ inputs.artifact-name }}-${dirname}.tar.gz"
116-
# tar -czvf "${{ inputs.artifact-name }}-${dirname}.tar.gz" -C "$i" .
117-
# echo "Moving tar to artifacts-${{ github.sha }}"
118-
# mv "${{ inputs.artifact-name }}-${dirname}.tar.gz" "artifacts-${{ github.sha }}"
119-
# else
120-
# echo "Artifact is file"
121-
# echo "Move to: artifacts-${{ github.sha }}"
122-
# mv "$i" "artifacts-${{ github.sha }}"
123-
# fi
124-
# done
12596
# Create the release draft on GitHub.
12697
- name: Create Release Draft
12798
if: ${{ startsWith(github.ref, 'refs/tags/') && endsWith(github.ref, inputs.tag) }}

.github/workflows/publish-microzig.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,38 @@ jobs:
1313
# Build the project to ensure it works. Also to get the binaries.
1414
build-microzig:
1515
uses: ./.github/workflows/build-base.yml
16+
concurrency:
17+
group: build
18+
cancel-in-progress: true
1619
with:
1720
zig-version: 0.13.0
1821
get-submodules: true
1922
is-packaged: true
23+
target-os: macOS
2024
github-artifact-name: microzig-build
21-
artifact-output-paths: boxzer-out
25+
artifact-output-path: boxzer-out
2226
ref: ${{ github.ref_name }}
2327
secrets:
2428
downloads-url: ${{ secrets.BOXZER_DOWNLOADS_URL }}
29+
# Alters the boxzer output to match what we desire
30+
alter-microzig-artifact:
31+
uses: ./.github/workflows/alter-microzig-artifact.yml
32+
needs: build-microzig
33+
with:
34+
in-gh-artifact-name: microzig-build
35+
out-gh-artifact-name: microzig-alt
36+
zig-version: 0.13.0
37+
microzig-version: ${{ needs.build-microzig.outputs.version }}
2538
# Publish microzig
2639
publish-microzig:
2740
uses: ./.github/workflows/publish-base.yml
28-
needs: build-microzig
41+
needs: alter-microzig-artifact
2942
concurrency:
3043
group: publish
3144
cancel-in-progress: false
3245
with:
3346
tag: ${{ github.ref_name }}
34-
artifact-name: microzig
35-
github-artifact-name: microzig-build
47+
github-artifact-name: microzig-alt
3648
source-path: /
3749
secrets:
3850
target-path: ${{ secrets.DEPLOY_MZ_ROOT_DATA_PATH }}

.github/workflows/publish-website-staging.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,23 @@ on:
1313

1414
jobs:
1515
# Build the project to ensure it works. Also to get the binaries.
16-
build-microzig:
16+
build-website:
1717
uses: ./.github/workflows/build-base.yml
1818
with:
1919
zig-version: 0.13.0
2020
get-submodules: true
21+
target-os: Linux
2122
github-artifact-name: website-build
22-
artifact-output-paths: zig-out
23+
artifact-output-path: website/zig-out
24+
working-directory: website
2325
# Publish microzig
24-
publish-microzig:
26+
publish-website:
2527
uses: ./.github/workflows/publish-base.yml
26-
needs: build-microzig
28+
needs: build-website
2729
concurrency:
2830
group: publish
2931
cancel-in-progress: false
3032
with:
31-
artifact-name: website
3233
github-artifact-name: website-build
3334
source-path: /
3435
secrets:
@@ -39,6 +40,7 @@ jobs:
3940
user: ${{ secrets.DEPLOY_WS_USER }}
4041
pr-comment:
4142
runs-on: ubuntu-latest
43+
needs: publish-website
4244
permissions:
4345
pull-requests: write
4446
steps:

0 commit comments

Comments
 (0)