Repository navigation
ci: add non-blocking gitleaks secret scan #374
Workflow file for this run
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 and Test | |
| on: | |
| push: | |
| branches: | |
| - '**' | |
| pull_request: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| checks: write | |
| pull-requests: write | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
| cancel-in-progress: true | |
| jobs: | |
| version: | |
| name: Resolve version | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.ver.outputs.version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Resolve version from git | |
| id: ver | |
| run: | | |
| set -euo pipefail | |
| v=$(git describe --tags --always --dirty) | |
| echo "version=$v" >> "$GITHUB_OUTPUT" | |
| echo "Resolved version: $v" | |
| build: | |
| name: Build smartrouter (${{ matrix.targetos }}-${{ matrix.arch }}) | |
| needs: [version] | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| targetos: [linux, darwin] | |
| arch: [amd64, arm64] | |
| env: | |
| CGO_ENABLED: "0" | |
| GOOS: ${{ matrix.targetos }} | |
| GOARCH: ${{ matrix.arch }} | |
| GOAMD64: v3 | |
| GOARM64: v8.2 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| cache-dependency-path: go.sum | |
| - name: Download dependencies | |
| run: go mod download | |
| - name: Build smartrouter | |
| run: | | |
| GOWORK=off go build \ | |
| -mod=readonly \ | |
| -trimpath \ | |
| -ldflags "-X github.com/magma-Devs/smart-router/version.Version=${{ needs.version.outputs.version }} -X github.com/magma-Devs/smart-router/version.Commit=${{ github.sha }} -w -s" \ | |
| -o out/smartrouter ./cmd/smartrouter | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: smartrouter-${{ matrix.targetos }}-${{ matrix.arch }} | |
| path: out/smartrouter | |
| build_docker: | |
| name: Build Docker image | |
| if: github.event_name != 'pull_request' | |
| needs: [version, build] | |
| permissions: | |
| contents: read | |
| packages: write | |
| runs-on: ubuntu-latest | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: magma-devs/smart-router | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Download linux/amd64 binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: smartrouter-linux-amd64 | |
| path: artifacts/linux/amd64 | |
| - name: Download linux/arm64 binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: smartrouter-linux-arm64 | |
| path: artifacts/linux/arm64 | |
| - name: Make binaries executable | |
| run: chmod +x artifacts/linux/amd64/smartrouter artifacts/linux/arm64/smartrouter | |
| - name: Plan tags | |
| id: plan | |
| env: | |
| VERSION: ${{ needs.version.outputs.version }} | |
| run: | | |
| set -euo pipefail | |
| push=false | |
| is_main=false | |
| tag="" | |
| if [ "${{ github.event_name }}" = "push" ]; then | |
| ref="${GITHUB_REF#refs/heads/}" | |
| if [ "$ref" = "main" ]; then | |
| push=true; is_main=true; tag="$VERSION" | |
| else | |
| # OCI tags must be lowercase and free of '/'; sanitize the branch name | |
| slug=$(echo "$ref" | tr '[:upper:]' '[:lower:]' | sed 's|[^a-z0-9._-]|-|g') | |
| push=true; tag="${slug}-${VERSION}" | |
| fi | |
| fi | |
| echo "push=$push" >> "$GITHUB_OUTPUT" | |
| echo "is_main=$is_main" >> "$GITHUB_OUTPUT" | |
| echo "tag=$tag" >> "$GITHUB_OUTPUT" | |
| if [ "$push" = "true" ]; then | |
| base="${REGISTRY}/${IMAGE_NAME}" | |
| tags=("${base}:${tag}" "${base}:${tag}-${GITHUB_SHA}") | |
| # Dev pushes from main get a :main floating tag — `:latest` is | |
| # reserved for the release pipeline (final tagged versions only, | |
| # see .goreleaser.yaml dockers / docker_manifests blocks). | |
| if [ "$is_main" = "true" ]; then | |
| tags+=("${base}:main") | |
| fi | |
| { | |
| echo "tags<<EOF" | |
| printf '%s\n' "${tags[@]}" | |
| echo "EOF" | |
| } >> "$GITHUB_OUTPUT" | |
| echo "::notice title=Image tags::$(IFS=' '; echo "${tags[*]}")" | |
| echo "Planned image tags:" | |
| printf ' - %s\n' "${tags[@]}" | |
| { | |
| echo "### Planned image tags" | |
| printf -- '- `%s`\n' "${tags[@]}" | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| else | |
| echo "Skipping push: event=${{ github.event_name }} ref=${GITHUB_REF}" | |
| fi | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log into registry ${{ env.REGISTRY }} | |
| if: steps.plan.outputs.push == 'true' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Ensure version is not already published (main only) | |
| if: steps.plan.outputs.is_main == 'true' | |
| env: | |
| IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.plan.outputs.tag }} | |
| run: | | |
| if docker buildx imagetools inspect "$IMAGE" >/dev/null 2>&1; then | |
| echo "::error::$IMAGE already exists. Tag a new release (git tag vX.Y.Z) before re-merging to main." | |
| exit 1 | |
| fi | |
| - name: Extract OCI labels | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| - name: Build and push | |
| id: build | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: Dockerfile.ci | |
| platforms: linux/amd64,linux/arm64 | |
| tags: ${{ steps.plan.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| push: ${{ steps.plan.outputs.push == 'true' }} | |
| - name: Report pushed image | |
| if: steps.plan.outputs.push == 'true' | |
| env: | |
| DIGEST: ${{ steps.build.outputs.digest }} | |
| TAGS: ${{ steps.plan.outputs.tags }} | |
| run: | | |
| echo "::notice title=Image published::digest=${DIGEST}" | |
| echo "Pushed image digest: ${DIGEST}" | |
| echo "Tags:" | |
| printf ' - %s\n' ${TAGS} | |
| { | |
| echo "### Pushed image" | |
| echo "" | |
| echo "**Digest:** \`${DIGEST}\`" | |
| echo "" | |
| echo "**Tags:**" | |
| for t in ${TAGS}; do echo "- \`${t}\`"; done | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| goreleaser_check: | |
| name: GoReleaser config check | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: goreleaser/goreleaser-action@v6 | |
| with: | |
| distribution: goreleaser | |
| version: '~> v2' | |
| args: check |