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 1 commit
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 }}"}'
43 changes: 24 additions & 19 deletions .github/workflows/publish-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ on:
push:
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 +34,24 @@ 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: Build and push Docker image
run: |
TAG="${{ github.event.client_payload.tag || github.event.inputs.tag }}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Potential issue with tag extraction.

The expression ${{ github.event.client_payload.tag || github.event.inputs.tag }} might not work as expected if github.event.client_payload.tag is an empty string. Consider using a more explicit check.

if [ -z "${TAG}" ]; then
mauvehed marked this conversation as resolved.
Show resolved Hide resolved
echo "Tag is not defined"
exit 1
fi

if [ "${TAG}" = "nightly" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Use double brackets for string comparison.

Using double brackets [[ ... ]] for string comparison is generally safer and more robust in shell scripts.

Suggested change
if [ "${TAG}" = "nightly" ]; then
if [[ "${TAG}" == "nightly" ]]; then

docker buildx build \
--tag ghcr.io/${{ github.repository_owner }}/yourip:nightly \
--push .
else
docker buildx build \
--tag ghcr.io/${{ github.repository_owner }}/yourip:${TAG} \
--tag ghcr.io/${{ github.repository_owner }}/yourip:latest \
--push .
fi

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