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

Jt/release git tag #130

Merged
merged 8 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/River_node_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
registry-type: 'public'

- name: Build and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-aws-ecr.outputs.registry }}
#This can be custom alias once requested to aws and approved for public repo
Expand Down Expand Up @@ -98,11 +99,37 @@ jobs:
-t river:local-latest \
.

echo "::set-output name=tag_valid::false"
for tag in "${TAGS[@]}"; do
if [ "$tag" == "mainnet" ] || [ "$tag" == "testnet" ]; then
echo "::set-output name=tag_valid::true"
echo "::set-output name=tag_value::$tag"
fi
docker tag river:local-latest $ECR_REGISTRY/$REGISTRY_ALIAS/$ECR_REPOSITORY:$tag
docker push $ECR_REGISTRY/$REGISTRY_ALIAS/$ECR_REPOSITORY:$tag
done

- name: Create new release tag
if: ${{ success() && steps.build-image.outputs.tag_valid == 'true' }}
id: create-tag
run: |
new_tag=$(./scripts/create-new-release-tag.sh ${{ steps.build-image.outputs.tag_value }})
echo "::set-output name=new_tag::$new_tag"

- name: Push tag
if: ${{ success() && steps.build-image.outputs.tag_valid == 'true' }}
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const response = await github.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/' + '${{ steps.create-tag.outputs.new_tag }}',
sha: context.sha
})
console.log(response)

# If action failed, we send a slack notification
- name: Slack notification
if: failure()
Expand Down
47 changes: 47 additions & 0 deletions scripts/create-new-release-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

# Check if prefix is provided as an argument
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <prefix>"
exit 1
fi

# Get the prefix argument
prefix="$1"

# Check if prefix is either "mainnet" or "testnet"
if [ "$prefix" != "mainnet" ] && [ "$prefix" != "testnet" ]; then
echo "Prefix must be either 'mainnet' or 'testnet'"
exit 1
fi

# Get the current year and month in YYYY-MM format
current_date=$(date "+%Y-%m-%d")

git fetch --tags > /dev/null 2>&1

# Get the list of tags matching the prefix and filter them by the format
tags=$(git tag -l "$prefix/*" | grep -E "^$prefix/[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]+$")

# Sort the tags lexicographically (highest first)
sorted_tags=$(echo "$tags" | sort -r)

# Iterate over the sorted tags
for tag in $sorted_tags; do
# Extract the date and number parts from the tag
tag_date=$(echo "$tag" | cut -d'/' -f2 | cut -d'-' -f1-3)
tag_number=$(echo "$tag" | cut -d'-' -f4)
# If the tag's date matches the current date
if [ "$tag_date" == "$current_date" ]; then
# Increment the number part of the tag
new_number=$((tag_number + 1))
new_tag="$prefix/$current_date-$new_number"

echo "$new_tag"
exit 0
fi
done

# If no matching tag was found for the current date, create a new one with number 01
new_tag="$prefix/$current_date-1"
echo "$new_tag"
Loading