From 2c49d73e149c8f95ec80874b6d8629cbb3eee9e5 Mon Sep 17 00:00:00 2001 From: EliSauder <24995216+EliSauder@users.noreply.github.com> Date: Fri, 26 Jul 2024 01:22:36 -0700 Subject: [PATCH] ci: implement build pipeline and patch to zig master Additionally adds the base reusable workflows for publishing (though they are untested) --- .github/workflows/build-microzig.yml | 54 ++++++++++++++++ .github/workflows/publish-base.yml | 77 ++++++++++++++++++++++ .github/workflows/publish-microzig.yml | 69 ++++++++++++++++++++ .github/workflows/zig-build-base.yml | 88 ++++++++++++++++++++++++++ .github/workflows/zig-master-build.yml | 10 +++ .gitmodules | 3 + check-pr-exists-output | 1 + 7 files changed, 302 insertions(+) create mode 100644 .github/workflows/zig-build-base.yml create mode 100644 .gitmodules create mode 100644 check-pr-exists-output diff --git a/.github/workflows/build-microzig.yml b/.github/workflows/build-microzig.yml index 925e0a33..8dff1c1d 100644 --- a/.github/workflows/build-microzig.yml +++ b/.github/workflows/build-microzig.yml @@ -21,6 +21,7 @@ on: jobs: build-microzig: +<<<<<<< HEAD if: | ${{ ( github.event_name == 'pull_request' && github.base_ref == 'main' ) @@ -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 @@ -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: | @@ -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" \ @@ -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: @@ -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) diff --git a/.github/workflows/publish-base.yml b/.github/workflows/publish-base.yml index 577a6fbb..6acfd511 100644 --- a/.github/workflows/publish-base.yml +++ b/.github/workflows/publish-base.yml @@ -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 @@ -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 @@ -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 }} @@ -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 }} diff --git a/.github/workflows/publish-microzig.yml b/.github/workflows/publish-microzig.yml index c2ad9e7c..5d7f05f9 100644 --- a/.github/workflows/publish-microzig.yml +++ b/.github/workflows/publish-microzig.yml @@ -6,6 +6,7 @@ permissions: on: push: tags: +<<<<<<< HEAD - "v*.*.*" - "v*.*.*-*" @@ -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: @@ -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) diff --git a/.github/workflows/zig-build-base.yml b/.github/workflows/zig-build-base.yml new file mode 100644 index 00000000..aa522ed8 --- /dev/null +++ b/.github/workflows/zig-build-base.yml @@ -0,0 +1,88 @@ +name: Reusable zig build workflow + +on: + workflow_call: + inputs: + # The version to build on + zig-version: + required: false + type: string + default: 0.13.0 + # Whether or not to clone submodules + get-submodules: + required: false + type: string + default: false + # If using sparse checkout, the file patterns to include when cloning + sparse-checkout-patterns: + required: false + type: string + default: "" + # If building a subproject only, you can specify a working directory + # which is the path to that subproject. + working-directory: + required: false + type: string + default: "." + # Whether or not to use a provided package command. + is-packaged: + required: false + type: boolean + default: false + # The github artifact name for uploading build artifacts to + # If it is blank, nothing will be uploaded + github-artifact-name: + required: false + type: string + default: "" + # The path that we should upload artifacts from + artifact-output-paths: + required: true + type: string + ref: + required: false + type: string + default: "" + secrets: + # The downloads url for the packaging step. This is used in boxzer to + # fill in the manifest downloads location + downloads-url: + required: false + +jobs: + build-zig: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] #, windows-latest, macos-latest] + steps: + - name: Checkout + if: ${{ inputs.ref == '' }} + uses: actions/checkout@v4 + with: + sparse-checkout: ${{ inputs.sparse-checkout-patterns }} + submodules: ${{ inputs.get-submodules }} + - name: Checkout Specific Ref + if: ${{ inputs.ref != '' }} + uses: actions/checkout@v4 + with: + ref: ${{ inputs.ref }} + sparse-checkout: ${{ inputs.sparse-checkout-patterns }} + submodules: ${{ inputs.get-submodules }} + - name: Setup Zig + uses: mlugg/setup-zig@v1 + with: + version: ${{ inputs.zig-version }} + - name: Build + if: ${{ ! inputs.is-packaged || runner.os != 'macOS' }} + run: zig build -Doptimize=ReleaseSmall + working-directory: ${{ inputs.working-directory }} + - name: Package + if: ${{ inputs.is-packaged && runner.os == 'macOS' }} + run: zig build package -- "${{ secrets.downloads-url }}" + - name: Upload Artifacts + if: ${{ inputs.artifact-output-paths == '' }} + uses: actions/upload-artifact@v4 + with: + name: ${{ inputs.github-artifact-name }} + path: ${{ inputs.artifact-output-paths }} diff --git a/.github/workflows/zig-master-build.yml b/.github/workflows/zig-master-build.yml index 5d771d94..2989ebff 100644 --- a/.github/workflows/zig-master-build.yml +++ b/.github/workflows/zig-master-build.yml @@ -5,7 +5,10 @@ on: pull_request: branches: [zig-master] +<<<<<<< HEAD # A simple workflow that will, upon a push or PR to zig-master, build microzig +======= +>>>>>>> ea386ec (ci: implement build pipeline and patch to zig master) jobs: # No we don't need this still, I'm just happy about figuring out the jq query # (I don't want to hear that it is simple, I think it's cool xD) @@ -24,12 +27,19 @@ jobs: # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} build-microzig-master-post-pr: name: Build with master +<<<<<<< HEAD uses: ./.github/workflows/build-base.yml +======= + uses: ./.github/workflows/zig-build-base.yml +>>>>>>> ea386ec (ci: implement build pipeline and patch to zig master) with: zig-version: master get-submodules: true is-packaged: true artifact-output-paths: boxzer-out +<<<<<<< HEAD zig-args: -Doptimize=ReleaseSmall +======= +>>>>>>> ea386ec (ci: implement build pipeline and patch to zig master) secrets: downloads-url: ${{ secrets.DOWNLOADS_URL }} diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..1f9e54d4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tools/uf2/deps/uf2"] + path = tools/uf2/deps/uf2 + url = https://github.com/microsoft/uf2.git diff --git a/check-pr-exists-output b/check-pr-exists-output new file mode 100644 index 00000000..e799c670 --- /dev/null +++ b/check-pr-exists-output @@ -0,0 +1 @@ +no pull requests match your search in EliSauder/microzig