ci: Refactor test timing summary in GitHub Actions workflow #19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
- name: Run tests | |
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")] | | |
group_by(.Package) | | |
map({ | |
Package: .[0].Package, | |
Elapsed: (map(.Elapsed) | add) | |
}) | | |
sort_by(-.Elapsed) | | |
.[0:10] | | |
.[] | | |
"\(.Package): \(.Elapsed)s" | |
' test-output.json | |
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 |