Skip to content

🚀 Release Nightly #47

🚀 Release Nightly

🚀 Release Nightly #47

name: "🚀 Release Nightly"
# on events
on:
# schedule:
# - cron: '0 0 * * *' # runs daily at 00:00
workflow_dispatch:
# push:
# branches: [main, master, release/v*, tvos17]
# jobs
jobs:
check:
name: Check has new commits today
permissions:
contents: write
runs-on: ubuntu-latest
outputs:
new_commit_count: ${{steps.commit_check.outputs.new_commit_count}}
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Check for new commits
id: commit_check
run: echo "new_commit_count=$(git log --oneline --since '24 hours ago' | wc -l)" >> $GITHUB_OUTPUT
build:
name: Generate cross-platform builds
if: ${{needs.check.outputs.new_commit_count > 0}}
needs: [check]
permissions:
contents: write
strategy:
matrix:
go_version: [1.21.x]
runs-on: ubuntu-latest
outputs:
VERSION: ${{steps.vars.outputs.VERSION}}
BUILDDATE: ${{steps.vars.outputs.BUILDDATE}}
COMMIT: ${{steps.vars.outputs.COMMIT}}
APP_NAME: ${{steps.vars.outputs.APP_NAME}}
PUSH_DOCKERHUB: ${{steps.vars.outputs.PUSH_DOCKERHUB}}
steps:
# step 1: checkout repository code
- name: Checkout the repository
uses: actions/checkout@v4
with:
fetch-depth: 0
# step 2: setup build envirement
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go_version }}
- uses: actions/setup-node@v4
with:
node-version: "20"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# step 3: set workflow variables
- id: metadata
uses: ahmadnassri/action-metadata@v2
- name: Initialize workflow environments variables
id: vars
run: |
echo "VERSION=${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "BUILDDATE=$(date '+%F-%T')" >> $GITHUB_OUTPUT
echo "COMMIT=$(git rev-parse --verify HEAD)" >> $GITHUB_OUTPUT
echo "APP_NAME=${{ steps.metadata.outputs.repository_name }}" >> $GITHUB_OUTPUT
echo "REPO=$(echo 'github.com/${{ github.repository }}')" >> $GITHUB_OUTPUT
echo "BRANCH=${{ steps.metadata.outputs.repository_default_branch }}" >> $GITHUB_OUTPUT
if [ ! -z $DOCKER_TOKEN ]; then echo "PUSH_DOCKERHUB=1" >> $GITHUB_OUTPUT; fi
env:
DOCKER_TOKEN: "${{ secrets.DOCKER_TOKEN }}"
# step 4: generate build files
- name: build frontend
run: cd ./web/static && npm install && npm run build
- name: Generate build files
uses: crazy-max/ghaction-xgo@v2
env:
CGO_ENABLED: "0"
with:
xgo_version: latest
go_version: ${{ matrix.go_version }}
dest: build
prefix: ${{steps.vars.outputs.APP_NAME}}
targets: linux/amd64,linux/arm64
v: true
x: false
ldflags: -w -s -X ${{steps.vars.outputs.REPO}}/internal/app/build.Version=${{steps.vars.outputs.VERSION}} -X ${{steps.vars.outputs.REPO}}/internal/app/build.BuildDate=${{steps.vars.outputs.BUILDDATE}} -X ${{steps.vars.outputs.REPO}}/internal/app/build.Commit=${{steps.vars.outputs.COMMIT}} -X ${{steps.vars.outputs.REPO}}/internal/app/build.Mode=production
# step 5: Upload binary to artifact
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{steps.vars.outputs.APP_NAME}}
path: build
retention-days: 1
dockerhub:
name: Push to DockerHub
if: ${{needs.build.outputs.PUSH_DOCKERHUB}}
needs: [build]
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{needs.build.outputs.APP_NAME}}
path: build
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}
tags: |
type=ref,event=branch
type=raw,value=nightly
- name: Build and push Docker images to DockerHub
uses: docker/build-push-action@v5
with:
context: .
push: true
provenance: false
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
APP_NAME=${{needs.build.outputs.APP_NAME}}
VERSION=${{needs.build.outputs.VERSION}}
BUILDDATE=${{needs.build.outputs.BUILDDATE}}
COMMIT=${{needs.build.outputs.COMMIT}}
ghcr:
name: Push to GitHub Container Registry
needs: [build]
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{needs.build.outputs.APP_NAME}}
path: build
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- 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@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=raw,value=nightly
- name: Build and push Docker images to ghci
uses: docker/build-push-action@v5
with:
context: .
push: true
provenance: false
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
APP_NAME=${{needs.build.outputs.APP_NAME}}
VERSION=${{needs.build.outputs.VERSION}}
BUILDDATE=${{needs.build.outputs.BUILDDATE}}
COMMIT=${{needs.build.outputs.COMMIT}}