Skip to content

ci: Refactor test execution in GitHub Actions for cross-platform comp… #17

ci: Refactor test execution in GitHub Actions for cross-platform comp…

ci: Refactor test execution in GitHub Actions for cross-platform comp… #17

name: release-please
on:
push:
branches:
- main
permissions:
contents: write
pull-requests: write
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
go-version: ['1.23.x']
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
cache: true
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- run: go mod download
# Windows test step
- name: Run tests (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
go test -v -race -parallel 4 -json -coverprofile coverage.txt -covermode atomic ./... | tee test-output.json
echo "Test timing summary:"
jq -r 'select(.Action == "pass") | "\(.Package): \(.Elapsed)s"' test-output.json |
ForEach-Object { $_ -split ': ' | Select-Object @{n='Package';e={$_[0]}},@{n='Time';e={[double]($_[1] -replace 's$')}} } |
Sort-Object Time -Descending |
Select-Object -First 10 |
ForEach-Object { "$($_.Package): $($_.Time)s" }
# Unix test step
- name: Run tests (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
go test -v -race -parallel 4 -json -coverprofile coverage.txt -covermode atomic ./... | tee test-output.json
echo "Test timing summary:"
jq -r 'select(.Action == "pass") | "\(.Package): \(.Elapsed)s"' test-output.json | sort -k2 -nr | head -n 10
release-please:
needs: test
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
steps:
- uses: googleapis/release-please-action@v4
id: release
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: go
package-name: take
goreleaser:
needs: release-please
if: ${{ needs.release-please.outputs.release_created }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v4
with:
go-version: '>=1.23.0'
cache: true
- uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --clean --skip-sign
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAP_GITHUB_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN }}
homebrew:
needs: [release-please, goreleaser]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
repository: deblasis/homebrew-tap
token: ${{ secrets.TAP_GITHUB_TOKEN }}
- name: Update Homebrew formula
run: |
version="${{ needs.release-please.outputs.tag_name }}"
version="${version#v}"
sed -i "s/version \".*\"/version \"$version\"/" Formula/take.rb
git config user.name github-actions
git config user.email [email protected]
git add Formula/take.rb
git commit -m "chore: update take to $version"
git push