Skip to content

Instantly share code, notes, and snippets.

@fredeil
Created March 29, 2020 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fredeil/26df20ef664b46f5ced338d5a8d8e8e9 to your computer and use it in GitHub Desktop.
Save fredeil/26df20ef664b46f5ced338d5a8d8e8e9 to your computer and use it in GitHub Desktop.
GitHub action for versioning your repository using NBGV

Simple versioning of your repository

Using NBGV to tag your master branch on push.

name: tag-master-branch
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-16.04
steps:
- uses: actions/checkout@v1
- uses: aarnott/nbgv@master
with:
setAllVars: true
- run: echo "VERSION= $NBGV_Version"
- name: Chmod shell script
run: chmod +x ./version.sh
shell: bash
continue-on-error: true
- name: Version
run: ./version.sh
shell: bash
{
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.0",
"publicReleaseRefSpec": [
"^refs/heads/master$",
"^refs/tags/v\\d+\\.\\d+"
]
}
#!/bin/bash
# Get the latest tag
tag=$(git describe --tags `git rev-list --tags --max-count=1`)
tag_commit=$(git rev-list -n 1 $tag)
# Get current commit hash for tag
commit=$(git rev-parse HEAD)
if [ "$tag_commit" == "$commit" ]; then
echo "No new commits since previous tag.."
exit 1
fi
if [ ! -f "version.json" ]; then
echo "Could not find version.json file.."
exit 1
fi
# Prefix release with 'v'
new="v$NBGV_Version"
echo ::set-output name=new_tag::$new
# Push new tag ref to GitHub
dt=$(date '+%Y-%m-%dT%H:%M:%SZ')
full_name=$GITHUB_REPOSITORY
git_refs_url=$(jq .repository.git_refs_url $GITHUB_EVENT_PATH | tr -d '"' | sed 's/{\/sha}//g')
echo "$dt: pushing tag $new to repo $full_name"
echo $git_refs_url
cat $GITHUB_EVENT_PATH | jq '.'
curl -s -X POST $git_refs_url \
-H "Authorization: token $GITHUB_TOKEN" \
-d @- << EOF
{
"ref": "refs/tags/$new",
"sha": "$commit"
}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment