release #45
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: release | |
| on: | |
| workflow_run: | |
| workflows: ["test"] | |
| branches: [main] | |
| types: | |
| - completed | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version: 1.26.0 | |
| - name: Install dependencies | |
| run: go mod download | |
| - name: Install mockgen | |
| run: go install go.uber.org/mock/mockgen@latest | |
| - name: Generate mocks | |
| run: go generate ./... | |
| - name: Run tests with coverage | |
| id: coverage | |
| run: | | |
| coverage_file="coverage-release-${{ github.run_id }}.out" | |
| go test -v -race -coverprofile="$coverage_file" -covermode=atomic ./... | |
| go tool cover -func="$coverage_file" | |
| echo "coverage_file=$coverage_file" >> $GITHUB_OUTPUT | |
| - name: Display coverage summary | |
| run: | | |
| echo "## Release Coverage Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "| Package.Function | Coverage |" >> $GITHUB_STEP_SUMMARY | |
| echo "|------------------|----------|" >> $GITHUB_STEP_SUMMARY | |
| go tool cover -func="${{ steps.coverage.outputs.coverage_file }}" | grep -v "total:" | grep -v "_mock.go" | while read line; do | |
| # Extract filename, function name, and coverage percentage | |
| filename=$(echo "$line" | awk '{print $1}') | |
| full_func=$(echo "$line" | awk '{print $2}') | |
| coverage=$(echo "$line" | awk '{print $3}') | |
| # Extract package name from filename (e.g., internal/config/config.go -> config) | |
| package_name=$(echo "$filename" | sed 's/.*\///' | sed 's/\.go$//' | sed 's/_test$//') | |
| # If there's no function name (just filename), use the package name | |
| if [[ "$full_func" == "" ]]; then | |
| func_display="$package_name" | |
| else | |
| # Combine package and function name | |
| func_display="$package_name.$full_func" | |
| fi | |
| echo "| \`$func_display\` | $coverage |" >> $GITHUB_STEP_SUMMARY | |
| done | |
| total_coverage=$(go tool cover -func="${{ steps.coverage.outputs.coverage_file }}" | grep "total:" | awk '{print $3}') | |
| echo "| **Total** | **$total_coverage** |" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Release Coverage: $total_coverage**" >> $GITHUB_STEP_SUMMARY | |
| - name: Upload coverage artifact | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: coverage-release-${{ github.run_id }} | |
| path: ${{ steps.coverage.outputs.coverage_file }} | |
| retention-days: 90 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| with: | |
| platforms: linux/amd64,linux/arm64 | |
| driver-opts: | | |
| network=host | |
| - name: Inspect builder | |
| run: docker buildx inspect --bootstrap | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| run: | | |
| SHORT_SHA=$(git describe --always --dirty) | |
| BRANCH_NAME_RAW=$(echo ${{ github.ref }} | sed 's/refs\/heads\///') | |
| BRANCH=$(echo $BRANCH_NAME_RAW | tr -c '[:alnum:]_-' '-') | |
| TAG="${BRANCH}${SHORT_SHA}" | |
| echo "Building tag: $TAG" | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| echo "branch=$BRANCH" >> $GITHUB_OUTPUT | |
| echo "short_sha=$SHORT_SHA" >> $GITHUB_OUTPUT | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| provenance: false | |
| sbom: false | |
| tags: | | |
| ghcr.io/${{ github.repository }}:${{ steps.meta.outputs.tag }} | |
| ghcr.io/${{ github.repository }}:latest | |
| labels: | | |
| org.opencontainers.image.title=OTEL LGTM Proxy | |
| org.opencontainers.image.description=OTEL LGTM Proxy | |
| org.opencontainers.image.url=https://github.com/${{ github.repository }} | |
| org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
| org.opencontainers.image.version=${{ steps.meta.outputs.tag }} | |
| org.opencontainers.image.created=${{ github.event.workflow_run.created_at }} | |
| org.opencontainers.image.revision=${{ github.sha }} | |
| org.opencontainers.image.licenses=MIT | |
| org.opencontainers.image.vendor=${{ github.repository_owner }} | |
| org.opencontainers.image.authors=${{ github.repository_owner }} | |
| build-args: | | |
| OTEL_SERVICE_NAME=otel-lgtm-proxy | |
| OTEL_SERVICE_VERSION=${{ steps.meta.outputs.tag }} |