Skip to content

Commit

Permalink
feat: simplify workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
EliSauder committed Oct 26, 2024
1 parent ee086b4 commit 861ef02
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 301 deletions.
120 changes: 0 additions & 120 deletions .github/workflows/alter-microzig-artifact.yml

This file was deleted.

110 changes: 0 additions & 110 deletions .github/workflows/build-microzig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
51 changes: 0 additions & 51 deletions .github/workflows/publish-website-staging.yml

This file was deleted.

20 changes: 19 additions & 1 deletion .github/workflows/publish-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 }}/)!
19 changes: 0 additions & 19 deletions .github/workflows/zig-master-build.yml

This file was deleted.

Empty file added blahfile
Empty file.
Empty file added website/blahfile
Empty file.

0 comments on commit 861ef02

Please sign in to comment.