Fix save db #4
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Attention: | |
# - Need goto [Settings -> Actions -> general] | |
# - Set [workflow permissions] to "Read and write permissions" | |
name: "🚀 Release" | |
# on events | |
on: | |
push: | |
tags: ["v*"] | |
# jobs | |
jobs: | |
# generate build cross-platform build files | |
release: | |
name: Generate cross-platform builds | |
strategy: | |
matrix: | |
go_version: [1.18.x] | |
runs-on: ubuntu-latest | |
steps: | |
# step 1: checkout repository code | |
- name: Checkout the repository | |
uses: actions/checkout@v3 | |
# step 2: setup build envirement | |
- uses: actions/setup-go@v3 | |
with: | |
go-version: ${{ matrix.go_version }} | |
- uses: actions/setup-node@v2 | |
with: | |
node-version: "16" | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
# step 3: set workflow variables | |
- name: Initialize workflow variables | |
id: vars | |
run: | | |
echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_OUTPUT | |
echo "BUILDDATE=$(date '+%F-%T')" >> $GITHUB_OUTPUT | |
echo "COMMIT=$(git rev-parse --verify HEAD)" >> $GITHUB_OUTPUT | |
echo "APP_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_OUTPUT | |
echo "REPO=$(echo 'github.com/${{ github.repository }}')" >> $GITHUB_OUTPUT | |
echo "REPO_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_OUTPUT | |
if [ ! -z $DOCKER_TOKEN ]; then echo "HAS_DOCKER_TOKEN=${HAS_DOCKER_TOKEN}" >> $GITHUB_OUTPUT; fi | |
env: | |
DOCKER_TOKEN: "${{ secrets.DOCKER_TOKEN }}" | |
# step 4: generate build files | |
- name: build frontend | |
run: cd ./view && npm install && npm run build | |
- name: Generate build files | |
uses: crazy-max/ghaction-xgo@v2 | |
with: | |
xgo_version: latest | |
go_version: ${{ matrix.go_version }} | |
dest: build | |
prefix: ${{steps.vars.outputs.APP_NAME}} | |
targets: linux/amd64 | |
v: true | |
x: false | |
ldflags: -w -s -X ${{steps.vars.outputs.REPO}}/internal/version.Version=${{steps.vars.outputs.VERSION}} -X ${{steps.vars.outputs.REPO}}/internal/version.BuildDate=${{steps.vars.outputs.BUILDDATE}} -X ${{steps.vars.outputs.REPO}}/internal/version.Commit=${{steps.vars.outputs.COMMIT}} -X ${{steps.vars.outputs.REPO}}/internal/mode.Mode=production | |
# step 5: compress build files | |
- name: Compress build files | |
run: cd ./build && for i in *; do tar -czf $i.tar.gz $i; done && cd .. | |
# step 6: Upload binary to GitHub Release | |
- name: Upload binary to GitHub Release | |
uses: softprops/action-gh-release@v1 | |
if: "startsWith(github.ref, 'refs/tags/')" | |
with: | |
files: | | |
./build/*.tar.gz | |
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') }} | |
generate_release_notes: true | |
fail_on_unmatched_files: true | |
# step 7.1: push to DockerHub | |
- name: Login to DockerHub | |
if: ${{ steps.vars.outputs.HAS_DOCKER_TOKEN == 'true' }} | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_TOKEN }} | |
- name: Build and push Docker images to DockerHub | |
if: ${{ steps.vars.outputs.HAS_DOCKER_TOKEN == 'true' }} | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
push: true | |
platforms: linux/amd64 | |
tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:latest | |
build-args: | | |
APP_NAME=${{steps.vars.outputs.APP_NAME}} | |
VERSION=${{steps.vars.outputs.VERSION}} | |
BUILDDATE=${{steps.vars.outputs.BUILDDATE}} | |
COMMIT=${{steps.vars.outputs.COMMIT}} | |
# step 7.2: push to GitHub Container Registry | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ghcr.io/${{ github.repository }} | |
- name: Build and push Docker images to ghci | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
platforms: linux/amd64 | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: | | |
APP_NAME=${{steps.vars.outputs.APP_NAME}} | |
VERSION=${{steps.vars.outputs.VERSION}} | |
BUILDDATE=${{steps.vars.outputs.BUILDDATE}} | |
COMMIT=${{steps.vars.outputs.COMMIT}} |