From 861ef028e0f0ab2e12368422ab7bc0e0b8fac279 Mon Sep 17 00:00:00 2001 From: EliSauder <24995216+EliSauder@users.noreply.github.com> Date: Fri, 25 Oct 2024 22:32:31 -0700 Subject: [PATCH] feat: simplify workflows --- .github/workflows/alter-microzig-artifact.yml | 120 ------------------ .github/workflows/build-microzig.yml | 110 ---------------- .github/workflows/publish-website-staging.yml | 51 -------- .github/workflows/publish-website.yml | 20 ++- .github/workflows/zig-master-build.yml | 19 --- blahfile | 0 website/blahfile | 0 7 files changed, 19 insertions(+), 301 deletions(-) delete mode 100644 .github/workflows/alter-microzig-artifact.yml delete mode 100644 .github/workflows/publish-website-staging.yml delete mode 100644 .github/workflows/zig-master-build.yml create mode 100644 blahfile create mode 100644 website/blahfile diff --git a/.github/workflows/alter-microzig-artifact.yml b/.github/workflows/alter-microzig-artifact.yml deleted file mode 100644 index 9b8add275..000000000 --- a/.github/workflows/alter-microzig-artifact.yml +++ /dev/null @@ -1,120 +0,0 @@ -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: - alter: - 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 - # Generate the folders that will be in the final artifact. Here is an - # example: - # zig-0.13.0/ - # └── microzig-0.1.0/ - #    ├── port/ - #    ├── build/ - #    ├── tools/ - #    └── examples/ - - 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 }}/port/" - 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/" - # In later steps we are going to use the outputs from the steps. To - # ensure that when we use them without quotes for globbint, we don't - # break things, create sanitized versions of the paths. - - 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 - # Copy files of which there are one of (Things that can be moved and - # renamed in the same step easily). - # Example: - # zig-0.13.0/ - # └── microzig-0.1.0/ - #    ├── port/ - #    ├── build/ - # │ └── definitions.tar.gz - #    ├── tools/ - #    ├── examples/ - #    ├── microzig-build.tar.gz - #    ├── microzig-core.tar.gz - #    └── microzig.tar.gz - - name: Copy Root, Build, Core - 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" - # Move over all of the files of which are similar. These still need to be - # renamed (this and the next step could be combined, but I have them - # separated to help with mental overhead). - - name: Move examples, port, tools - shell: bash - run: | - mv ${{ steps.get-glob-paths.outputs.source-path }}/microzig-*/tools/*.tar.gz "${{ steps.base-folders.outputs.path }}/tools" - mv ${{ steps.get-glob-paths.outputs.source-path }}/microzig-*/port/*/*.tar.gz "${{ steps.base-folders.outputs.path }}/port/" - mv ${{ steps.get-glob-paths.outputs.source-path }}/microzig-*/examples/*/*.tar.gz "${{ steps.base-folders.outputs.path }}/examples/" - # Rename all the files to remove the version information from the filename. - - name: Rename examples, port, tools - 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 }}/port" -type f -exec sh -c 'mv "{}" "$(dirname -- "{}")/$(basename -- "{}" | sed "s/-.*\.tar\.gz/-port.tar.gz/g")"' \; - find "${{ steps.base-folders.outputs.path }}/tools" -type f -exec sh -c 'mv "{}" "$(dirname -- "{}")/$(basename -- "{}" | sed "s/-.*\.tar\.gz/.tar.gz/g")"' \; - # Upload everything to the new artifact - - name: Upload Artifacts - uses: actions/upload-artifact@v4 - with: - name: ${{ inputs.out-gh-artifact-name }} - path: "./output/" diff --git a/.github/workflows/build-microzig.yml b/.github/workflows/build-microzig.yml index b1d8d1211..4fe559a6f 100644 --- a/.github/workflows/build-microzig.yml +++ b/.github/workflows/build-microzig.yml @@ -35,113 +35,3 @@ jobs: 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 }} diff --git a/.github/workflows/publish-website-staging.yml b/.github/workflows/publish-website-staging.yml deleted file mode 100644 index ec9b575b5..000000000 --- a/.github/workflows/publish-website-staging.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: Deploy Website - Staging - -permissions: - contents: write - -on: - pull_request: - branches: - - main - paths: - - .github/** - - website/** - -jobs: - # Build the project to ensure it works. Also to get the binaries. - build-website: - uses: ./.github/workflows/build-base.yml - with: - zig-version: ${{ vars.WS_TARGET_ZIG_VERSION }} - get-submodules: true - target-os: Linux - github-artifact-name: website-build - artifact-output-path: website/zig-out - working-directory: website - # Publish microzig - publish-website: - uses: ./.github/workflows/publish-base.yml - needs: build-website - concurrency: - group: publish - cancel-in-progress: false - with: - github-artifact-name: website-build - source-path: / - secrets: - target-path: "${{ secrets.DEPLOY_ROOT_DATA_PATH }}/staging/pulls/${{ github.event.number }}/" - ssh-key: ${{ secrets.DEPLOY_PRIVATE_KEY }} - host: ${{ secrets.DEPLOY_HOST }} - port: ${{ secrets.DEPLOY_PORT }} - user: ${{ secrets.DEPLOY_USER }} - pr-comment: - runs-on: ubuntu-latest - needs: publish-website - permissions: - pull-requests: write - steps: - - uses: mshick/add-pr-comment@v2 - with: - message: | - Heya! - You can check out a preview of your PR at [${{ vars.WEBSITE_STAGING_HOST }}/pulls/${{ github.event.number }}/](${{ vars.WEBSITE_STAGING_HOST }}/pulls/${{ github.event.number }}/)! diff --git a/.github/workflows/publish-website.yml b/.github/workflows/publish-website.yml index 3a50e9f67..b3f02afd1 100644 --- a/.github/workflows/publish-website.yml +++ b/.github/workflows/publish-website.yml @@ -10,6 +10,12 @@ on: paths: - .github/** - website/** + pull_request: + branches: + - main + paths: + - .github/** + - website/** jobs: # Build the project to ensure it works. Also to get the binaries. @@ -33,8 +39,20 @@ jobs: github-artifact-name: website-build source-path: / secrets: - target-path: ${{ secrets.DEPLOY_ROOT_DATA_PATH }} + target-path: ${{ github.event_name == 'pull_request' && format('{0}/staging/pulls/{1}', secrets.DEPLOY_ROOT_DATA_PATH, github.event.number) || secrets.DEPLOY_ROOT_DATA_PATH }} ssh-key: ${{ secrets.DEPLOY_PRIVATE_KEY }} host: ${{ secrets.DEPLOY_HOST }} port: ${{ secrets.DEPLOY_PORT }} user: ${{ secrets.DEPLOY_USER }} + pr-comment: + if: ${{ github.event_name == 'pull_request' }} + runs-on: ubuntu-latest + needs: publish-website + permissions: + pull-requests: write + steps: + - uses: mshick/add-pr-comment@v2 + with: + message: | + Heya! + You can check out a preview of your PR at [${{ vars.WEBSITE_STAGING_HOST }}/pulls/${{ github.event.number }}/](${{ vars.WEBSITE_STAGING_HOST }}/pulls/${{ github.event.number }}/)! diff --git a/.github/workflows/zig-master-build.yml b/.github/workflows/zig-master-build.yml deleted file mode 100644 index 234f2316c..000000000 --- a/.github/workflows/zig-master-build.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Build Microzig Master -on: - push: - branches: [zig-master] - pull_request: - branches: [zig-master] - -# A simple workflow that will, upon a push or PR to zig-master, build microzig -jobs: - build-microzig-master-post-pr: - name: Build with master - uses: ./.github/workflows/build-base.yml - with: - zig-version: master - get-submodules: true - is-packaged: false - zig-args: -Doptimize=ReleaseSmall - secrets: - downloads-url: ${{ secrets.DOWNLOADS_URL }} diff --git a/blahfile b/blahfile new file mode 100644 index 000000000..e69de29bb diff --git a/website/blahfile b/website/blahfile new file mode 100644 index 000000000..e69de29bb