0

This is what I am trying:

- name: Create tag
  uses: actions/github-script@v3
  with:
    script: |
      console.log(await github.git.getRef({
        owner: context.repo.owner,
        ref: "refs/tags/v0.0.1",
        repo: context.repo.repo,
      }));

However, it is producing "Not Found" error.

If I check using git, I can see that tag exists:

$ git ls-remote
From [email protected]:contra/contra-deploy-tools.git
fc857fff2008eca7c4a547ad4bb35cd7ef5f3891    HEAD
fc857fff2008eca7c4a547ad4bb35cd7ef5f3891    refs/heads/main
b4e20f75a51aac030e3d8ca1360ee1ff84f10c18    refs/tags/v0.0.1

It appears like this is a permission issue. However, I am able to create a tag, and workflow permissions are configured to "Read and write permissions".

What's more surprising is that I am able to list references within the workflow:

Run git ls-remote
From https://github.com/contra/contra-deploy-tools
f0191b469168aa48ee177d270fa2af507d3f7710    HEAD
f0191b469168aa48ee177d270fa2af507d3f7710    refs/heads/main
b4e20f75a51aac030e3d8ca1360ee1ff84f10c18    refs/tags/v0.0.1

This seems to be API specific issue.

What am I missing?

1 Answer 1

1

You don't need the refs/ prefix in that API. Looking at the docs, it says that:

Returns a single reference from your Git database. The :ref in the URL must be formatted as heads/ for branches and tags/ for tags.

So if you change your step to the below, it should work.

- name: Create tag
  uses: actions/github-script@v3
  with:
    script: |
      console.log(await github.git.getRef({
        owner: context.repo.owner,
        ref: "tags/v0.0.1",
        repo: context.repo.repo,
      }));

NB: You're using github-script version 3, but there's already v5. If you want to keep your actions up to date, I previously described how that can be done using dependabot: https://stackoverflow.com/a/70196496/1080523

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.