Skip to content

Commit

Permalink
Update main.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
saranagaoka authored Dec 7, 2023
1 parent 59a4194 commit e2b3df0
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
name: Create Tag

on:
push:
branches:
- master
- prod
- dev

jobs:
build:
name: Create Tag
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Git
run: |
git config --global user.name 'github-actions'
- name: Create Tag
id: create_tag
env:
GITHUB_REF: ${{ github.ref }}
run: |
set -x
VERSION_PREFIX="v"
Expand All @@ -31,30 +29,20 @@ jobs:
CURRENT_VERSION=${CURRENT_TAG#$VERSION_PREFIX}
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
echo "VERSION_PARTS: ${VERSION_PARTS[@]}"
if [[ "$GITHUB_REF" == 'refs/heads/prod' ]]; then
if [[ "${{ github.ref }}" == 'refs/heads/prod' || "${{ github.ref }}" == 'refs/heads/master' ]]; then
VERSION_PARTS[0]=$((VERSION_PARTS[0] + 1))
VERSION_PARTS[1]=0
VERSION_PARTS[2]=0
elif [[ "$GITHUB_REF" == 'refs/heads/master' ]]; then
VERSION_PARTS[2]=$((VERSION_PARTS[2] + 1))
else
VERSION_PARTS[1]=$((VERSION_PARTS[1] + 1))
VERSION_PARTS[2]=0
fi
NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.${VERSION_PARTS[2]}"
NEW_TAG="$VERSION_PREFIX$NEW_VERSION"
while git rev-parse "$NEW_TAG" >/dev/null 2>&1
do
echo "$NEW_TAG already exists"
VERSION_PARTS[2]=$((VERSION_PARTS[2] + 1))
NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.${VERSION_PARTS[2]}"
NEW_TAG="$VERSION_PREFIX$NEW_VERSION"
done
echo "NEW_TAG: $NEW_TAG"
git tag $NEW_TAG || (echo "Failed to create tag" && exit 1)
git push origin $NEW_TAG || (echo "Failed to push tag" && exit 1)
echo "::set-output name=TAG_NAME::$NEW_TAG"
- name: Create Release
id: create_release
uses: actions/create-release@v1
Expand Down

0 comments on commit e2b3df0

Please sign in to comment.