Skip to content

fix(ci): handle projects without go.sum in dependency workflow #50

fix(ci): handle projects without go.sum in dependency workflow

fix(ci): handle projects without go.sum in dependency workflow #50

Workflow file for this run

---
name: Build
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: "0 1 * * 6"
env:
CI: true
GO_VERSION: '1.20'
REGISTRY: ghcr.io
permissions:
contents: read
packages: write
jobs:
run-code-quality:
uses: ./.github/workflows/code-quality.yml
secrets: inherit
run-tests:
needs: [run-code-quality]
uses: ./.github/workflows/test.yml
secrets: inherit
permissions:
contents: read
pull-requests: write # Required for coverage report comments
build-alertmanager-discord:
needs: [run-tests]
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
packages: write
steps:
- name: ⏱️ Start timer
id: timer
run: echo "start_time=$(date +%s)" >> "$GITHUB_OUTPUT"
- name: 🏷️ Set lowercase image name
id: image
run: |
echo "IMAGE_NAME=$(echo "${{ github.repository }}" | tr "[:upper:]" "[:lower:]")" >> "$GITHUB_ENV"
- name: πŸ”€ Checkout repository
uses: actions/checkout@v4
with:
submodules: true
- name: 🧹 Free disk space
run: |
echo "πŸ“Š Disk space before cleanup:"
df -h
echo "πŸ—‘οΈ Removing unnecessary software..."
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
echo "🧹 Cleaning Docker..."
docker system prune -af --volumes || true
echo "πŸ“Š Disk space after cleanup:"
df -h
- name: πŸ”’ Log in to the GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: πŸ“Š Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
type=schedule,pattern={{date 'YYYYMMDD'}}
- name: πŸ”§ Set up QEMU
uses: docker/setup-qemu-action@v3
- name: πŸ”§ Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6
driver-opts: |
image=moby/buildkit:latest
network=host
- name: πŸš€ Build and push Docker image to GitHub Container Registry
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
provenance: true
sbom: true
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
BUILDKIT_INLINE_CACHE=1
GO_VERSION=${{ env.GO_VERSION }}
BUILD_DATE=${{ github.event.head_commit.timestamp || github.event.repository.updated_at }}
BUILD_VERSION=${{ steps.meta.outputs.version }}
VCS_REF=${{ github.sha }}
- name: 🧹 Cleanup build artifacts
if: always()
run: |
echo "πŸ—‘οΈ Pruning Docker build cache..."
docker buildx prune -f --filter until=1h || true
docker system prune -f --filter until=1h || true
echo "πŸ“Š Remaining disk space:"
df -h
- name: πŸ“Š Collect metrics
if: always()
id: metrics
run: |
end_time=$(date +%s)
duration=$((end_time - ${{ steps.timer.outputs.start_time }}))
echo "duration=${duration}" >> "$GITHUB_OUTPUT"
echo "::notice title=Build Metrics::Duration: ${duration}s, Platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6"
- name: πŸ“’ Send notification to Discord
uses: sarisia/actions-status-discord@b8381b25576cb341b2af39926ab42c5056cc44ed # v1.15.5
if: always()
with:
title: alertmanager-discord
description: |
Build duration: ${{ steps.metrics.outputs.duration || 'N/A' }}s
Platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6
Version: ${{ steps.meta.outputs.version }}
webhook: ${{ secrets.DISCORD_WEBHOOK }}