|
| 1 | +name: Container Image Releaser |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "*" |
| 7 | + branches: |
| 8 | + - "main" |
| 9 | + |
| 10 | +concurrency: ci-container-release |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + |
| 15 | +env: |
| 16 | + REGISTRY: ghcr.io |
| 17 | + IMAGE_NAME: ${{ github.repository }} |
| 18 | + |
| 19 | +jobs: |
| 20 | + build: |
| 21 | + if: "!contains(github.event.commits[0].message, '[noci]')" |
| 22 | + timeout-minutes: 30 |
| 23 | + runs-on: ubuntu-latest |
| 24 | + permissions: |
| 25 | + contents: read |
| 26 | + packages: write |
| 27 | + id-token: write |
| 28 | + |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 |
| 31 | + with: |
| 32 | + submodules: true |
| 33 | + fetch-depth: 0 |
| 34 | + |
| 35 | + - name: Registry Login |
| 36 | + uses: docker/login-action@dd4fa0671be5250ee6f50aedf4cb05514abda2c7 |
| 37 | + with: |
| 38 | + registry: ${{ env.REGISTRY }} |
| 39 | + username: ${{ github.actor }} |
| 40 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 41 | + |
| 42 | + - name: Setup QEMU |
| 43 | + uses: docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7 |
| 44 | + |
| 45 | + - name: Setup Docker Buildx |
| 46 | + uses: docker/setup-buildx-action@885d1462b80bc1c1c7f0b00334ad271f09369c55 |
| 47 | + |
| 48 | + - name: Build and Push Container Image |
| 49 | + run: | |
| 50 | + # Get the tag if this was a tag push event |
| 51 | + if [[ "${{ github.ref_type }}" == "tag" ]]; then |
| 52 | + TAG=${{ github.ref_name }} |
| 53 | + # Validate tag format (must be vX.Y.Z) |
| 54 | + if [[ $TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 55 | + # Build and push with both version tag and latest |
| 56 | + docker buildx build --push --platform linux/amd64,linux/arm64 \ |
| 57 | + -t $REGISTRY/$IMAGE_NAME:$TAG \ |
| 58 | + -t $REGISTRY/$IMAGE_NAME:latest \ |
| 59 | + . |
| 60 | + else |
| 61 | + echo "Invalid tag format. Must be in format vX.Y.Z (e.g. v1.2.3)" |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | + else |
| 65 | + # For non-tag pushes, just use latest tag |
| 66 | + docker buildx build --push --platform linux/amd64,linux/arm64 \ |
| 67 | + -t $REGISTRY/$IMAGE_NAME:latest \ |
| 68 | + . |
| 69 | + fi |
| 70 | +
|
| 71 | +
|
0 commit comments