Skip to content

Commit

Permalink
feat: website*microzig publish with artifact restructuring
Browse files Browse the repository at this point in the history
Ability to publish both microzig and the website based on a tag/push.
The microzig boxzer artifact output is also restructured to be flatter.
  • Loading branch information
EliSauder committed Sep 23, 2024
1 parent 15dac2b commit 3f23611
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 56 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/alter-microzig-artifact.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Reusasble Alter Microzig Artifact

on:
workflow_call:
inputs:
in-gh-artifact-name:
required: true
type: string
description: The github artifact to download the artifact from.
out-gh-artifact-name:
required: true
type: string
description: The github artifact to upload to
source-path:
required: false
type: string
default: ""
description: |
The path within the github artifact where the artifact is located at
zig-version:
required: true
type: string
description: The zig version to use.
microzig-version:
required: true
type: string
description: The microzig version to use

jobs:
publish:
runs-on: ubuntu-latest
steps:
# Download the requested github artifact
- name: Download artifacts
id: download
uses: actions/download-artifact@v4
with:
name: ${{ inputs.in-gh-artifact-name }}
# Get the path to where the artifact is at. This is the path to the
# downloaded artifact that is relative to the github workspace with the
# source-path parameter tacked on the end.
- name: Get Source Path
shell: bash
id: get-source-path
run: |
echo "path=$( \
realpath -s --relative-to="${{ github.workspace }}" \
"${{ steps.download.outputs.download-path }}/${{ inputs.source-path }}" \
)" >> $GITHUB_OUTPUT
- name: Create base folder structure
shell: bash
id: base-folders
run: |
mkdir ./output
mkdir "./output/zig-${{ inputs.zig-version }}/"
mkdir "./output/zig-${{ inputs.zig-version }}/microzig-${{ inputs.microzig-version }}/"
echo "path=./output/zig-${{ inputs.zig-version }}/microzig-${{ inputs.microzig-version }}/" >> $GITHUB_OUTPUT
mkdir "./output/zig-${{ inputs.zig-version }}/microzig-${{ inputs.microzig-version }}/bsp/"
mkdir "./output/zig-${{ inputs.zig-version }}/microzig-${{ inputs.microzig-version }}/build/"
mkdir "./output/zig-${{ inputs.zig-version }}/microzig-${{ inputs.microzig-version }}/examples/"
mkdir "./output/zig-${{ inputs.zig-version }}/microzig-${{ inputs.microzig-version }}/tools/"
- name: Get glob safe base paths
id: get-glob-paths
shell: bash
run: |
echo "source-path=$(printf "%q" "${{ steps.get-source-path.outputs.path }}")" >> $GITHUB_OUTPUT
echo "output-path=$(printf "%q" "${{ steps.base-folders.outputs.path }}")" >> $GITHUB_OUTPUT
- name: Copy Root, Build, Core, Tools
shell: bash
run: |
mv ${{ steps.get-glob-paths.outputs.source-path }}/microzig-*.tar.gz "${{ steps.base-folders.outputs.path }}/microzig.tar.gz"
mv ${{ steps.get-glob-paths.outputs.source-path }}/microzig-*/build-*.tar.gz "${{ steps.base-folders.outputs.path }}/microzig-build.tar.gz"
mv ${{ steps.get-glob-paths.outputs.source-path }}/microzig-*/core-*.tar.gz "${{ steps.base-folders.outputs.path }}/microzig-core.tar.gz"
mv ${{ steps.get-glob-paths.outputs.source-path }}/microzig-*/build/definitions-*.tar.gz "${{ steps.base-folders.outputs.path }}/build/definitions.tar.gz"
- name: Move examples, bsp
shell: bash
run: |
mv ${{ steps.get-glob-paths.outputs.source-path }}/microzig-*/bsp/*/*.tar.gz "${{ steps.base-folders.outputs.path }}/bsp/"
mv ${{ steps.get-glob-paths.outputs.source-path }}/microzig-*/examples/*/*.tar.gz "${{ steps.base-folders.outputs.path }}/examples/"
- name: Rename examples, bsp
shell: bash
run: |
find "${{ steps.base-folders.outputs.path }}/examples" -type f -exec sh -c 'mv "{}" "$(dirname -- "{}")/$(basename -- "{}" | sed "s/-.*\.tar\.gz/-examples.tar.gz/g")"' \;
find "${{ steps.base-folders.outputs.path }}/bsp" -type f -exec sh -c 'mv "{}" "$(dirname -- "{}")/$(basename -- "{}" | sed "s/-.*\.tar\.gz/-bsp.tar.gz/g")"' \;
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.out-gh-artifact-name }}
path: "./output/"
66 changes: 57 additions & 9 deletions .github/workflows/build-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ on:
description: |
If building a sub-project only, you can specify a working directory
which is the path to that sub-project.
target-os:
required: false
type: string
default: ""
description: |
If you need to filter which platform uploads the artifact.
is-packaged:
required: false
type: boolean
Expand All @@ -43,7 +49,7 @@ on:
description: |
The name to use for the github actifact that will be uploaded.
# The path that we should upload artifacts from
artifact-output-paths:
artifact-output-path:
required: false
type: string
default: ""
Expand All @@ -55,6 +61,11 @@ on:
type: string
default: ""
description: A sepcific ref to build for (i.e. a version or commit)
zig-args:
required: false
type: string
default: ""
description: Arguments to add to the zig build command
secrets:
# The downloads url for the packaging step. This is used in boxzer to
# fill in the manifest downloads location
Expand All @@ -63,13 +74,43 @@ on:
description: |
The download url that will be included in the boxzer manifest output.
If the "is-packaged" option is false, this will not be used.
outputs:
issemver:
description: Whether or not it was built with a semver
value: ${{ jobs.build-zig.outputs.issemver }}
major:
description: The major version of the semver
value: ${{ jobs.build-zig.outputs.major }}
minor:
description: The minor version of the semver
value: ${{ jobs.build-zig.outputs.minor }}
patch:
description: The patch version of the semver
value: ${{ jobs.build-zig.outputs.patch }}
prerelease:
description: The prerelease info of the semver
value: ${{ jobs.build-zig.outputs.prerelease }}
build:
description: The build info of the semver
value: ${{ jobs.build-zig.outputs.build }}
version:
description: The full semver string
value: ${{ jobs.build-zig.outputs.version }}

jobs:
build-zig:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
outputs:
issemver: ${{ steps.semver.outputs.issemver }}
major: ${{ steps.semver.outputs.major }}
minor: ${{ steps.semver.outputs.minor }}
patch: ${{ steps.semver.outputs.patch }}
prerelease: ${{ steps.semver.outputs.prerelease }}
build: ${{ steps.semver.outputs.build }}
version: ${{ steps.semver.outputs.version }}
steps:
# If we just want to use the current commit, simply run a checkout
- name: Checkout
Expand All @@ -86,10 +127,13 @@ jobs:
ref: ${{ inputs.ref }}
sparse-checkout: ${{ inputs.sparse-checkout-patterns }}
submodules: ${{ inputs.get-submodules }}
# Parse the reference and pull out the semversion information if it is semversion
- name: Get Semver Details
shell: bash
id: semver
run: |
# 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.
# https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
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
echo "issemver=true" >> "$GITHUB_OUTPUT"
echo "major=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT"
Expand All @@ -101,7 +145,8 @@ jobs:
else
echo "issemver=false" >> "$GITHUB_OUTPUT"
fi
# Setup zig, we use mlugg's setup because it has caching
# If the reference is semver, modify all zon files to include the version from the reference
# Mac needs to be done different than windows/linux (see the sed command)
- name: Process Version Info
if: steps.semver.outputs.issemver == 'true' && runner.os != 'macOS'
shell: bash
Expand All @@ -112,26 +157,28 @@ jobs:
shell: bash
run: |
find . -name "*.zig.zon" -exec sed -i '' 's/\(.version *= *"\)[^\s]*\(",\)/\1${{ steps.semver.outputs.version }}\2/' {} \;
# Setup zig, we use mlugg's setup because it has caching
- name: Setup Zig
uses: mlugg/setup-zig@v1
with:
version: ${{ inputs.zig-version }}
- name: Build
run: zig build -Doptimize=ReleaseSmall
working-directory: ${{ inputs.working-directory }}
run: |
zig build ${{ inputs.zig-args }}
working-directory: ./${{ inputs.working-directory }}
- name: Package
if: ${{ inputs.is-packaged && runner.os == 'macOS' }}
run: zig build package -- "${{ secrets.downloads-url }}"
working-directory: ./${{ inputs.working-directory }}
# We use whether or not an artifact output path is provided and whether
# or not there is actually anything in that directory to know whether or
# not there is anything to upload.
- name: Get Should Upload bash
id: should-upload
shell: bash
run: |
if [[ ! -z "${{ inputs.artifact-output-paths }}" ]] \
&& test -n "$(find . -maxdepth 1 \
-name '${{ inputs.artifact-output-paths }}' \
if [[ ! -z "${{ inputs.artifact-output-path }}" ]] \
&& test -n "$(find ${{ inputs.artifact-output-path }} -maxdepth 1 \
-print -quit)"; then
echo "SHOULD_UPLOAD=true" >> $GITHUB_OUTPUT;
else
Expand All @@ -142,8 +189,9 @@ jobs:
- name: Upload Artifacts
if: |
steps.should-upload.outputs.SHOULD_UPLOAD == 'true'
&& inputs.github-artifact-name != ''
&& inputs.github-artifact-name != ''
&& ( runner.os == inputs.target-os || inputs.target-os == '' )
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.github-artifact-name }}
path: ${{ inputs.artifact-output-paths }}
path: ${{ inputs.artifact-output-path }}
1 change: 1 addition & 0 deletions .github/workflows/build-microzig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
zig-version: 0.13.0
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
Expand Down
31 changes: 1 addition & 30 deletions .github/workflows/publish-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ on:
required: true
type: string
description: The github artifact to download the artifact from.
artifact-name:
required: true
type: string
description: The name of what we are publishing
# The path after the target-path to publish the artifact to
# {artifact | {target-path}/{target-artifact-path}
target-artifact-path:
Expand Down Expand Up @@ -57,7 +53,7 @@ on:

jobs:
publish:
runs-on: macos-latest
runs-on: ubuntu-latest
steps:
# If this is somehow not run from a tag, fail. This is a remainder from
# when the build side and publish side were done in one workflow.
Expand Down Expand Up @@ -97,31 +93,6 @@ jobs:
REMOTE_USER: ${{ secrets.user }}
REMOTE_PORT: ${{ secrets.port }}
TARGET: ${{ secrets.target-path }}/${{ inputs.target-artifact-path }}
# (Not working as intented) Un-needed for now. This step would go through
# every binary and folder within the source path and add it to the release
# if it were a file, or compress it and then add the compressed file to
# the release.
# Issue: Adds things that are not desired in the output.
#- name: Handle Folder Release Artifact
# if: ${{ startsWith(github.ref, 'refs/tags/') && endsWith(github.ref, inputs.tag) }}
# shell: bash
# run: |
# mkdir -p "artifacts-${{ github.sha }}"
# for i in "${{ steps.download.outputs.download-path }}/${{ inputs.source-path }}"/*; do
# echo "Artifact path $i"
# if [[ -d "$i" ]]; then
# echo "Artifact is path"
# dirname="$(basename "$i")"
# echo "Artifact directory $dirname. Compressing folder to ${{ inputs.artifact-name }}-${dirname}.tar.gz"
# tar -czvf "${{ inputs.artifact-name }}-${dirname}.tar.gz" -C "$i" .
# echo "Moving tar to artifacts-${{ github.sha }}"
# mv "${{ inputs.artifact-name }}-${dirname}.tar.gz" "artifacts-${{ github.sha }}"
# else
# echo "Artifact is file"
# echo "Move to: artifacts-${{ github.sha }}"
# mv "$i" "artifacts-${{ github.sha }}"
# fi
# done
# Create the release draft on GitHub.
- name: Create Release Draft
if: ${{ startsWith(github.ref, 'refs/tags/') && endsWith(github.ref, inputs.tag) }}
Expand Down
20 changes: 16 additions & 4 deletions .github/workflows/publish-microzig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,38 @@ jobs:
# Build the project to ensure it works. Also to get the binaries.
build-microzig:
uses: ./.github/workflows/build-base.yml
concurrency:
group: build
cancel-in-progress: true
with:
zig-version: 0.13.0
get-submodules: true
is-packaged: true
target-os: macOS
github-artifact-name: microzig-build
artifact-output-paths: boxzer-out
artifact-output-path: boxzer-out
ref: ${{ github.ref_name }}
secrets:
downloads-url: ${{ secrets.BOXZER_DOWNLOADS_URL }}
# Alters the boxzer output to match what we desire
alter-microzig-artifact:
uses: ./.github/workflows/alter-microzig-artifact.yml
needs: build-microzig
with:
in-gh-artifact-name: microzig-build
out-gh-artifact-name: microzig-alt
zig-version: 0.13.0
microzig-version: ${{ needs.build-microzig.outputs.version }}
# Publish microzig
publish-microzig:
uses: ./.github/workflows/publish-base.yml
needs: build-microzig
needs: alter-microzig-artifact
concurrency:
group: publish
cancel-in-progress: false
with:
tag: ${{ github.ref_name }}
artifact-name: microzig
github-artifact-name: microzig-build
github-artifact-name: microzig-alt
source-path: /
secrets:
target-path: ${{ secrets.DEPLOY_MZ_ROOT_DATA_PATH }}
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/publish-website-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@ on:

jobs:
# Build the project to ensure it works. Also to get the binaries.
build-microzig:
build-website:
uses: ./.github/workflows/build-base.yml
with:
zig-version: 0.13.0
get-submodules: true
target-os: Linux
github-artifact-name: website-build
artifact-output-paths: zig-out
artifact-output-path: website/zig-out
working-directory: website
# Publish microzig
publish-microzig:
publish-website:
uses: ./.github/workflows/publish-base.yml
needs: build-microzig
needs: build-website
concurrency:
group: publish
cancel-in-progress: false
with:
artifact-name: website
github-artifact-name: website-build
source-path: /
secrets:
Expand All @@ -39,6 +40,7 @@ jobs:
user: ${{ secrets.DEPLOY_WS_USER }}
pr-comment:
runs-on: ubuntu-latest
needs: publish-website
permissions:
pull-requests: write
steps:
Expand Down
Loading

0 comments on commit 3f23611

Please sign in to comment.