Skip to content

Commit

Permalink
feat: composite workflow to create latest release
Browse files Browse the repository at this point in the history
  • Loading branch information
cybardev committed Mar 13, 2024
1 parent db48a2a commit c218661
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build

on:
# Allows running this workflow from other workflows
workflow_call:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
os: [linux, darwin, windows]
arch: [amd64, arm64]
steps:
- name: Checkout
uses: actions/checkout@v3

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

- name: Build for ${{ matrix.os }} (${{ matrix.arch }})
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
run: |
[ "$GOOS" = "windows" ] && EXT=".exe" || EXT=""
go build -C cmd/ytgo -o "../../bin/ytgo-${GOOS}-${GOARCH}${EXT}"
- name: Upload ${{ matrix.os }}-${{ matrix.arch }} binary
uses: actions/upload-artifact@v2
with:
name: ytgo-${{ matrix.os }}-${{ matrix.arch }}
path: |
bin/ytgo-${{ matrix.os }}-${{ matrix.arch }}*
41 changes: 41 additions & 0 deletions .github/workflows/latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This workflow will build a golang project and create a release with generated binaries

# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: CI/CD (latest)

on:
push:
branches: ["main"]

# Allows running this workflow from other workflows
workflow_call:

# Allows running this workflow from GitHub Actions tab
workflow_dispatch:

jobs:
test:
uses: ./.github/workflows/test.yml

build:
needs: test
uses: ./.github/workflows/build.yml

release:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download binaries
uses: actions/download-artifact@v2
with:
path: |
bin/
- name: Create Release with latest tag
uses: "marvinpinto/action-automatic-releases@latest"
with:
automatic_release_tag: latest
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
files: |
bin/ytgo-*/ytgo-*
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Run Tests

on:
# Allows running this workflow from other workflows
workflow_call:

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

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

- name: Test build
run: go build -C cmd/ytgo -o "../../bin/ytgo"

- name: Run tests
run: go test -v -coverprofile=coverage.out ./cmd/ytgo

- name: Report Coverage
uses: shogo82148/actions-goveralls@v1
with:
github-token: ${{ secrets.COVERALLS_REPO_TOKEN }}
path-to-profile: coverage.out

0 comments on commit c218661

Please sign in to comment.