nx-tools icon indicating copy to clipboard operation
nx-tools copied to clipboard

Getting the tagging working

Open cskiwi opened this issue 1 year ago • 1 comments

hi,

I'm trying to get my packages correctly tagged.

I want to have latest, vX.X.X. But it only seems to tag with the sha-xxxx and main

this is my config:

"docker": {
  "executor": "@nx-tools/nx-docker:build",
  "options": {
    "push": true,
    "metadata": {
      "images": ["ghcr.io/badminton-apps/xxxx/worker/sync"],
      "flavor": ["latest=auto"],
      "tags": [
        "type=schedule",
        "type=ref,event=branch",
        "type=ref,event=tag",
        "type=ref,event=pr",
        "type=match,pattern=v(.*),group=1",
        "type=semver,pattern={{version}}",
        "type=semver,pattern={{major}}.{{minor}}",
        "type=semver,pattern={{major}}",
        "type=sha,prefix=sha-"
      ]
    }
  }
},

github actions:

- uses: actions/checkout@v3
  with:
    fetch-depth: 0
- name: Checkout latest release tag
  run: |
    LATEST_TAG=$(git describe --match 'v*' --abbrev=0 --tags $(git rev-list --tags --max-count=1))
    git checkout $LATEST_TAG
- run: npx nx affected --target=docker --base=${{ needs.base.outputs.base }} --head=origin/main
  env:
    INPUT_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

I've tried just normally checking out, with and without the fetch-depth. I've tried differnt tags and with and without any flavors. But none gave me the expected result

Is there anything I'm doing wrong?

I'm thinking that a possible issue could be that the name of master branch is changed to "main" for new github projects?

cskiwi avatar Jul 13 '22 12:07 cskiwi

By doing:

- run: npx nx affected --target=docker --base=${{ needs.base.outputs.base }} --head=origin/main
  env:
    INPUT_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    INPUT_TAGS: ${{env.LATEST_TAG}}

I can get the version tag on it. But now I don't have the latest tag on it. Is there any way to add this?

cskiwi avatar Jul 27 '22 16:07 cskiwi

You need to push an actual tag in order to get match and semver to work, using npm version for instance and have the action run on that. The latest tag will be automatically added when this happens due to the semver and match rules. In addition, as you might be working with a monorepo semver might not work as the tags created are usually of the format <app>@<version>(e.g. changesets). I have added some rules to cover that scenario below:

"type=match,pattern=/app-name@(\\d+\\.\\d+\\.\\d+)(?!-)/i,group=1",
"type=match,pattern=/app-name@(\\d+\\.\\d+)\\.\\d+(?!-)/i,group=1",
"type=match,pattern=/app-name@(\\d+)\\.\\d+\\.\\d+(?!-)/i,group=1",

Also this might be of interest regarding the generation of the latest tag https://github.com/docker/metadata-action#latest-tag

microwavekonijn avatar Feb 12 '23 23:02 microwavekonijn

thanks! but the creation of a docker image isn't needed anymore. So I can't test this as I've removed the code.

cskiwi avatar Feb 17 '23 09:02 cskiwi