Update README.md #21
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 & Publish Docker Image | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - container-setup | |
| tags: | |
| - 'v*' # optional: trigger on version tags like v1.2.3 | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Image version' | |
| required: true | |
| default: 'latest' | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| env: | |
| DEFAULT_TAG: 'latest' | |
| permissions: | |
| contents: read # to checkout code | |
| packages: write # to publish package | |
| id-token: write # if you use OIDC | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Determine image version | |
| id: set_version | |
| run: | | |
| # 1) dispatch → use the input | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| TAG="${{ github.event.inputs.version }}" | |
| # 2) tag → use the tag name (v1.2.3) | |
| elif [[ "${GITHUB_REF}" =~ ^refs/tags/(v.+)$ ]]; then | |
| TAG="${BASH_REMATCH[1]}" | |
| # 3) branch push → use our DEFAULT_VERSION | |
| else | |
| TAG="$DEFAULT_TAG" | |
| fi | |
| echo "TAG=$TAG" >> $GITHUB_ENV | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push image | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: . | |
| file: ./ContainerFile | |
| push: true | |
| tags: | | |
| ghcr.io/${{ github.repository_owner }}/popins4snake:${{ env.TAG }} | |
| ghcr.io/${{ github.repository_owner }}/popins4snake:latest | |
| - name: Output image reference | |
| run: echo "Published ghcr.io/${{ github.repository_owner }}/popins4snake:${{ env.TAG }}" |