182 lines
4.3 KiB
YAML
182 lines
4.3 KiB
YAML
name: Build
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- '*'
|
|
tags:
|
|
- 'v*'
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
# dependencies
|
|
- name: goreleaser
|
|
uses: goreleaser/goreleaser-action@v3
|
|
with:
|
|
install-only: true
|
|
version: 1.7.0
|
|
|
|
- name: goreleaser version
|
|
run: goreleaser -v
|
|
|
|
- name: task
|
|
uses: arduino/setup-task@v1
|
|
|
|
- name: task info
|
|
run: task --version
|
|
|
|
- name: qemu
|
|
uses: docker/setup-qemu-action@v2
|
|
|
|
- name: buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
|
|
# checkout
|
|
- name: checkout
|
|
uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
# setup go
|
|
- name: go
|
|
uses: actions/setup-go@v3
|
|
with:
|
|
go-version: 1.19
|
|
|
|
- name: go info
|
|
run: |
|
|
go version
|
|
go env
|
|
|
|
# cache
|
|
- name: cache-go
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: |
|
|
~/.cache/go-build
|
|
~/go/pkg/mod
|
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-go-cache-mod
|
|
|
|
- name: cache-task
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: .task/**/*
|
|
key: ${{ runner.os }}-go-task
|
|
|
|
# vendor
|
|
- name: vendor
|
|
run: |
|
|
task vendor
|
|
|
|
# test
|
|
- name: tests
|
|
run: |
|
|
task test
|
|
|
|
# git status
|
|
- name: git status
|
|
run: git status
|
|
|
|
# build
|
|
- name: build
|
|
if: startsWith(github.ref, 'refs/tags/') == false
|
|
run: |
|
|
task snapshot
|
|
|
|
# publish
|
|
- name: publish
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
GITHUB_REF: ${{ github.ref }}
|
|
run: |
|
|
task publish
|
|
|
|
# artifacts
|
|
- name: artifact_linux
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: build_linux
|
|
path: dist/*linux*
|
|
|
|
- name: artifact_darwin
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: build_darwin
|
|
path: dist/*darwin*
|
|
|
|
- name: artifact_windows
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: build_windows
|
|
path: dist/*windows*
|
|
|
|
# docker login
|
|
- name: docker login
|
|
env:
|
|
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
|
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
|
run: |
|
|
echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin
|
|
|
|
# docker build (latest & tag)
|
|
- name: release tag
|
|
if: startsWith(github.ref, 'refs/tags/') == true
|
|
uses: little-core-labs/get-git-tag@v3.0.2
|
|
id: releasetag
|
|
with:
|
|
tagRegex: "v?(.+)"
|
|
|
|
- name: docker - build release
|
|
if: startsWith(github.ref, 'refs/tags/') == true
|
|
uses: docker/build-push-action@v3
|
|
with:
|
|
context: .
|
|
file: ./docker/Dockerfile
|
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
|
pull: true
|
|
push: true
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
tags: |
|
|
cloudb0x/nabarr:${{ steps.releasetag.outputs.tag }}
|
|
cloudb0x/nabarr:latest
|
|
|
|
# docker build (branch)
|
|
- name: branch name
|
|
if: startsWith(github.ref, 'refs/tags/') == false
|
|
id: branch-name
|
|
uses: tj-actions/branch-names@v6
|
|
|
|
- name: docker tag
|
|
if: startsWith(github.ref, 'refs/tags/') == false
|
|
uses: frabert/replace-string-action@v2.3
|
|
id: dockertag
|
|
with:
|
|
pattern: '[:\.\/]+'
|
|
string: "${{ steps.branch-name.outputs.current_branch }}"
|
|
replace-with: '-'
|
|
flags: 'g'
|
|
|
|
- name: docker - build branch
|
|
if: startsWith(github.ref, 'refs/tags/') == false
|
|
uses: docker/build-push-action@v3
|
|
with:
|
|
context: .
|
|
file: ./docker/Dockerfile
|
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
|
pull: true
|
|
push: true
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
tags: |
|
|
cloudb0x/nabarr:${{ steps.dockertag.outputs.replaced }}
|
|
|
|
# cleanup
|
|
- name: cleanup
|
|
run: |
|
|
rm -f ${HOME}/.docker/config.json |