Skip to content

Publish

Publish #75

Workflow file for this run

# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: Publish
on:
workflow_run:
workflows: ["CI"]
types: [completed]
permissions:
contents: read
packages: write
jobs:
publish:
name: Build binaries and publish container image
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23.0'
cache: false
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Get version info
id: version
run: |
echo "git_sha=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_OUTPUT
echo "branch=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT
- name: Build linux/amd64 binary
run: |
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -mod vendor -ldflags "-X main.Branch=${{ steps.version.outputs.branch }} -X main.Revision=${{ steps.version.outputs.git_sha }} -X main.Version=${{ steps.version.outputs.git_sha }} -s -w" -o ./bin/linux/prometheus-plex-exporter-amd64 ./cmd/prometheus-plex-exporter
- name: Build linux/arm64 binary
run: |
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -mod vendor -ldflags "-X main.Branch=${{ steps.version.outputs.branch }} -X main.Revision=${{ steps.version.outputs.git_sha }} -X main.Version=${{ steps.version.outputs.git_sha }} -s -w" -o ./bin/linux/prometheus-plex-exporter-arm64 ./cmd/prometheus-plex-exporter
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push multi-arch image
id: build
uses: docker/build-push-action@v5
with:
context: .
file: ./cmd/prometheus-plex-exporter/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/prometheus-plex-exporter:latest
ghcr.io/${{ github.repository_owner }}/prometheus-plex-exporter:${{ steps.version.outputs.git_sha }}
# emit metadata including the manifest digest so we can tag by digest
outputs: type=registry
- name: Create composite tag and push
run: |
# extract manifest digest from build action output
digest="${{ steps.build.outputs.digest }}"
if [ -z "$digest" ]; then
echo "No digest found from build step; aborting"
exit 1
fi
# strip optional 'sha256:' prefix and use the full hex digest so the tag
# can be mapped directly back to the manifest used for docker pull.
docker_digest_hex=$(echo "$digest" | sed -E 's/^sha256://g')
git_sha=${{ steps.version.outputs.git_sha }}
composite_tag="ghcr.io/${{ github.repository_owner }}/prometheus-plex-exporter:sha256-${docker_digest_hex}-${git_sha}"
echo "Composite tag: $composite_tag"
# pull by manifest digest and retag
docker pull ghcr.io/${{ github.repository_owner }}/prometheus-plex-exporter@${digest}
docker tag ghcr.io/${{ github.repository_owner }}/prometheus-plex-exporter@${digest} $composite_tag
docker push $composite_tag