-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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
chore: add latest tag action #11148
Merged
villebro
merged 7 commits into
apache:master
from
preset-io:elizabeth/latest-tag-action
Dec 17, 2020
Merged
chore: add latest tag action #11148
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
90a937e
add latest tag action
eschutho b423f5d
update documentation with latest tag info
eschutho d1130d8
Python in docs doesn't need v3 reference
eschutho 973d47a
add check that latest tag is truly a later version
eschutho 589c4ef
remove rc from acceptable tags
eschutho db2b28c
move tag script to seperate file
eschutho ba31898
add a check that the tag exists
eschutho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Tags | ||
on: | ||
release: | ||
types: [published] # This makes it run only when a new released is published | ||
|
||
jobs: | ||
latest-release: | ||
name: Add/update tag to new release | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Check for latest tag | ||
id: latest-tag | ||
run: | | ||
source ./scripts/tag_latest_release.sh $(echo ${{ github.event.release.tag_name }}) --dry-run | ||
|
||
if ${SKIP_TAG} | ||
then | ||
echo "::set-env name=skip_tag::true" | ||
fi | ||
|
||
- name: Run latest-tag | ||
uses: EndBug/latest-tag@latest | ||
if: (! env.skip_tag ) | ||
with: | ||
description: Superset latest release | ||
tag-name: latest | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#! /bin/bash | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
run_git_tag () { | ||
if [ "$DRY_RUN" = "false" ] && [ "$SKIP_TAG" = "false" ] | ||
then | ||
git tag -a -f latest "${GITHUB_TAG_NAME}" -m "latest tag" | ||
echo "${GITHUB_TAG_NAME} has been tagged 'latest'" | ||
fi | ||
exit 0 | ||
} | ||
|
||
SKIP_TAG=false | ||
DRY_RUN=false | ||
|
||
# get params passed in with script when it was run | ||
# --dry-run is optional and returns the value of SKIP_TAG, but does not run the git tag statement | ||
# A tag name is required as a param. A SHA won't work. You must first tag a sha with a release number | ||
# and then run this script | ||
while [[ $# -gt 0 ]] | ||
do | ||
key="$1" | ||
|
||
case $key in | ||
--dry-run) | ||
DRY_RUN=true | ||
shift # past value | ||
;; | ||
*) # this should be the tag name | ||
GITHUB_TAG_NAME=$key | ||
shift # past value | ||
;; | ||
esac | ||
done | ||
|
||
if [ -z "${GITHUB_TAG_NAME}" ]; then | ||
echo "Missing tag parameter, usage: ./scripts/tag_latest_release.sh <GITHUB_TAG_NAME>" | ||
exit 1 | ||
fi | ||
|
||
# check that this tag only contains a proper semantic version | ||
if ! [[ ${GITHUB_TAG_NAME} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] | ||
then | ||
echo "This tag ${GITHUB_TAG_NAME} is not a valid release version. Not tagging." | ||
SKIP_TAG=true | ||
exit 0 | ||
fi | ||
|
||
## split the current GITHUB_TAG_NAME into an array at the dot | ||
IFS=$'.' | ||
THIS_TAG_NAME=(${GITHUB_TAG_NAME}) || echo 'not found' | ||
|
||
# look up the 'latest' tag on git | ||
LATEST_TAG_LIST=$(git show-ref latest && git show --pretty=tformat:%d -s latest | grep tag:) || echo 'not found' | ||
|
||
# if 'latest' tag doesn't exist, then set this commit to latest | ||
if [[ -z "$LATEST_TAG_LIST" ]] | ||
then | ||
# move on to next task | ||
echo "there are no latest tags yet, so I'm going to start by tagging this sha as the latest" | ||
run_git_tag | ||
fi | ||
|
||
## get all tags that use the same sha as the latest tag. split at comma. | ||
IFS=$',' | ||
LATEST_TAGS=($LATEST_TAG_LIST) | ||
|
||
## loop over those tags and only take action on the one that isn't tagged 'latest' | ||
## that one will have the version number tag | ||
for (( i=0; i<${#LATEST_TAGS[@]}; i++ )) | ||
do | ||
if [[ ${LATEST_TAGS[$i]} != *"latest"* ]] | ||
then | ||
## extract just the version from this tag | ||
LATEST_RELEASE_TAG=$(echo "${LATEST_TAGS[$i]}" | sed -E -e 's/tag:|\(|\)|[[:space:]]*//g') | ||
|
||
# check that this only contains a proper semantic version | ||
if ! [[ ${LATEST_RELEASE_TAG} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] | ||
then | ||
echo "This tag ${LATEST_RELEASE_TAG} is not a valid release version. Looking for another." | ||
continue | ||
fi | ||
echo "The current release with the latest tag is version ${LATEST_RELEASE_TAG}" | ||
|
||
## remove the sha from the latest tag and split into an array- split at the dot | ||
IFS=$'.' | ||
LATEST_RELEASE_TAG_SPLIT=(${LATEST_RELEASE_TAG}) | ||
|
||
for (( j=0; j<${#THIS_TAG_NAME[@]}; j++ )) | ||
do | ||
## if this value is greater than the latest release, then tag it, if it's lower, then stop, if it's | ||
## the same then move on to the next index | ||
if [[ ${THIS_TAG_NAME[$j]} -gt ${LATEST_RELEASE_TAG_SPLIT[$j]} ]] | ||
then | ||
echo "This release tag ${GITHUB_TAG_NAME} is the latest. Tagging it" | ||
run_git_tag | ||
|
||
elif [[ ${THIS_TAG_NAME[$j]} -lt ${LATEST_RELEASE_TAG_SPLIT[$j]} ]] | ||
then | ||
continue | ||
fi | ||
done | ||
fi | ||
done | ||
|
||
echo "This release tag ${GITHUB_TAG_NAME} is not the latest. Not tagging." | ||
# if you've gotten this far, then we don't want to run any tags in the next step | ||
SKIP_TAG=true |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ktmud may have some insight on using
secrets.GITHUB_TOKEN
vsgithub.GITHUB_TOKEN
. I haven't seen the latter in documentation, although it seems that using it over thesecrets
could be worth looking at.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems there is no
github.GITHUB_TOKEN
available according to the doc, butgithub.token
is equivalent tosecrets.GITHUB_TOKEN
: https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions#github-contextThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great. thanks for that. That makes sense.