How do I get the previous tag in github actions and then compare it to the current tag? - tags

I'm setting up continuous deployment with github actions which I want to run every time a tag is created.
However I only want to deploy if there has not been a major bump (Using semver for versions) since the last tag.
I have only been able so far to find actions/examples that get the current tag, not the one before. like (https://github.com/WyriHaximus/github-action-get-previous-tag)
How would I do this?
Edit: (thanks for the tip on git fetch -a) I managed to get it working with git tag and cut
- name: Get major of current tag and previous tag
id: vars
run: |
git fetch -a
echo ::set-output name=current_major::$(git tag --sort "-committerdate" | cut -d$'\n' -f1 | cut -d. -f1)
echo ::set-output name=previous_major::$(git tag --sort "-committerdate" | cut -d$'\n' -f2 | cut -d. -f1)

Related

Looking for curl or any other command to get the version number of an artifact belonging to particular release in nexus

For eg:
In my nexus repo - Temp-releases, under com/abc/temp/trial-platform-rpm, I have various folders like
6.1.7.0.34
6.1.8.1.3
7.0.0.0.568
7.0.1.0.89
7.0.2.0.544
So my script will provide the first 4 digits (For eg: if the branch selected is 7.0.2.0) then from nexus, I need to find latest version for this release (which is 7.0.2.0.544)
INPUT
7.0.2.0
OUTPUT
7.0.2.0.544
Curl command is as below and provide the version in grep :
curl -s "https://nexussite/nexus/service/local/repositories/Core-deloy/content/com/abc/item/item-portal-rpm/maven-metadata.xml" | grep "." | sort | uniq | sed -e "s#\(.\)\(\)\(.\)\(\)\(.\)#\3#g"| grep 7.0.1.0 | tail -n1""

Why doesn't git diff work between two dates?

I checked out a project from an internal GitLab server using Eclipse, then I pulled all the changes. When I view the history from Eclipse. (Team > show in history), it displays the full history of the project.
Now I go to the relevant project from the terminal.
/home/workspace/ProjectX/
I am trying to get the differences between 2 dates with the following command:
git diff --name-only master#{2015-10-10}..master#{2015-11-10} > /home/results/ProjectX/Changes.txt
It wont display any result for that. It displays:
warning: Log for 'master' only goes back to Tue, 10 Nov 2015.
How can I get all the differences in that date range?
In addition to that, how does Eclipse request its history from the remote server. If we can run the same command from the terminal, that should work.
Git parses dates like master#{2015-10-10} using your reflog, which doesn't appear to go back as far as you're searching. But, you can find commits for that date range anyway with rev-list:
git rev-list --since='2015-10-10' --until='2015-11-10' master
You want the files changes between the most recent and the oldest commit in that list, which we can get using head and tail. I'd like to use -n1 and --reverse, but --reverse applies after -n, so we can't.
first=$(git rev-list --since='2015-10-10' --until='2015-11-10' master | tail -1)
last=$(git rev-list --since='2015-10-10' --until='2015-11-10' master | head -1)
git diff --name-only $first..$last
Setting variables and duplicating the rev-list feels clumsy, but the pipe-y version I can come up with is sort of worse. It picks the first and last commits, converts the newline to a space using tr, replaces the new space with .. using sed, then passes the pair off to git diff.
git rev-list --since='2015-10-10' --until='2015-11-10' master | \
(head -n1 && tail -n1) | \
tr '\n' ' ' | \
sed 's/ /../' | \
xargs git diff --name-only

Commit hash of the revision about to be deployed?

I want to add a hook that logs something to the effect of "Hey, I'm about to deploy such-and-such commit." Something like:
before "deploy:update_code" do
logger.info "Deploying #{revision}"
end
Except "revision" in this context seems to yield a ref name (i.e. "master") rather than a commit ID. What construct can I use to get the sha1?
To get the ref, you'll need to shell out to Git:
Here's an example from one of my own projects, where master is fully up-to-date and pushed, and my clean_architecture branch isn't.
~/api git:(clean_architecture) $ git show-ref master
349dabbffec0713ac0fc70cf991dbaff6412ad2b refs/heads/master
349dabbffec0713ac0fc70cf991dbaff6412ad2b refs/remotes/origin/master
~/api git:(clean_architecture) $ git show-ref clean_architecture
14afae560ace128a13336ca01ff2391b678fadaf refs/heads/clean_architecture
bc78906ad0b2814dbc6225b2e14155b66eedffd0 refs/remotes/origin/clean_architecture
Taking that on-board, I'd suggest something like the following to grab the remotely pushed ref hash (as that's the only one the Capistrano 3 can see, Capistrano will do a check like this internally, but you can't access the ref, and will complain if these two values differ, anyway)
First, on the command line:
$ git show-ref clean_architecture | tail -1 | cut -f1 -d ' '
bc78906ad0b2814dbc6225b2e14155b66eedffd0
$ git show-ref clean_architecture | tail -1 | awk '{print $1}'
bc78906ad0b2814dbc6225b2e14155b66eedffd0
(there's about a million ways to do this on linux)
Secondly in Ruby:
$ irb --simple-prompt
>> `git show-ref #{fetch(:branch)}`
=> "349dabbffec0713ac0fc70cf991dbaff6412ad2b refs/heads/master\n349dabbffec0713ac0fc70cf991dbaff6412ad2b refs/remotes/origin/master\n"
Which let's us know we can split this up really easily in Ruby land, and not need cut or awk:
$ irb --simple-prompt
>> `git show-ref #{fetch(:branch)}`.split.first
That should be pretty close, and pretty-portable (where as cut and awk, and splitting that up in the shell with pipes, etc is quite *nix specific and unlikely to work well on Windows)
Drop that in your before task, and you should be set.

Bazaar: how to show history of changes to a file?

Hey I am using bazaar for my code, I wanna show the history of changes to a specific file, instead of showing changes to the whole bazaar repo. How could I do it?
bzr blame <filename> will show you which lines were introduced with which changes:
$ bzr blame Makefile
548 steve-b | #
| #
861 steve-b | OVERRIDE_TARBALL=yes
548 steve-b |
| include common/Make.rules
|
| DIRS=parser \
| profiles \
| utils \
| changehat/libapparmor \
| changehat/mod_apparmor \
| changehat/pam_apparmor \
| tests
If you just want the commit messages, bzr log <filename> will show you:
$ bzr log Makefile
------------------------------------------------------------
revno: 1828
tags: apparmor_2.7.0-beta2
committer: John Johansen <john.johansen#canonical.com>
branch nick: apparmor
timestamp: Thu 2011-09-15 13:28:01 -0700
message:
Remove extra space insert at from of ${TAG_VERSION} when doing the ~ to -
substitution.
Signed-off-by: John Johansen <john.johansen#canonical.com>
------------------------------------------------------------
revno: 1734
committer: Steve Beattie <sbeattie#ubuntu.com>
branch nick: apparmor
timestamp: Thu 2011-06-02 18:54:56 -0700
message:
This patch adjusts the tag make target to use a separate version with
'~' replaced by '-'. This is needed for mirroring to git as git can't
handle '~'s embedded in tag or branch names.
Tested by setting up a separate tag_version target like so:
tag_version:
echo ${TAG_VERSION}
...
bzr log is the key.
Purpose: Show historical log for a branch or subset of a branch.
Usage: bzr log [FILE...]
If you use a gui (TortoiseBzr of BzrExplorer), select the file and clic on log command.

How do I identify what branches exist in CVS?

I have a legacy CVS repository which shall be migrated to Perforce.
For each module, I need to identify what branches exist in that module.
I just want a list of branch names, no tags.
It must be a command line tool, for scripting reasons.
For example (assuming there is a cvs-list-branches.sh script):
$ ./cvs-list-branches.sh module1
HEAD
dev_foobar
Release_1_2
Release_1_3
$
As a quick hack:) The same stands true for rlog.
cvs log -h | awk -F"[.:]" '/^\t/&&$(NF-1)==0{print $1}' | sort -u
Improved version as per bdevay, hiding irrelevant output and left-aligning the result:
cvs log -h 2>&1 | awk -F"[.:]" '/^\t/&&$(NF-1)==0{print $1}' | awk '{print $1}' | sort -u
You could simply parse log output of cvs log -h. For each file there will be a section named Symbolic names :. All tags listed there that have a revision number that contains a zero as the last but one digit are branches. E.g.:
$ cvs log -h
Rcs file : '/cvsroot/Module/File.pas,v'
Working file : 'File.pas'
Head revision : 1.1
Branch revision :
Locks : strict
Access :
Symbolic names :
1.1 : 'Release-1-0'
1.1.2.4 : 'Release-1-1'
1.1.0.2 : 'Maintenance-BRANCH'
Keyword substitution : 'kv'
Total revisions : 5
Selected revisions : 0
Description :
===============================================
In this example Maintenance-BRANCH is clearly a branch because its revision number is listed as 1.1.0.2. This is also sometimes called a magic branch revision number.
This will bring up tags too, but tags and branches are basically the same in CVS.
$cvs.exe rlog -h -l -b module1
I have a small collection of "handy" korn shell functions one of which fetches tags for a given file. I've made a quick attempt to adapt it to do what you want. It simply does some seding/greping of the (r)log output and lists versions which have ".0." in them (which indicates that it's a branch tag):
get_branch_tags()
{
typeset FILE_PATH=$1
TEMP_TAGS_INFO=/tmp/cvsinfo$$
/usr/local/bin/cvs rlog $FILE_PATH 1>${TEMP_TAGS_INFO} 2>/dev/null
TEMPTAGS=`sed -n '/symbolic names:/,/keyword substitution:/p' ${TEMP_TAGS_INFO} | grep "\.0\." | cut -d: -f1 | awk '{print $1}'`
TAGS=`echo $TEMPTAGS | tr ' ' '/'`
echo ${TAGS:-NONE}
rm -Rf $TEMP_TAGS_INFO 2>/dev/null 1>&2
}
with Wincvs (Gui client for windows) this is trivial, a right click will give you any branches and tags the files have.
Trough a shell you may use cvs log -h -l module.
Check for the very first file created and committed in the repository. Open the file in server which will list all the Tags and Branches together