Tag name not well-formed

In the root of my repository, I have a VERSION.txt file that contains something like v1.2.3.

My workflow is:

name: My workflow name

on:
  push:
    branches: [ master ]

env:
  MAJOR: $(cat VERSION.txt | cut -d . -f 1)
  MINOR: $(cat VERSION.txt | cut -d . -f 2)
  PATCH: $(cat VERSION.txt | cut -d . -f 3)

jobs:

  linting_unit_tests:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout master branch
      uses: actions/checkout@v2

    - name: Install Python3
      uses: actions/setup-python@v2
      with:
        python-version: '3.9'
    - name: Install requirements
      run:  pip install -r requirements.txt

    - name: Linting with sort
      uses: jamescurtin/isort-action@master

    - name: Linting with black
      run: black --check .

    - name: Run tests
      run: |
          python -m pytest tests/

  push_docker_image:
    needs: [linting_unit_tests]
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.get_version.outputs.version }}

    steps:
    - uses: actions/checkout@v2

    - name: Get docker image version
      id: get_version
      run:  |
        VERSION="v${MAJOR}.${MINOR}.${PATCH}"
        echo "::set-output name=version::${VERSION}"

    - name: Build docker image
      run:  |
        git tag ${{ steps.get_version.outputs.version }}
        cd docker
        docker-compose build

    - name: Tag docker image
      run:  |
        VERSION=${{ steps.get_version.outputs.version }}
        docker tag "my-app:latest" "us.gcr.io/${{secrets.GCP_PROJECT_ID}}/my-app:$VERSION"

    - name: Setup Cloud SDK
      uses: google-github-actions/setup-gcloud@master
      with:
        project_id: ${{ secrets.GCP_PROJECT_ID }}
        service_account_key: ${{ secrets.GCP_SA_KEY }}
        export_default_credentials: true

    - name: Authenticate docker with gcp
      run: |
        gcloud auth configure-docker

    - name: Push docker image
      run: |
        VERSION=${{ steps.get_version.outputs.version }}
        docker push "us.gcr.io/${{secrets.GCP_PROJECT_ID}}/my-app:$VERSION

  create_release:
    needs: [push_docker_image]
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - name: Echo release name
      run: |
        echo ${{ needs.push_docker_image.outputs.version }} # this outputs the right name for the release

    - name: Create release
      uses: actions/create-release@v1
      env:
         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      tag_name: ${{ needs.push_docker_image.outputs.version }} # THIS THROWS ERROR
      release_name: ${{ needs.push_docker_image.outputs.version }}
       draft: false
       prerelease: false

The step “Echo release name” outputs the right name I want to give to the release, which is something like v1.2.3
However, the “Create release” step throws an error:

Error: Validation Failed: {"resource":"Release","code":"custom","field":"tag_name","message":"tag_name is not a valid tag"}, {"resource":"Release","code":"custom","field":"tag_name","message":"tag_name is not well-formed"}, {"resource":"Release","code":"custom","message":"Published releases must have a valid tag"}

It seems like tag_name is taking the value v$(cat VERSION.txt | cut -d . -f 1).$(cat VERSION.txt | cut -d . -f 2).$(cat VERSION.txt | cut -d . -f 3) instead of the value v1.2.3

How to make tag_name take the value v1.2.3 ?

The problem is with this env definition, you can’t use Bash expressions there:

You’ll need to process the version file in a step, and set output parameters or environment variables, whichever works better for your use case. If you need the version parts in multiple jobs it’s probably better to use outputs and turn them into job outputs (see jobs.<job_id>.outputs).

Thank you for your reply. I removed the env key at the beginning of the yaml file, and replaced the get_version step with the following:

   - name: Get docker image version
      id: get_version
      run:  |
        MAJOR=$(cat VERSION.txt | cut -d . -f 1)
        MINOR=$(cat VERSION.txt | cut -d . -f 2)
        PATCH=$(cat VERSION.txt | cut -d . -f 3)
        VERSION="v${MAJOR}.${MINOR}.${PATCH}"
        echo "::set-output name=version::${VERSION}"

and it worked.

1 Like