glider/.github/workflows/build.yml

137 lines
3.9 KiB
YAML
Raw Normal View History

name: Build
2022-01-31 11:51:32 +08:00
on:
push:
branches:
- 'dev'
tags:
- '*'
2022-03-11 13:10:59 +08:00
pull_request:
2022-01-31 11:51:32 +08:00
env:
2022-02-14 12:12:37 +08:00
APP_NAME: glider
2022-01-31 11:51:32 +08:00
DOCKERHUB_REPO: nadoo/glider
GHCR_REPO: ghcr.io/nadoo/glider
PLATFORMS: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/riscv64
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
2020-04-03 22:54:13 +08:00
- name: Checkout
2022-03-11 13:10:59 +08:00
uses: actions/checkout@v3
2021-09-14 00:56:10 +08:00
with:
fetch-depth: 0
2022-01-26 22:31:56 +08:00
2022-02-14 12:12:37 +08:00
- name: Set Vars
2021-09-14 00:56:10 +08:00
run: |
2022-02-14 12:12:37 +08:00
echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "GO_MOD_VERSION=$(grep -P "go \d+\." go.mod | cut -d " " -f2)" >> $GITHUB_ENV
2022-01-26 22:31:56 +08:00
2020-04-03 22:54:13 +08:00
- name: Set up Go
2022-03-11 13:10:59 +08:00
uses: actions/setup-go@v3
2020-04-03 22:54:13 +08:00
with:
2022-02-14 12:12:37 +08:00
check-latest: true
2022-03-16 12:01:09 +08:00
go-version: ${{ env.GO_MOD_VERSION}}
2022-01-26 22:31:56 +08:00
2022-01-27 17:15:04 +08:00
- name: Set up Cache
uses: actions/cache@v3
2022-01-27 17:15:04 +08:00
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
2021-09-14 00:56:10 +08:00
- name: Test
run: go test -v .
2022-01-26 22:31:56 +08:00
2020-04-03 22:54:13 +08:00
- name: Build
2022-01-26 22:31:56 +08:00
uses: goreleaser/goreleaser-action@v2
if: "!startsWith(github.ref, 'refs/tags/')"
with:
version: latest
args: build --snapshot --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2022-01-26 23:40:49 +08:00
2022-02-14 12:12:37 +08:00
- name: Upload Artifact - Linux amd64
2022-03-11 13:10:59 +08:00
uses: actions/upload-artifact@v3
2022-02-14 12:12:37 +08:00
if: "!startsWith(github.ref, 'refs/tags/')"
with:
name: ${{ env.APP_NAME }}-dev-${{ env.SHA_SHORT }}-linux-amd64
path: |
./dist/default_linux_amd64_v1/${{ env.APP_NAME }}
2022-02-14 12:12:37 +08:00
- name: Upload Artifact - Linux arm64
2022-03-11 13:10:59 +08:00
uses: actions/upload-artifact@v3
2022-02-14 12:12:37 +08:00
if: "!startsWith(github.ref, 'refs/tags/')"
with:
name: ${{ env.APP_NAME }}-dev-${{ env.SHA_SHORT }}-linux-arm64
path: |
./dist/default_linux_arm64/${{ env.APP_NAME }}
- name: Upload Artifact - macOS arm64
2022-03-11 13:10:59 +08:00
uses: actions/upload-artifact@v3
2022-02-14 12:12:37 +08:00
if: "!startsWith(github.ref, 'refs/tags/')"
with:
name: ${{ env.APP_NAME }}-dev-${{ env.SHA_SHORT }}-macos-arm64
path: |
./dist/default_darwin_arm64/${{ env.APP_NAME }}
- name: Upload Artifact - Windows amd64
2022-03-11 13:10:59 +08:00
uses: actions/upload-artifact@v3
2022-02-14 12:12:37 +08:00
if: "!startsWith(github.ref, 'refs/tags/')"
with:
name: ${{ env.APP_NAME }}-dev-${{ env.SHA_SHORT }}-windows-amd64
path: |
./dist/default_windows_amd64_v1/${{ env.APP_NAME }}.exe
2022-02-14 12:12:37 +08:00
2022-01-26 23:40:49 +08:00
- name: Release
2021-09-14 00:56:10 +08:00
uses: goreleaser/goreleaser-action@v2
if: startsWith(github.ref, 'refs/tags/')
with:
version: latest
args: release --rm-dist
env:
2022-01-31 11:51:32 +08:00
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Docker - Set up Buildx
id: buildx
uses: docker/setup-buildx-action@v2
2022-01-31 11:51:32 +08:00
- name: Docker - Login to DockerHub
uses: docker/login-action@v2
2022-01-31 11:51:32 +08:00
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker - Login to GHCR
uses: docker/login-action@v2
2022-01-31 11:51:32 +08:00
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker - Docker meta
id: meta
uses: docker/metadata-action@v4
2022-01-31 11:51:32 +08:00
with:
images: |
${{ env.DOCKERHUB_REPO }}
${{ env.GHCR_REPO }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
2022-03-11 13:10:59 +08:00
2022-01-31 11:51:32 +08:00
- name: Docker - Build and push
uses: docker/build-push-action@v3
2022-01-31 11:51:32 +08:00
with:
context: .
file: .Dockerfile
platforms: ${{ env.PLATFORMS }}
2022-03-11 13:10:59 +08:00
push: ${{ github.event_name != 'pull_request' }}
2022-01-31 11:51:32 +08:00
tags: ${{ steps.meta.outputs.tags }}