Skip to content

Commit

Permalink
*: refine github actions
Browse files Browse the repository at this point in the history
Signed-off-by: xhe <xw897002528@gmail.com>
  • Loading branch information
xhebox committed Sep 18, 2022
1 parent 7acab4d commit d6efffd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 67 deletions.
56 changes: 23 additions & 33 deletions .github/workflows/build.yml → .github/workflows/common.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
name: build
name: make
on:
workflow_call:
inputs:
debug:
type: boolean
description: "set tmate on failure"
required: true
target:
type: string
description: "makefile target"
required: true
ref:
type: string
description: "checkout specific ref"
required: true
all_platform:
type: boolean
description: "test on all platforms or not"
default: false

defaults:
run:
shell: bash

jobs:
cmd:
make:
strategy:
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
matrix: ${{ fromJSON(inputs.all_platform && '{"platform": ["ubuntu-latest", "macos-latest", "windows-latest"]}' || '{}') }}
runs-on: ${{ matrix.platform || 'ubuntu-latest' }}
steps:
- if: ${{ runner.os == 'Windows' }}
name: Use GNU tar for faster cache restore
Expand All @@ -33,41 +44,20 @@ jobs:
with:
go-version-file: go.mod
check-latest: true
cache: true
- name: "build cmd"
run: make
- name: "set up tmate session if necessary"
if: ${{ failure() && inputs.debug }}
uses: mxschmitt/action-tmate@v3

all:
needs: cmd
runs-on: ubuntu-latest
steps:
- name: "checkout repo"
uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}
- name: "setup golang"
uses: actions/setup-go@v3
with:
go-version: 1.18
- name: "set vars"
run: |
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_ENV
- name: "try to use build cache"
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
~/Library/Caches/go-build
~\AppData\Local\go-build
${{ env.GOCACHE }}
${{ env.GOMODCACHE }}
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: "build all"
run: make build
- name: "set up tmate session if necessary"
if: ${{ failure() && inputs.debug }}
uses: mxschmitt/action-tmate@v3
- run: make ${{ inputs.target }}
- name: "set up tmate session if necessary"
if: ${{ failure() && inputs.debug }}
uses: mxschmitt/action-tmate@v3
15 changes: 13 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,26 @@ concurrency:
cancel-in-progress: true

jobs:
cmd:
uses: ./.github/workflows/common.yml
with:
debug: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug }}
ref: ${{ inputs.ref || github.ref }}
target: "cmd"
all_platform: true

build:
uses: ./.github/workflows/build.yml
needs: cmd
uses: ./.github/workflows/common.yml
with:
debug: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug }}
ref: ${{ inputs.ref || github.ref }}
target: "build"

test:
needs: build
uses: ./.github/workflows/test.yml
uses: ./.github/workflows/common.yml
with:
debug: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug }}
ref: ${{ inputs.ref || github.ref }}
target: "test"
32 changes: 0 additions & 32 deletions .github/workflows/test.yml

This file was deleted.

0 comments on commit d6efffd

Please sign in to comment.