Skip to content

Daily Release

Daily Release #187

Workflow file for this run

name: Daily Release
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
jobs:
release:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for changes
run: |
TAG_COUNT=$(git tag | wc -l)
if [ "$TAG_COUNT" -gt 0 ]; then
LAST_TAG=$(git describe --tags --abbrev=0)
else
echo "No tags found, assuming changes."
LAST_TAG=""
fi
if [ -n "$LAST_TAG" ]; then
CHANGES=$(git diff --name-only $LAST_TAG..HEAD)
if [ -z "$CHANGES" ]; then
echo "No changes since last tag."
echo "CHANGES_EXIST=false" >> $GITHUB_ENV
else
echo "Changes detected."
echo "CHANGES_EXIST=true" >> $GITHUB_ENV
fi
else
echo "Assuming changes due to no tags."
echo "CHANGES_EXIST=true" >> $GITHUB_ENV
fi
- name: Log in to Docker Hub
if: env.CHANGES_EXIST == 'true'
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Log in to GitHub Packages
if: env.CHANGES_EXIST == 'true'
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20
with:
username: ${{ secrets.GH_PACKAGES_USERNAME }}
password: ${{ secrets.GH_PACKAGES_PASSWORD }}
registry: ghcr.io
- name: Set up Go
if: env.CHANGES_EXIST == 'true'
uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Set up Node.js
if: env.CHANGES_EXIST == 'true'
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: "npm"
- name: Install C dependencies
if: env.CHANGES_EXIST == 'true'
run: >
sudo apt-get update && sudo apt-get install -y gcc libc6-dev
mingw-w64 gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu
- name: Create empty file in webroot
if: env.CHANGES_EXIST == 'true'
run: mkdir -p webroot && touch webroot/empty
- name: Install go dependencies
if: env.CHANGES_EXIST == 'true'
run: go install
- name: Install npm dependencies
if: env.CHANGES_EXIST == 'true'
run: npm ci
- name: Run generate
if: env.CHANGES_EXIST == 'true'
run: npm run generate
- name: Run tests
if: env.CHANGES_EXIST == 'true'
run: npm run test
- name: Build project
if: env.CHANGES_EXIST == 'true'
run: npm run build
- name: Build application
if: env.CHANGES_EXIST == 'true'
run: |
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC=gcc go build -tags 'netgo sqlite_stat4 sqlite_fts5 sqlite_math_functions sqlite_vtable' -o res-mon-linux-amd64
GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc go build -tags 'netgo sqlite_stat4 sqlite_fts5 sqlite_math_functions sqlite_vtable' -o res-mon-linux-arm64
GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=1 CC=arm-linux-gnueabihf-gcc go build -tags 'netgo sqlite_stat4 sqlite_fts5 sqlite_math_functions sqlite_vtable' -o res-mon-linux-armv7
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build -tags 'netgo sqlite_stat4 sqlite_fts5 sqlite_math_functions sqlite_vtable' -o res-mon-windows-amd64.exe
- name: Set up Docker Buildx
if: env.CHANGES_EXIST == 'true'
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
if: env.CHANGES_EXIST == 'true'
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Calculate version
if: env.CHANGES_EXIST == 'true'
run: |
YEAR=$(date +"%Y")
MONTH=$(date +"%m")
COUNT=$(git tag | grep "^v$YEAR\.$MONTH\." | wc -l | xargs)
NEW_TAG="v$YEAR.$MONTH.$COUNT"
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV
echo "DOCKER_TAG=yertools/res-mon:$NEW_TAG" >> $GITHUB_ENV
echo "PACKAGE_TAG=ghcr.io/res-mon/res-mon:$NEW_TAG" >> $GITHUB_ENV
echo "New version: $NEW_TAG"
- name: Build and push Docker image
if: env.CHANGES_EXIST == 'true'
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/Release.Dockerfile
push: true
tags: "${{ env.DOCKER_TAG }},\
${{ env.PACKAGE_TAG }}"
builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Set up GitHub CLI
if: env.CHANGES_EXIST == 'true'
run: gh auth setup-git
env:
GH_TOKEN: ${{ secrets.DAILY_RELEASE_ACCESS_TOKEN }}
- name: Create release
if: env.CHANGES_EXIST == 'true'
run: >
gh release create $NEW_TAG res-mon-linux-amd64
res-mon-linux-arm64 res-mon-linux-armv7
res-mon-windows-amd64.exe --generate-notes
env:
GH_TOKEN: ${{ secrets.DAILY_RELEASE_ACCESS_TOKEN }}