From efa3abecfdc7143fe2bd9a5cd1eec2d6bdee5782 Mon Sep 17 00:00:00 2001 From: Chlod Aidan Alejandro Date: Fri, 23 Dec 2022 22:00:22 +0800 Subject: [PATCH] Add external use tests to `build.yml` (#5) * make build.yml reproducible `build.yml` is currently biased to succeed every time on this repository. Reasoning is that it will always checkout the actions' repository (which essentially transfers the actions' files to the "working directory", not the case if this action is being used externally), and it assumes that the action is run locally. This commit breaks the build file into two parts: one that performs the current action as-is, and a new job which attempts to simulate usage from an external repository. In this job, no initial checkout is made and an immediate attempt at connecting to a ZeroTier network is made. * trigger workflow run * build.yml: only run test job on main This forces the `test` job to only run if the workflow was triggered from the `main` branch. It wouldn't make sense to check if `main` works when using a different branch or tag, so this avoids doing that entirely. `test` cannot automatically use the ref that triggered this workflow because `uses` does not take in expressions (and therefore cannot use `github.ref_name`). --- .github/workflows/build.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c0bdb0a..4dde9e7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,3 +27,27 @@ jobs: let count=count-1 done echo "ping success" + + test: + strategy: + matrix: + os: [ ubuntu-latest, macos-latest, windows-latest ] + runs-on: ${{ matrix.os }} + if: github.ref_name === "main" + steps: + - name: zerotier + uses: zerotier/github-action@main + with: + network_id: ${{ secrets.ZEROTIER_NETWORK_ID }} + auth_token: ${{ secrets.ZEROTIER_CENTRAL_TOKEN }} + + - name: ping host + shell: bash + run: | + count=10 + while ! ping -c 1 ${{ secrets.ZEROTIER_HOST_IP }} ; do + echo "waiting..." ; + sleep 1 ; + let count=count-1 + done + echo "ping success"