Skip to content

Update workflow to use GH_TOKEN instead of GITHUB_TOKEN #27

Update workflow to use GH_TOKEN instead of GITHUB_TOKEN

Update workflow to use GH_TOKEN instead of GITHUB_TOKEN #27

Workflow file for this run

name: Build and Push Docker Image
on:
push:
branches: [ main ]
# Optionally trigger on tags for releases
tags: [ 'v*' ]
# Allow manual triggering with version input
workflow_dispatch:
inputs:
version:
description: 'Version tag (e.g., v1.0.0)'
required: true
default: 'v1.0.0'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: write # Needed for creating releases
packages: write
# Add additional permissions for package management
actions: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
env:
GOTOOLCHAIN: auto
- name: Check Go version in Dockerfile and go.mod
run: |
echo "Checking Go version in Dockerfile..."
GO_VERSION_DOCKERFILE=$(grep "FROM golang:" Dockerfile | head -1 | cut -d':' -f2 | cut -d'-' -f1)
echo "Go version in Dockerfile: $GO_VERSION_DOCKERFILE"
echo "Checking Go version in go.mod..."
GO_VERSION_GOMOD=$(grep "^go " go.mod | awk '{print $2}')
echo "Go version in go.mod: $GO_VERSION_GOMOD"
if [[ "$GO_VERSION_DOCKERFILE" != "$GO_VERSION_GOMOD" ]]; then
echo "Warning: Go version mismatch between Dockerfile ($GO_VERSION_DOCKERFILE) and go.mod ($GO_VERSION_GOMOD)"
fi
echo "GOTOOLCHAIN environment variable is set to: $GOTOOLCHAIN"
env:
GOTOOLCHAIN: auto
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.PACKAGE_PAT || 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=schedule
type=ref,event=branch
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=${{ github.event.inputs.version }},enable=${{ github.event_name == 'workflow_dispatch' }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
env:
DOCKER_BUILDKIT: 1
GOTOOLCHAIN: auto
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GOTOOLCHAIN=auto
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Display manual instructions for making package public
run: |
echo "::warning::To make your package public, please follow these steps:"
echo "::warning::1. Go to https://github.com/${{ github.repository }}/pkgs/container/aws-multi-eni-controller"
echo "::warning::2. Click on Package settings (⚙️ icon) at the bottom of the page"
echo "::warning::3. Under 'Danger Zone', click 'Change visibility'"
echo "::warning::4. Select 'Public' and confirm"
- name: Create GitHub Release
if: github.event_name == 'workflow_dispatch'
uses: softprops/action-gh-release@v1
with:
name: Release ${{ github.event.inputs.version }}
tag_name: ${{ github.event.inputs.version }}
generate_release_notes: true
draft: false
prerelease: false