Skip to content

Daily Build

Daily Build #27

Workflow file for this run

name: Daily Build
on:
schedule:
- cron: '0 3 * * *'
push:
branches:
- main
- master
workflow_dispatch:
concurrency:
group: daily-${{ github.ref }}
cancel-in-progress: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/devel' || github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/beta' }}
permissions:
contents: write
env:
PROJECTNAME: countries
jobs:
build:
runs-on: ubuntu-latest
container: golang:alpine
strategy:
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
- goos: windows
goarch: amd64
ext: .exe
- goos: windows
goarch: arm64
ext: .exe
- goos: freebsd
goarch: amd64
- goos: freebsd
goarch: arm64
steps:
- uses: actions/checkout@v6
- name: Set build info
run: |
if [ -f release.txt ]; then
echo "VERSION=$(cat release.txt)" >> $GITHUB_ENV
else
echo "VERSION=$(date -u +"%Y%m%d%H%M%S")" >> $GITHUB_ENV
fi
echo "COMMIT_ID=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "BUILD_DATE=$(date +"%a %b %d, %Y at %H:%M:%S %Z")" >> $GITHUB_ENV
if [ -f site.txt ]; then
echo "OFFICIALSITE=$(cat site.txt)" >> $GITHUB_ENV
else
echo "OFFICIALSITE=${{ secrets.OFFICIALSITE }}" >> $GITHUB_ENV
fi
- name: Build server
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
LDFLAGS="-s -w -X 'main.Version=${{ env.VERSION }}' -X 'main.CommitID=${{ env.COMMIT_ID }}' -X 'main.BuildDate=${{ env.BUILD_DATE }}' -X 'main.OfficialSite=${{ env.OFFICIALSITE }}'"
go build -ldflags "${LDFLAGS}" -o ${{ env.PROJECTNAME }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.ext }} ./src
- name: Build CLI
if: hashFiles('src/client/') != ''
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
LDFLAGS="-s -w -X 'main.Version=${{ env.VERSION }}' -X 'main.CommitID=${{ env.COMMIT_ID }}' -X 'main.BuildDate=${{ env.BUILD_DATE }}' -X 'main.OfficialSite=${{ env.OFFICIALSITE }}'"
go build -ldflags "${LDFLAGS}" -o ${{ env.PROJECTNAME }}-cli-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.ext }} ./src/client
- name: Upload server artifact
uses: actions/upload-artifact@v5
with:
name: ${{ env.PROJECTNAME }}-${{ matrix.goos }}-${{ matrix.goarch }}
path: ${{ env.PROJECTNAME }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.ext }}
- name: Upload CLI artifact
if: hashFiles('src/client/') != ''
uses: actions/upload-artifact@v5
with:
name: ${{ env.PROJECTNAME }}-cli-${{ matrix.goos }}-${{ matrix.goarch }}
path: ${{ env.PROJECTNAME }}-cli-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.ext }}
release:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6
- name: Download all artifacts
uses: actions/download-artifact@v5
with:
path: binaries
merge-multiple: true
- name: Set version
run: |
if [ -f release.txt ]; then
echo "VERSION=$(cat release.txt)" >> $GITHUB_ENV
else
echo "VERSION=$(date -u +"%Y%m%d%H%M%S")" >> $GITHUB_ENV
fi
- name: Create version.txt
run: echo "${{ env.VERSION }}" > binaries/version.txt
- name: Delete previous daily release
run: |
gh release delete daily --yes 2>/dev/null || true
git push origin :refs/tags/daily 2>/dev/null || true
env:
GH_TOKEN: ${{ github.token }}
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: daily
name: "Daily Build ${{ env.VERSION }}"
files: binaries/*
prerelease: true
body: "Daily build: ${{ env.VERSION }}"