docker / docker/metadata-action
Improve error message for invalid global expression
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.1k
- Forks
- 160
- Avg merge
- 4d 17h
- Merged PRs (30d)
- 12
Description
Contributing guidelines
- I've read the contributing guidelines and wholeheartedly agree
I've found a bug, and:
- The documentation does not mention anything about my problem
- There are no open or closed issues that are related to my problem
Description
Hello!
I'm trying to use the {{is_default_branch}} template to enable or disable specific tagging. This is my code:
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/messenger
tags: |
# Set version from releases. By default uses git tag which is has prefix "messenger"
type=semver,pattern={{version}},value=${{ needs.release.outputs.version }}
# Only on default branch (master) add MAJOR.MINOR and MAJOR and 'latest'
type=semver,pattern={{major}}.{{minor}},value=${{ needs.release.outputs.version }},enable={{is_default_branch}}
type=semver,pattern={{major}},value=${{ needs.release.outputs.version }},enable={{is_default_branch}}
type=raw,value=latest,enable={{is_default_branch}}
# Only on prereleases add beta-latest
type=raw,value=beta-latest,enable={{is_prerelease}}
labels: |
org.opencontainers.image.created={{commit_date 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'}}
The build fails on my CI because: "Error: Invalid value for enable attribute: " - sadly I can't figure this one out after hours of searching on google and trying to maybe set the context right.
Expected behaviour
is_default_branch to have a value
Actual behaviour
is_default_branch must be undefined or null since this code in src/meta.ts checks for the value:
# src/meta.ts
for (const tag of this.tags) {
const enabled = this.setGlobalExp(tag.attrs['enable']);
if (!['true', 'false'].includes(enabled)) {
throw new Error(`Invalid value for enable attribute: ${enabled}`);
}
Repository URL
No response
Workflow run URL
No response
YAML workflow
name: Release and Publish Messenger
on:
# Trigger on PR merge since direct pushes are prohibited
push:
branches:
- beta
- master
paths:
- 'messenger/**'
- '.github/workflows/release-messenger.yml'
# Trigger from UI
workflow_dispatch:
jobs:
# Create tag and release on github with correct version from conventional commits
release:
permissions:
contents: write
name: Create release
runs-on: ubuntu-latest
outputs:
published: ${{ steps.semantic.outputs.new_release_published }}
version: ${{ steps.semantic.outputs.new_release_version }}
major: ${{ steps.semantic.outputs.new_release_major_version }}
minor: ${{ steps.semantic.outputs.new_release_minor_version }}
patch: ${{ steps.semantic.outputs.new_release_patch_version }}
notes: ${{ steps.semantic.outputs.new_release_notes }}
tag: ${{ steps.semantic.outputs.new_release_git_tag }}
head: ${{ steps.semantic.outputs.new_release_git_head }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Execute Semantic Release
id: semantic
uses: cycjimmy/semantic-release-action@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
working_directory: ./messenger
# needed by commit-analyzer as dependency, this action installs it for us with this option
extra_plugins: |
conventional-changelog-conventionalcommits@9.1.0
build-and-push:
name: Build and Push Ponton Docker Image
runs-on: ubuntu-latest
needs: release
if: needs.release.outputs.published == 'true'
permissions:
contents: read
packages: write
steps:
- name: Checkout repository at released tag
uses: actions/checkout@v4
with:
ref: ${{ needs.release.outputs.head }}
fetch-depth: 0
fetch-tags: true
- name: Read Ponton version
id: ponton
run: |
PONTON_VERSION="$(cat messenger/VERSION)"
echo "ponton_version=${PONTON_VERSION}" >> "$GITHUB_OUTPUT"
- name: Compose combined image tag
id: tag
run: |
echo "combined=${{ steps.ponton.outputs.ponton_version }}-${{ needs.release.outputs.version }}" >> "$GITHUB_OUTPUT"
# For multiarch builds (x86, arm)
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Generate tags/labels. We pass the release version explicitly.
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/messenger
tags: |
# Set version from releases. By default uses git tag which is has prefix "messenger"
type=semver,pattern={{version}},value=${{ needs.release.outputs.version }}
# Only on default branch (master) add MAJOR.MINOR and MAJOR and 'latest'
type=semver,pattern={{major}}.{{minor}},value=${{ needs.release.outputs.version }},enable={{is_default_branch}}
type=semver,pattern={{major}},value=${{ needs.release.outputs.version }},enable={{is_default_branch}}
type=raw,value=latest,enable={{is_default_branch}}
# Only on prereleases add beta-latest
type=raw,value=beta-latest,enable={{is_prerelease}}
labels: |
org.opencontainers.image.created={{commit_date 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./messenger
file: ./messenger/Dockerfile
push: true
platforms: linux/amd64
tags: |
# Combined Ponton + SemRel tag (always)
ghcr.io/${{ github.repository_owner }}/messenger:${{ steps.tag.outputs.combined }}
# Tags from metadata-action
${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Output image details
run: |
cat <<'EOF'
Docker image pushed
Semantic-release version: ${{ needs.release.outputs.version }}
Ponton version: ${{ steps.ponton.outputs.ponton_version }}
Combined Version: ${{ steps.tag.outputs.combined }}
All tags:
$(echo "${{ steps.meta.outputs.tags }}" | sed 's/^/ - /')
- ${{ steps.tag.outputs.combined }}
EOF
Workflow logs
No response
BuildKit logs
Additional info
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/meta.ts at setGlobalExp and the validation of the tags' enable attribute. Reproduce the workflow's is_default_branch and is_prerelease expressions, then trace why the value is empty. Done means the expression handling or error reporting clearly reflects the supported behavior for these tag attributes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, github-actions, typescript
- Domain
- ci-cd, devops, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100