Skip to content

Commit

Permalink
ci: implement build pipeline and patch to zig master
Browse files Browse the repository at this point in the history
Additionally adds the base reusable workflows for publishing (though
they are untested)
  • Loading branch information
EliSauder committed Sep 23, 2024
1 parent bce1484 commit 2c49d73
Show file tree
Hide file tree
Showing 7 changed files with 302 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/build-microzig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ on:

jobs:
build-microzig:
<<<<<<< HEAD
if: |
${{
( github.event_name == 'pull_request' && github.base_ref == 'main' )
Expand All @@ -44,6 +45,18 @@ jobs:
# 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
Expand All @@ -56,25 +69,36 @@ jobs:
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: |
Expand All @@ -84,19 +108,26 @@ jobs:
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" \
Expand All @@ -118,18 +149,30 @@ jobs:
- 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:
Expand All @@ -145,3 +188,14 @@ jobs:
# 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)
77 changes: 77 additions & 0 deletions .github/workflows/publish-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ permissions:
on:
workflow_call:
inputs:
<<<<<<< HEAD
=======
# The tag that we are publishing to
>>>>>>> ea386ec (ci: implement build pipeline and patch to zig master)
tag:
required: false
type: string
default: ""
<<<<<<< HEAD
description: The version tag to publish
github-artifact-name:
required: true
Expand Down Expand Up @@ -61,10 +66,54 @@ jobs:
if: |
startsWith(github.ref, 'refs/tags/')
&& ! endsWith(github.ref, inputs.tag)
=======
# The name of what we are building
artifact:
required: true
type: string
# The name that will be used to same build artifacts to share
# between jobs
github-artifact-name:
required: true
type: string
# The root path to publish package to. If left blank, artifact
# is used.
artifact-target-name:
required: false
type: string
default: ""
# The target path that goes before the artifact-target-name
# {artifact | artifact-target-name}/{target-path}
target-path:
required: false
type: string
default: ""
# The folder where the stuff to be published is located
source:
required: true
type: string
secrets:
ssh-key:
required: true
host:
required: true
port:
required: true
user:
required: true

jobs:
publish:
runs-on: macos-latest
steps:
- name: Check tag status
if: ${{ startsWith(github.ref, 'refs/tags/') && ! endsWith(github.ref, input.tag) }}
>>>>>>> ea386ec (ci: implement build pipeline and patch to zig master)
uses: actions/github-script@v3
with:
script: |
core.setFailed("Provided tag does not match github ref tag")
<<<<<<< HEAD
# Download the requested github artifact
- name: Download artifacts
id: download
Expand All @@ -83,11 +132,26 @@ jobs:
"${{ steps.download.outputs.download-path }}/${{ inputs.source-path }}" \
)" >> $GITHUB_OUTPUT
# Publish to the host
=======
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: ${{ input.github-artifact-name }}
- name: Get Target
id: get-target
run: |
if [ -z ${{ input.artifact-target-name }} ]; then
echo "PUB_TARGET=${{ input.artifact }}" >> $GITHUB_OUTPUT;
else
echo "PUB_TARGET=${{ input.artifact-target-name }}" >> $GITHUB_OUTPUT;
fi
>>>>>>> ea386ec (ci: implement build pipeline and patch to zig master)
- name: Publish Release
uses: easingthemes/ssh-deploy@main
with:
SSH_PRIVATE_KEY: ${{ secrets.ssh-key }}
ARGS: "-vzrli"
<<<<<<< HEAD
SOURCE: ${{ steps.get-source-path.outputs.path }}
REMOTE_HOST: ${{ secrets.host }}
REMOTE_USER: ${{ secrets.user }}
Expand All @@ -100,6 +164,19 @@ jobs:
with:
# artifacts: "artifacts-${{ github.sha }}/*"
# artifactErrorsFailBuild: true
=======
SOURCE: ${{ input.source }}
REMOTE_HOST: ${{ secrets.host }}
REMOTE_USER: ${{ secrets.user }}
REMOTE_PORT: ${{ secrets.port }}
TARGET: ${{ steps.get-target.outputs.PUB_TARGET }}/${{ inputs.target-path }}
- name: Create Release Draft
if: ${{ startsWith(github.ref, 'refs/tags/') && endsWith(github.ref, input.tag) }}
uses: ncipollo/release-action@v1
with:
artifacts: ${{ input.source }}/*
artifactErrorsFailBuild: true
>>>>>>> ea386ec (ci: implement build pipeline and patch to zig master)
draft: true
generateReleaseNotes: true
tag: ${{ inputs.tag }}
Expand Down
69 changes: 69 additions & 0 deletions .github/workflows/publish-microzig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ permissions:
on:
push:
tags:
<<<<<<< HEAD
- "v*.*.*"
- "v*.*.*-*"

Expand Down Expand Up @@ -39,11 +40,36 @@ jobs:
publish-microzig:
uses: ./.github/workflows/publish-base.yml
needs: alter-microzig-artifact
=======
- "microzig-*.*.*"

jobs:
build-microzig:
uses: ./.github/workflows/build-zig-base.yml
with:
zig-version: 0.13.0
get-submodules: true
sparse-checkout-patterns: |
build.zig*
tools/**
core/**
build/**
bsp/**
examples/**
is-packaged: true
github-artifact-name: microzig
artifact-output-paths: boxzer-out
secrets:
downloads-url: ${{ secrets.DOWNLOADS_URL }}
publish-microzig:
uses: ./.github/workflows/publish-base.yml
>>>>>>> ea386ec (ci: implement build pipeline and patch to zig master)
concurrency:
group: publish
cancel-in-progress: false
with:
tag: ${{ github.ref_name }}
<<<<<<< HEAD
github-artifact-name: microzig-alt
source-path: /
secrets:
Expand All @@ -52,3 +78,46 @@ jobs:
host: ${{ secrets.DEPLOY_MZ_HOST }}
port: ${{ secrets.DEPLOY_MZ_PORT }}
user: ${{ secrets.DEPLOY_MZ_USER }}
=======
artifact: microzig
github-artifact-name: microzig-build
artifact-target-name: "."
source: boxzer-out/
secrets:
ssh-key: ${{ secrets.DEPLOY_PRIVATE_KEY }}
host: ${{ secrets.DEPLOY_HOST }}
port: ${{ secrets.DEPLOY_PORT }}
user: ${{ secrets.DEPLOY_USER }}
publish-microzig-regz:
concurrency:
group: publish
cancel-in-progress: false
uses: ./.github/workflows/publish-base.yml
with:
tag: ${{ github.ref_name }}
artifact: regz
github-artifact-name: microzig-build
artifact-target-name: "tools/regz"
source: zig-out/
secrets:
ssh-key: ${{ secrets.DEPLOY_PRIVATE_KEY }}
host: ${{ secrets.DEPLOY_HOST }}
port: ${{ secrets.DEPLOY_PORT }}
user: ${{ secrets.DEPLOY_USER }}
publish-microzig-uf2:
concurrency:
group: publish
cancel-in-progress: false
uses: ./.github/workflows/publish-base.yml
with:
tag: ${{ github.ref_name }}
artifact: regz
github-artifact-name: microzig-build
artifact-target-name: "tools/uf2"
source: zig-out/
secrets:
ssh-key: ${{ secrets.DEPLOY_PRIVATE_KEY }}
host: ${{ secrets.DEPLOY_HOST }}
port: ${{ secrets.DEPLOY_PORT }}
user: ${{ secrets.DEPLOY_USER }}
>>>>>>> ea386ec (ci: implement build pipeline and patch to zig master)
Loading

0 comments on commit 2c49d73

Please sign in to comment.