Giter Site home page Giter Site logo

github-action-get-previous-tag's Introduction

Get previous tag

Continuous Integration GitHub release (latest SemVer)

GitHub Action that gets the latest tag from Git

Example output showing this action in action

Input

By default, this action will fail if no tag can be found, however, it accepts a fallback tag that will be used when no tag can be found. Keep in mind that when this action is used in a workflow that has no .git directory, it will still fail, and the fallback tag isn't used. It is also accepts a prefix string to query the tags based on it. And finally it takes a workingDirectory if you need to look for a tag in an alternative path.

  • fallback: 1.0.0
  • prefix: tag-prefix
  • workingDirectory: another/path/where/a/git/repo/is/checked/out

Output

This action has two outputs, tag for the found tag, or the fallback. And, timestamp as a UNIX Epoch timestmap for when the tag was created, or when no tag is found, and a fallback tag has be specific is provides the timestamp of action execution.

  • tag: 1.2.3
  • timestamp: 123

Example

Find more examples in the examples directory.

The following example works together with the WyriHaximus/github-action-next-semvers and WyriHaximus/github-action-create-milestone actions. Where it provides the previous tag from that action so it can supply a set of versions for the next action, which creates a new milestone. (This snippet has been taken from the automatic code generation of wyrihaximus/fake-php-version.)

name: Generate
jobs:
  generate:
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0 # Required due to the way Git works, without it this action won't be able to find any or the correct tags
      - name: 'Get Previous tag'
        id: previoustag
        uses: "WyriHaximus/github-action-get-previous-tag@v1"
        with:
          fallback: 1.0.0 # Optional fallback tag to use when no tag can be found
          #workingDirectory: another/path/where/a/git/repo/is/checked/out # Optional alternative working directory
      - name: 'Get next minor version'
        id: semvers
        uses: "WyriHaximus/github-action-next-semvers@v1"
        with:
          version: ${{ steps.previoustag.outputs.tag }}
      - name: 'Create new milestone'
        id: createmilestone
        uses: "WyriHaximus/github-action-create-milestone@v1"
        with:
          title: ${{ steps.semvers.outputs.patch }}
        env:
          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

License

Copyright 2021 Cees-Jan Kiewiet

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

github-action-get-previous-tag's People

Contributors

amitbenami avatar andrewkatz avatar bakoontz2 avatar coreyworrell avatar dargmuesli avatar fredster33 avatar harrisonratcliffe avatar imgbotapp avatar jhakonen avatar renovate[bot] avatar rheeseyb avatar rickstaa avatar staabm avatar wyrihaximus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

github-action-get-previous-tag's Issues

Change versioning scheme

First of all thanks a lot for the great action. Please allow me to throw in one suggestion. Maybe it is an idea to change the versioning scheme to include the v prefix? I think this is the convention used by official GitHub actions like the actions/checkout action. This will prevent confusion when users like me try to use the package based on a specific version:

- name: 'Get Previous tag'
  id: previous_tag
  uses: WyriHaximus/github-action-get-previous-tag@v1

Haya14busa provided a very handy action to make sure the major version tag points to the newest release. You can find it here.

related to #9

Doesn't work at all

Hello, I am trying to use this action to get the latest release tag.

The repo is here: https://github.com/zowe/vscode-extension-for-zowe/tags

As you can see, there are a lot of tags.

But the action fails with this error:
image

I am using the action as follows:

      - name: Get most recent GitHub release version (2)
        id: get_gh_version_2
        uses: "WyriHaximus/github-action-get-previous-tag@v1"

Action pulls tag associated with latest commit, not the latest tag

(Sorry, the workflow is not accessible publicly)

Two tags of interest, 1.10.109 and 1.10.110. Pulling the timestamps for the associated commits:

image

The timestamps for the tags themselves:

image

Clearly, 1.10.110 was created at a later time than 1.10.109. However, this is what get-previous-tag returns:

image

Interestingly, the timestamp "1662046975" corresponds to the commit time shown in the first image:

image

In the code:

image

"rev-list" "lists commit objects in reverse chronological order" (per the git-rev-list manpage). So the revision that is being returned isn't the revision associated with the latest tag, it's the revision representing the latest commit.

A more accurate command to actually return the lastest tag might be:

git for-each-ref --sort=-taggerdate --format="%(refname:short) | %(taggerdate)" "refs/tags/*"

where the last returned value is, in fact, the latest tag:

image

Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files.

Run WyriHaximus/github-action-get-previous-tag@v1
Found tag: v0.1.0
Found timestamp: 1666319694
Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-[10](https://github.com/jhm-ciberman/phantom-desktop/actions/runs/3305880852/jobs/5456349986#step:7:11)-[11](https://github.com/jhm-ciberman/phantom-desktop/actions/runs/3305880852/jobs/5456349986#step:7:12)-github-actions-deprecating-save-state-and-set-output-commands/
Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

Wrong tag and output format

I've been using this and the next-semvers for a long time without issue, but after the latest update an hour ago, I'm seeing the following issues:

Finding the wrong tag. It's outputting my oldest tag v1.0.0 when it should be something way higher in the 600's.

Then it looks like the new way of outputting the tags that was merged in #36 is breaking next-semvers, possibly from the extra newlines.

Fatal error: Uncaught Version\Exception\InvalidVersionString: Version string 'v1.0.0
' is not valid and cannot be parsed in /workdir/vendor/nikolaposa/version/src/Exception/InvalidVersionString.php:16
Stack trace:
#0 /workdir/vendor/nikolaposa/version/src/Version.php(65): Version\Exception\InvalidVersionString::notParsable('v1.0.0\r')
#1 /workdir/src/Next.php(25): Version\Version::fromString('v1.0.0\r')
#2 /workdir/next.php(14): WyriHaximus\Github\Actions\NextSemVers\Next::run('v1.0.0\r', true)
#3 /workdir/next.php(17): {closure}()
#4 {main}
  thrown in /workdir/vendor/nikolaposa/version/src/Exception/InvalidVersionString.php on line 16

Let me know if there's anything else I can help with in troubleshooting.

git not found?

Run WyriHaximus/github-action-get-previous-tag@v1
/usr/bin/docker exec  d177be54cbfdf6e6b4ae294e4f83da6da9b144df31cf1485904d55c896c89c7e sh -c "cat /etc/*release | grep ^ID"
Could not find any revisions because: 
/bin/sh: 1: git: not found

Shouldn't this action install git? I also use the checkout action before yours, which also relies on git. What am I doing wrong? My config is :

      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Get previous tag
        id: previoustag
        uses: "WyriHaximus/github-action-get-previous-tag@v1"
        with:
          fallback: ""

Not seeing latest tag

I've been having a few problems with this plugin over the past couple of days - unsure if it's the plugin or Github but it's not resolving the latest tag (it's been working fine for months before this week).

The action is resolving 1.161.0:
screenshot-github com-2021 06 03-11_53_52

But the latest is actually 1.162.0:
screenshot-github com-2021 06 03-11_54_16

This isn't a time issue as reported in a previous issue, as 1.162.0 was created yesterday.

My script is as follows (the repo is private):

      - name: Git checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: 'Get Previous tag'
        id: previoustag
        uses: "WyriHaximus/github-action-get-previous-tag@v1"
      - name: 'Get next minor version'
        id: semvers
        uses: "WyriHaximus/github-action-next-semvers@v1"
        with:
          version: ${{ steps.previoustag.outputs.tag }}

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v4
  • actions/checkout v4
  • therussiankid92/gat v1
  • actions/checkout v4
  • therussiankid92/gat v1
  • therussiankid92/gat v1
  • therussiankid92/gat v1
.github/workflows/craft-release.yaml
  • actions/checkout v4
  • actions/create-release v1
  • haya14busa/action-update-semver v1
.github/workflows/set-milestone-on-pr.yaml
  • actions/checkout v4

  • Check this box to trigger a request for Renovate to run again on this repository

Gets absolute latest tag, not just latest tag on branch

I'm not sure if this is intentional or not, but the action seems to get the latest tag across all branches, instead of just the latest on the branch that I run a workflow on.

The way I use the action is I have a manually triggered workflow_dispatch workflow that I can run on any branch. When I want to push a release, I trigger a workflow, and use your action in order to get the previous version number, so I can bump it. However, let's say I have two branches: 1.15 and 1.16, and the latest tag on the 1.15 branch is v1.10.4 and the latest tag on the 1.16 branch is v1.14.3, if I trigger my workflow on the 1.15 branch, your action gets the latest tag, which is v1.14.3, even though that's on a separate branch. Because of this, I'm unable to push a release for an older branch.

I'm not too sure about how git tags work, but I figure it should probably be possible to only get tags based on a certain branch? Hoping this isn't a difficult issue.

Failing with error: "Could not find any tags because: fatal: No names found, cannot describe anything."

I have created a (release) tag on my master branch and had to delete it again (deleted it locally + on GitHub). After that, one of my build workflows is suddenly failing with this error:

Run WyriHaximus/github-action-get-previous-tag@master
Could not find any tags because: 
fatal: No names found, cannot describe anything.

I think there is something messed up within GitHub. Locally, the commands git rev-list --tags --max-count=1 and git describe --tags execute just fine and yield the correct results.

I don't know how to "clean up" GitHub so that the action works correctly again. Any ideas?

Thanks!

Look further back in history?

Hey

I'm working on an Actions workflow to gather some information about PRs that were merged in a particular release, triggered by the creation of a new tag.

So for example if I tag 1.1 I would want to be able to run some git commands that specify a range of 1.0..1.1.

This action is excellent for getting the 1.1, but AFAICT I can't use it to figure out what the tag before that was (ie the 1.0).

Is that something that could be added?

Allow defining a default tag

I'm using your action in a template-repo, and when somebody uses the template, the first CI run will fail with

Could not find any tags because: 
fatal: No names found, cannot describe anything.

Your action is correct. There are no tags, it's a new repo :D
The obvious workaround is to create a tag, e.g., 0.0.1.

However, I would like to propose that we can specify a default tag, e.g., 0.0.1, like this:

      - name: 'Get Previous tag'
        id: get_previous_tag
        uses: "WyriHaximus/[email protected]"
        with:
          defaultTag: "0.0.1"
      - name: 'Get next patch version'
        id: get_next_semver_tag
        uses: "WyriHaximus/[email protected]"
        with:
          version: ${{ steps.get_previous_tag.outputs.tag }}

This would require a code change here:

exec(`git describe --tags ${rev}`, (err, tag, stderr) => {
if (err) {
console.log('\x1b[33m%s\x1b[0m', 'Could not find any tags because: ');
console.log('\x1b[31m%s\x1b[0m', stderr);
process.exit(1);
}

To respond with

            console.log(`::set-output name=tag::${tag}`);
            console.log(`::set-output name=timestamp::${timestamp}`);

instead of

            process.exit(1);

if a default tag is set. The timestamp, in this case, could just be set to the current time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.