Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(create-new-release.yml): update client-payload to use github.ref_… #92

Merged
merged 4 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/create-new-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
event-type: publish-docker-image
client-payload: '{"tag": "${{ github.ref }}"}'
client-payload: '{"tag": "${{ github.ref_name }}"}'
52 changes: 34 additions & 18 deletions .github/workflows/publish-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ on:
paths:
- 'Dockerfile'
- '.github/workflows/publish-docker-image.yml'
workflow_dispatch:
# Triggered by a repository_dispatch event to allow external systems to initiate the workflow
repository_dispatch:
types: [publish-docker-image]
workflow_dispatch:
inputs:
tag:
description: 'Docker image tag'
required: true
default: 'nightly'

jobs:
build-and-publish:
Expand All @@ -31,22 +35,34 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image with version tag
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/yourip:${{ github.event.client_payload.tag }}
ghcr.io/${{ github.repository_owner }}/yourip:latest

- name: Build and push Docker image with nightly tag
if: github.event.client_payload.tag == 'nightly'
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ghcr.io/${{ github.repository_owner }}/yourip:nightly
- name: Set TAG variable
run: |
if [ "${{ github.event_name }}" == "repository_dispatch" ]; then
TAG="${{ github.event.client_payload.tag }}"
elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
TAG="${{ github.event.inputs.tag }}"
elif [ "${{ github.event_name }}" == "push" ]; then
if [[ "${{ github.event.head_commit.message }}" == *"Update publish-docker-image.yml"* ]]; then
TAG="test"
else
TAG="nightly"
fi
else
echo "Unsupported event: ${{ github.event_name }}"
exit 1
fi

if [ -z "$TAG" ]; then
echo "TAG is not defined. Please ensure that the tag is set in your environment variables or input parameters."
exit 1
fi
echo "TAG=$TAG" >> $GITHUB_ENV

- name: Build and push Docker image
run: |
docker buildx build \
--tag ghcr.io/${{ github.repository_owner }}/yourip:${TAG} \
--push .

- name: Logout from GHCR
run: docker logout ghcr.io
Loading