Skip to content

Daily Build

Daily Build #21

Workflow file for this run

name: Daily Build
on:
schedule:
- cron: '0 3 * * *'
push:
branches:
- main
- master
workflow_dispatch:
env:
PROJECTNAME: search
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 'stable'
- name: Set build info
run: |
echo "VERSION=$(date -u +"%Y%m%d%H%M%S")" >> $GITHUB_ENV
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
- name: Build server
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
LDFLAGS="-s -w -X 'github.com/apimgr/search/src/config.Version=${{ env.VERSION }}' -X 'github.com/apimgr/search/src/config.CommitID=${{ env.COMMIT_ID }}' -X 'github.com/apimgr/search/src/config.BuildDate=${{ env.BUILD_DATE }}'"
go build -ldflags "${LDFLAGS}" -o ${{ env.PROJECTNAME }}-${{ matrix.goos }}-${{ matrix.goarch }} ./src
- name: Build CLI
if: hashFiles('src/client/') != ''
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
LDFLAGS="-s -w -X 'github.com/apimgr/search/src/client/cmd.ProjectName=${{ env.PROJECTNAME }}' -X 'github.com/apimgr/search/src/client/cmd.Version=${{ env.VERSION }}' -X 'github.com/apimgr/search/src/client/cmd.CommitID=${{ env.COMMIT_ID }}' -X 'github.com/apimgr/search/src/client/cmd.BuildDate=${{ env.BUILD_DATE }}' -X 'github.com/apimgr/search/src/client/api.ProjectName=${{ env.PROJECTNAME }}' -X 'github.com/apimgr/search/src/client/api.Version=${{ env.VERSION }}'"
go build -ldflags "${LDFLAGS}" -o ${{ env.PROJECTNAME }}-${{ matrix.goos }}-${{ matrix.goarch }}-cli ./src/client
- name: Upload server artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.PROJECTNAME }}-${{ matrix.goos }}-${{ matrix.goarch }}
path: ${{ env.PROJECTNAME }}-${{ matrix.goos }}-${{ matrix.goarch }}
- name: Upload CLI artifact
if: hashFiles('src/client/') != ''
uses: actions/upload-artifact@v4
with:
name: ${{ env.PROJECTNAME }}-${{ matrix.goos }}-${{ matrix.goarch }}-cli
path: ${{ env.PROJECTNAME }}-${{ matrix.goos }}-${{ matrix.goarch }}-cli
release:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: binaries
merge-multiple: true
- name: Set version
run: echo "VERSION=$(date -u +"%Y%m%d%H%M%S")" >> $GITHUB_ENV
- 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@v1
with:
tag_name: daily
name: "Daily Build ${{ env.VERSION }}"
files: binaries/*
prerelease: true
body: "Daily build: ${{ env.VERSION }}"