Skip to content

Commit

Permalink
gh-action: auto-choose runner
Browse files Browse the repository at this point in the history
  • Loading branch information
seriousm4x committed Oct 3, 2023
1 parent 02367b5 commit b32d569
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ jobs:
runs-on: ubuntu-latest
outputs:
runner-label: ${{ steps.set-runner.outputs.runner-label }}

steps:
- name: Set runner
id: set-runner
Expand All @@ -25,12 +24,10 @@ jobs:
runs-on: ${{ needs.check-runner.outputs.runner-label }}
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ">=1.21"

- name: Test
run: |
cd backend
Expand Down
25 changes: 22 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,25 @@ on:
workflow_dispatch:

jobs:
goreleaser:
check-runner:
runs-on: ubuntu-latest
outputs:
runner-label: ${{ steps.set-runner.outputs.runner-label }}
steps:
- name: Set runner
id: set-runner
run: |
runners=$(curl -s -H "Accept: application/vnd.github+json" -H "Authorization: token ${{ secrets.REPO_ACCESS_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/actions/runners")
available=$(echo "$runners" | jq '.runners[] | select(.status == "online" and .busy == false and .labels[] .name == "self-hosted")')
if [ -n "$available" ]; then
echo "runner-label=self-hosted" >> "$GITHUB_OUTPUT"
else
echo "runner-label=ubuntu-latest" >> "$GITHUB_OUTPUT"
fi
goreleaser:
needs: check-runner
runs-on: ${{ needs.check-runner.outputs.runner-label }}
steps:
# pull code
- name: Checkout
Expand Down Expand Up @@ -48,8 +65,10 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

docker:
needs: goreleaser
runs-on: ubuntu-latest
needs:
- goreleaser
- check-runner
runs-on: ${{ needs.check-runner.outputs.runner-label }}
steps:
# pull code
- name: Check Out Repo
Expand Down

0 comments on commit b32d569

Please sign in to comment.