Skip to content

Commit

Permalink
chore: test create a tag that matches the version defined in the pack…
Browse files Browse the repository at this point in the history
…age.json file
  • Loading branch information
huynguyen-hl committed Jun 28, 2024
1 parent 078b684 commit 810224c
Showing 1 changed file with 58 additions and 29 deletions.
87 changes: 58 additions & 29 deletions .github/workflows/tag-main-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,72 @@ jobs:
git config --global user.name 'GitHub Actions'
git config --global user.email '[email protected]'
- name: Fetch all tags
run: |
git fetch --tags
# - name: Fetch all tags
# run: |
# git fetch --tags

- name: Get latest tag
id: get_latest_tag
run: |
# Get the latest tag
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1` 2>/dev/null || echo "none")
echo "Latest tag: $latest_tag"
echo "latest_tag=$latest_tag" >> $GITHUB_ENV
# - name: Get latest tag
# id: get_latest_tag
# run: |
# # Get the latest tag
# latest_tag=$(git describe --tags `git rev-list --tags --max-count=1` 2>/dev/null || echo "none")
# echo "Latest tag: $latest_tag"
# echo "latest_tag=$latest_tag" >> $GITHUB_ENV

# - name: Determine next tag version
# id: get_next_version
# run: |
# latest_tag=${{ env.latest_tag }}
# if [[ "$latest_tag" == "none" ]]; then
# echo "No tags found. Starting with v0.0.1"
# next_tag="v0.0.1"
# elif [[ $latest_tag =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
# major=${BASH_REMATCH[1]}
# minor=${BASH_REMATCH[2]}
# patch=${BASH_REMATCH[3]}
# next_patch=$((patch + 1))
# next_tag="v${major}.${minor}.${next_patch}"
# else
# echo "Latest tag format is invalid, cannot determine next version."
# exit 1
# fi
# echo "Next tag version: $next_tag"
# echo "next_tag=$next_tag" >> $GITHUB_ENV


- name: Determine next tag version
id: get_next_version
# - name: Create and push new tag
# env:
# TAG_NAME: ${{ env.next_tag }}
# run: |
# git tag $TAG_NAME
# git push origin $TAG_NAME
# echo "done"

- name: Get version from package.json
id: get_version
run: |
latest_tag=${{ env.latest_tag }}
if [[ "$latest_tag" == "none" ]]; then
echo "No tags found. Starting with v0.0.1"
next_tag="v0.0.1"
elif [[ $latest_tag =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
major=${BASH_REMATCH[1]}
minor=${BASH_REMATCH[2]}
patch=${BASH_REMATCH[3]}
next_patch=$((patch + 1))
next_tag="v${major}.${minor}.${next_patch}"
else
echo "Latest tag format is invalid, cannot determine next version."
# Read the version from package.json
version=$(jq -r .version package.json)
if [[ -z "$version" || "$version" == "null" ]]; then
echo "No valid version found in package.json."
exit 1
fi
echo "Next tag version: $next_tag"
echo "next_tag=$next_tag" >> $GITHUB_ENV
echo "Version from package.json: $version"
echo "version=$version" >> $GITHUB_ENV
- name: Check if tag already exists
id: check_tag
run: |
# Check if the tag already exists
tag_exists=$(git tag -l "v${{ env.version }}")
if [[ "$tag_exists" == "v${{ env.version }}" ]]; then
echo "Tag v${{ env.version }} already exists."
exit 0
fi
- name: Create and push new tag
env:
TAG_NAME: ${{ env.next_tag }}
TAG_NAME: "v${{ env.version }}"
run: |
git tag $TAG_NAME
git push origin $TAG_NAME
echo "done"
git push origin $TAG_NAME

0 comments on commit 810224c

Please sign in to comment.