glider/.github/workflows/build.yml

139 lines
4.0 KiB
YAML
Raw Normal View History

name: Build
2022-01-31 11:51:32 +08:00
on:
push:
branches:
- 'dev'
tags:
- '*'
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
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
2020-04-03 22:54:13 +08:00
- name: Checkout
uses: actions/checkout@v2
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_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
2021-02-06 00:26:58 +08:00
uses: actions/setup-go@v2
2020-04-03 22:54:13 +08:00
with:
2022-02-14 12:12:37 +08:00
stable: false
check-latest: true
go-version: '1.18.0-beta2'
2022-01-26 23:40:49 +08:00
# go-version: ${{ env.GO_VERSION}}
2022-01-26 22:31:56 +08:00
2022-01-27 17:15:04 +08:00
- name: Set up Cache
uses: actions/cache@v2
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
uses: actions/upload-artifact@v2
if: "!startsWith(github.ref, 'refs/tags/')"
with:
name: ${{ env.APP_NAME }}-dev-${{ env.SHA_SHORT }}-linux-amd64
path: |
./dist/default_linux_amd64/${{ env.APP_NAME }}
- name: Upload Artifact - Linux arm64
uses: actions/upload-artifact@v2
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
uses: actions/upload-artifact@v2
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
uses: actions/upload-artifact@v2
if: "!startsWith(github.ref, 'refs/tags/')"
with:
name: ${{ env.APP_NAME }}-dev-${{ env.SHA_SHORT }}-windows-amd64
path: |
./dist/default_windows_amd64/${{ env.APP_NAME }}.exe
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@v1
- name: Docker - Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker - Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker - Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: |
${{ env.DOCKERHUB_REPO }}
${{ env.GHCR_REPO }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Docker - Build and push
uses: docker/build-push-action@v2
with:
context: .
file: .Dockerfile
platforms: ${{ env.PLATFORMS }}
push: true
tags: ${{ steps.meta.outputs.tags }}