fix(ci): handle projects without go.sum in dependency workflow #50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| 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 }} |