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

allow fetch tags too #701

Open
bluelovers opened this issue Feb 21, 2022 · 15 comments
Open

allow fetch tags too #701

bluelovers opened this issue Feb 21, 2022 · 15 comments

Comments

@bluelovers
Copy link

current it will add --no-tags

but i hope can fetch tag too

that is help when wanna build changelog base on tag in github actions

@koraktor
Copy link

koraktor commented Apr 6, 2022

Using fetch-depth: 0 will cause the refspec for tags to be added, effectively removing the --no-tags option:

if (!refSpec.some(x => x === refHelper.tagsRefSpec)) {
args.push('--no-tags')
}

Apparently, this might not be enough depending on your workflow. I‘m currently trying to implement this for koraktor/mavanagaiata which checks if the commit is tagged before releasing a new version. This check fails and I‘m still trying to find the cause for this.

@anthony-steele-cko
Copy link

anthony-steele-cko commented May 22, 2022

It is correct that if you add fetch-depth: 0 then you will get tags.

But this leaves you with two choices:

  • get no tags ( fetch-depth > 0 )
  • get the whole history, everything back to the start of the repo ( fetch-depth = 0 )

If you need the latest tag, then the first won't work at all.
If the repo is large and old, the then second isn't great either.

We should be able to get a bounded number of recent commits and tags by specifying some options.

@anthony-steele-cko
Copy link

See also: #448

@anthony-steele-cko
Copy link

anthony-steele-cko commented May 27, 2022

As a workaround, you can fetch tags as a step after the actions/checkout, as it leaves git in a valid state with credentials to do other operations. e.g.:

      - name: Checkout
        uses: actions/checkout@v3
      - name: Get tags
        run: git fetch --tags origin

As I understand it, this will fetch all tags but that's preferable to fetching all history when you want a tag.

@tiagovrtr
Copy link

This would be really useful so that things like dolfinus/setuptools-git-versioning would work in Actions

@mattpitkin
Copy link

@anthony-steele-cko Thanks for your suggested workaround. Unfortunately, I get the error:

git fetch --tags origin
  shell: sh -e {0}
fatal: unsafe repository ('/__w/cwinpy/cwinpy' is owned by someone else)
To add an exception for this directory, call:
	git config --global --add safe.directory /__w/cwinpy/cwinpy

despite git config --global --add safe.directory /__w/cwinpy/cwinpy being performed during the checkout action.

@alok87
Copy link

alok87 commented Sep 7, 2022

after git fetch --tags: git describe --tags --always --dirty is giving v1.0.0-beta.1-44-g898e851 response in my local when all tags are present but it gives tagless response in github action 🤔

had to do fetch-depth: 0

@markstijnman-shell
Copy link

Ran into this today as well. Turns out there is already a PR for this too: #579. Hopefully the maintainers can merge it soon, because I really don't fancy setting fetch_depth=0 on large, old repositories. Also, the link between fetch_depth and the fetching or not of tags is undocumented behavior, and I don't like having to rely on undocumented behavior.

@arvindpdmn
Copy link

Very useful feature. Please implement.

@geobos23
Copy link

after git fetch --tags: git describe --tags --always --dirty is giving v1.0.0-beta.1-44-g898e851 response in my local when all tags are present but it gives tagless response in github action thinking

had to do fetch-depth: 0

Ran into same problem recently. It's because it's not fetching the entire commit history if depth >0, so you'll only get tags for the the commits that are fetched within the specified depth. If the tags are older than depth, tough luck.
It's working locally for you because you're probably doing a git clone which fetches the entire history, while actions/checkout is actually doing a git init , git remote add origin and git fetch --depth=n --no-tags and only brings the current specified "remote ref" (to oversimplify it), preventing the history to be fetched.

I can also confirm the workaround with fetching the entire history solves the problem using

        with:
          fetch-depth: 0

tbnobody added a commit to tbnobody/OpenDTU that referenced this issue Apr 6, 2023
JCGoran added a commit to JCGoran/fitk that referenced this issue Apr 12, 2023
aureliendavid added a commit to aureliendavid/gpac that referenced this issue Jun 14, 2023
mschwan-phytec added a commit to phytec/partup that referenced this issue Jul 11, 2023
Manually fetch the Git tags, as this is currently not possible with the
default checkout action. See
actions/checkout#701 for detailed information.

Signed-off-by: Martin Schwan <m.schwan@phytec.de>
@arxeiss
Copy link

arxeiss commented Jul 18, 2023

As a workaround, you can fetch tags as a step after the actions/checkout, as it leaves git in a valid state with credentials to do other operations. e.g.:

  - name: Checkout
    uses: actions/checkout@v3
  - name: Get tags
    run: git fetch --tags origin

As I understand it, this will fetch all tags but that's preferable to fetching all history when you want a tag.

@anthony-steele-cko I'm not sure this works well.

If I do git fetch --tags it pulls all of them and then the result size of downloaded data is equal to normal fetch. Ie whole repo.

So I'm not sure that what this task is trying to achieve actually is feasible. Because it might looks like git issue, and not Github Action issue.

Or do I miss something? I'm trying it locally first with the latest git v2.41.0.

antroseco added a commit to DaveDuck321/GrapheneLang that referenced this issue Aug 28, 2023
This requires the `bootstrap/1` tag, which we have to fetch explicitly
on the test runners (see
actions/checkout#701).
@nmoroze
Copy link

nmoroze commented Sep 11, 2023

It looks like the PR adding this functionality got merged recently: #579, and is available in versions >=3.6.0. I think this issue can be closed now.

@dellagustin
Copy link

@nmoroze , I'm trying to use the option fetch-tags: true, introduced with #579, but that is not working for me.

My repository has 4 tags (https://github.com/podStation/podStation-test-new-pipeline/tags), the fetch command from actions/checkout@v4 does not have the --no-tags, yet a subsequent run of git tag does not list my tags:
https://github.com/podStation/podStation-test-new-pipeline/actions/runs/7837269005/job/21386615237
image

I compare the current version of my package with the latest tag in the pipeline to trigger my release and deployment in case there was a change in the version.

Have I understood the purpose of the option fetch-tags?
I think I'll need to use fetch-depth: 0 for the moment.

@arxeiss
Copy link

arxeiss commented Feb 9, 2024

I tried that and it works for me. However I specified fetch-depth: 20.
It seems to me, that it will fetch x commits and tags related to them. If you fetch just last commit, you might not get any tags at all.

In my case I need just last commit with tag. Based on our release strategy it most likely is within 5 last commits on master. So I fetch 20 just not to hit some edge case and works perfectly.

@dellagustin
Copy link

@arxeiss thank you, I though it would be something like that, but I did not test it yet.
I'll design around that than.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

13 participants