glider/.github/workflows/build.yml

104 lines
2.8 KiB
YAML
Raw Normal View History

name: Build
2022-01-31 11:51:32 +08:00
on:
push:
branches:
2024-08-05 23:31:19 +08:00
- "dev"
2022-01-31 11:51:32 +08:00
tags:
2024-08-05 23:31:19 +08:00
- "*"
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
2023-11-28 18:26:33 +08:00
uses: actions/checkout@v4
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
2022-01-26 22:31:56 +08:00
2020-04-03 22:54:13 +08:00
- name: Set up Go
uses: actions/setup-go@v5
2020-04-03 22:54:13 +08:00
with:
2022-02-14 12:12:37 +08:00
check-latest: true
2024-08-05 23:31:19 +08:00
go-version-file: "go.mod"
2022-12-19 00:01:14 +08:00
cache: true
2022-01-27 17:15:04 +08:00
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
2024-08-05 23:31:19 +08:00
uses: goreleaser/goreleaser-action@v6
2022-01-26 22:31:56 +08:00
if: "!startsWith(github.ref, 'refs/tags/')"
with:
2023-03-13 20:42:36 +08:00
args: build --snapshot --clean
2022-01-26 22:31:56 +08:00
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2022-01-26 23:40:49 +08:00
2024-08-05 23:31:19 +08:00
- name: Upload Artifacts
uses: actions/upload-artifact@v4
2022-02-14 12:12:37 +08:00
if: "!startsWith(github.ref, 'refs/tags/')"
with:
2024-08-05 23:31:19 +08:00
name: ${{ env.APP_NAME }}-dev-${{ env.SHA_SHORT }}
2022-02-14 12:12:37 +08:00
path: |
./dist/default_linux_amd64_v1/${{ env.APP_NAME }}
2022-02-14 12:12:37 +08:00
./dist/default_linux_arm64/${{ env.APP_NAME }}
./dist/default_darwin_arm64/${{ env.APP_NAME }}
./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
2024-08-05 23:31:19 +08:00
uses: goreleaser/goreleaser-action@v6
2021-09-14 00:56:10 +08:00
if: startsWith(github.ref, 'refs/tags/')
with:
2023-03-13 20:42:36 +08:00
args: release --clean
2021-09-14 00:56:10 +08:00
env:
2022-01-31 11:51:32 +08:00
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Docker - Set up Buildx
id: buildx
2023-11-28 18:26:33 +08:00
uses: docker/setup-buildx-action@v3
2022-01-31 11:51:32 +08:00
- name: Docker - Login to DockerHub
2023-11-28 18:26:33 +08:00
uses: docker/login-action@v3
2022-01-31 11:51:32 +08:00
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker - Login to GHCR
2023-11-28 18:26:33 +08:00
uses: docker/login-action@v3
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
2023-11-28 18:26:33 +08:00
uses: docker/metadata-action@v5
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
2024-08-05 23:31:19 +08:00
uses: docker/build-push-action@v6
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 }}