From fb71ac4f672273a53de8dfa2d8e14cfdbc08e951 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Tue, 12 Sep 2023 08:10:18 +0200 Subject: [PATCH 1/3] ci: add github ci workflows --- .github/workflows/zig-fmt.yml | 51 ++++++++++++++++++++++++++++++++++ .github/workflows/zig-test.yml | 37 ++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 .github/workflows/zig-fmt.yml create mode 100644 .github/workflows/zig-test.yml diff --git a/.github/workflows/zig-fmt.yml b/.github/workflows/zig-fmt.yml new file mode 100644 index 0000000..6af423b --- /dev/null +++ b/.github/workflows/zig-fmt.yml @@ -0,0 +1,51 @@ +# Original version: https://github.com/oven-sh/bun/blob/main/.github/workflows/zig-fmt.yml +name: zig-fmt + +env: + ZIG_VERSION: 0.11.0 + +on: + pull_request: + branches: + - main + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + zig-fmt: + name: zig fmt + runs-on: ubuntu-latest + outputs: + zig_fmt_errs: ${{ steps.fmt.outputs.zig_fmt_errs }} + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + fetch-depth: 0 + + - name: Install zig + run: | + curl https://ziglang.org/download/${{env.ZIG_VERSION}}/zig-linux-x86_64-${{env.ZIG_VERSION}}.tar.xz -L -o zig.tar.xz + tar -xf zig.tar.xz + echo "$(pwd)/zig-linux-x86_64-${{env.ZIG_VERSION}}" >> $GITHUB_PATH + - name: Run zig fmt + id: fmt + run: | + zig fmt --check ./*.zig ./**/*.zig 2> zig-fmt.err > zig-fmt.err2 || echo "Failed" + delimiter="$(openssl rand -hex 8)" + echo "zig_fmt_errs<<${delimiter}" >> "${GITHUB_OUTPUT}" + + if [ -s zig-fmt.err ]; then + echo "// The following errors occurred:" >> "${GITHUB_OUTPUT}" + cat zig-fmt.err >> "${GITHUB_OUTPUT}" + fi + + if [ -s zig-fmt.err2 ]; then + echo "// The following files were not formatted:" >> "${GITHUB_OUTPUT}" + cat zig-fmt.err2 >> "${GITHUB_OUTPUT}" + fi + + echo "${delimiter}" >> "${GITHUB_OUTPUT}" + - name: Fail the job + if: steps.fmt.outputs.zig_fmt_errs != '' + run: exit 1 diff --git a/.github/workflows/zig-test.yml b/.github/workflows/zig-test.yml new file mode 100644 index 0000000..6ea34b0 --- /dev/null +++ b/.github/workflows/zig-test.yml @@ -0,0 +1,37 @@ +name: test + +env: + ZIG_VERSION: 0.11.0 + +on: + push: + branches: + - main + paths: + - "src/**/*.zig" + - "src/*.zig" + pull_request: + branches: + - main + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + test: + name: test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + fetch-depth: 0 + + - name: Install zig + run: | + curl https://ziglang.org/download/${{env.ZIG_VERSION}}/zig-linux-x86_64-${{env.ZIG_VERSION}}.tar.xz -L -o zig.tar.xz + tar -xf zig.tar.xz + echo "$(pwd)/zig-linux-x86_64-${{env.ZIG_VERSION}}" >> $GITHUB_PATH + - run: zig test constants.zig + - run: zig test fifo.zig + - run: zig test io.zig + - run: zig test time.zig From a597c161d051962ba9ed9dde97a5ef9ba3f8a57e Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 13 Nov 2023 11:01:16 +0100 Subject: [PATCH 2/3] ci: use zig docker image --- .github/workflows/zig-fmt.yml | 12 ++++++------ .github/workflows/zig-test.yml | 17 +++++++++-------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/zig-fmt.yml b/.github/workflows/zig-fmt.yml index 6af423b..da694f3 100644 --- a/.github/workflows/zig-fmt.yml +++ b/.github/workflows/zig-fmt.yml @@ -1,4 +1,3 @@ -# Original version: https://github.com/oven-sh/bun/blob/main/.github/workflows/zig-fmt.yml name: zig-fmt env: @@ -15,6 +14,12 @@ jobs: zig-fmt: name: zig fmt runs-on: ubuntu-latest + container: + image: ghcr.io/browsercore/zig-v8:${{env.ZIG_VERSION}} + credentials: + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + outputs: zig_fmt_errs: ${{ steps.fmt.outputs.zig_fmt_errs }} steps: @@ -23,11 +28,6 @@ jobs: submodules: recursive fetch-depth: 0 - - name: Install zig - run: | - curl https://ziglang.org/download/${{env.ZIG_VERSION}}/zig-linux-x86_64-${{env.ZIG_VERSION}}.tar.xz -L -o zig.tar.xz - tar -xf zig.tar.xz - echo "$(pwd)/zig-linux-x86_64-${{env.ZIG_VERSION}}" >> $GITHUB_PATH - name: Run zig fmt id: fmt run: | diff --git a/.github/workflows/zig-test.yml b/.github/workflows/zig-test.yml index 6ea34b0..376526e 100644 --- a/.github/workflows/zig-test.yml +++ b/.github/workflows/zig-test.yml @@ -1,4 +1,4 @@ -name: test +name: zig-test env: ZIG_VERSION: 0.11.0 @@ -17,20 +17,21 @@ on: workflow_dispatch: jobs: - test: - name: test + zig-test: + name: zig test runs-on: ubuntu-latest + container: + image: ghcr.io/browsercore/zig-v8:${{env.ZIG_VERSION}} + credentials: + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + steps: - uses: actions/checkout@v3 with: submodules: recursive fetch-depth: 0 - - name: Install zig - run: | - curl https://ziglang.org/download/${{env.ZIG_VERSION}}/zig-linux-x86_64-${{env.ZIG_VERSION}}.tar.xz -L -o zig.tar.xz - tar -xf zig.tar.xz - echo "$(pwd)/zig-linux-x86_64-${{env.ZIG_VERSION}}" >> $GITHUB_PATH - run: zig test constants.zig - run: zig test fifo.zig - run: zig test io.zig From 04d758115b342595db2937244b2bdb49d8398670 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 13 Nov 2023 11:06:35 +0100 Subject: [PATCH 3/3] ci: hardcode zig version image b/c using env doesn't work as exepected: ``` Invalid workflow file: .github/workflows/zig-test.yml#L24 The workflow is not valid. .github/workflows/zig-test.yml (Line: 24, Col: 14): Unrecognized named-value: 'env'. Located at position 1 within expression: env.ZIG_VERSION ``` --- .github/workflows/zig-fmt.yml | 7 ++----- .github/workflows/zig-test.yml | 5 +---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/zig-fmt.yml b/.github/workflows/zig-fmt.yml index da694f3..0a94a2a 100644 --- a/.github/workflows/zig-fmt.yml +++ b/.github/workflows/zig-fmt.yml @@ -1,8 +1,5 @@ name: zig-fmt -env: - ZIG_VERSION: 0.11.0 - on: pull_request: branches: @@ -15,13 +12,13 @@ jobs: name: zig fmt runs-on: ubuntu-latest container: - image: ghcr.io/browsercore/zig-v8:${{env.ZIG_VERSION}} + image: ghcr.io/browsercore/zig:0.11.0 credentials: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - outputs: zig_fmt_errs: ${{ steps.fmt.outputs.zig_fmt_errs }} + steps: - uses: actions/checkout@v3 with: diff --git a/.github/workflows/zig-test.yml b/.github/workflows/zig-test.yml index 376526e..432b1c5 100644 --- a/.github/workflows/zig-test.yml +++ b/.github/workflows/zig-test.yml @@ -1,8 +1,5 @@ name: zig-test -env: - ZIG_VERSION: 0.11.0 - on: push: branches: @@ -21,7 +18,7 @@ jobs: name: zig test runs-on: ubuntu-latest container: - image: ghcr.io/browsercore/zig-v8:${{env.ZIG_VERSION}} + image: ghcr.io/browsercore/zig:0.11.0 credentials: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }}