Update Workflows #15
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Microzig | |
on: | |
push: | |
branches: [main] | |
paths: | |
- .github/** | |
- build.zig* | |
- tools/** | |
- core/** | |
- port/** | |
- examples/** | |
pull_request: | |
branches: [main] | |
paths: | |
- build.zig* | |
- tools/** | |
- core/** | |
- port/** | |
- examples/** | |
jobs: | |
build-microzig: | |
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 | |
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: | |
# 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. | |
- 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: | | |
if [[ -z "$(git ls-remote \ | |
--heads origin master-patch/${{ github.sha }})" ]]; then | |
echo "exists=false" >> "$GITHUB_OUTPUT" | |
else | |
echo "exists=true" >> "$GITHUB_OUTPUT" | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# If the branch doesn't already exist, we create a new one. We use the | |
# username and email of the last commit. | |
- 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 }} | |
# Checkout to the new branch | |
- name: checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: master-patch/${{ github.sha }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# Create an empty commit that will be used to save the ci results | |
# against (For more details see "create-branch" comment) | |
- name: add-commit | |
run: | | |
git config user.name "$(git log -1 --pretty=format:'%an')" | |
git config user.email "$(git log -1 --pretty=format:'%ae')" | |
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. | |
- 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: | | |
gh pr list -B zig-master \ | |
-H "${{ needs.create-branch.outputs.branch }}" 2> check-exists-out | |
if [[ -z "$(cat check-exists-out)" ]]; then | |
echo "exists=false" >> "$GITHUB_OUTPUT" | |
else | |
echo "exists=true" >> "$GITHUB_OUTPUT" | |
fi | |
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 }} |