Skip to content

Commit

Permalink
🧱 Set up workflow for branch and tags sync
Browse files Browse the repository at this point in the history
  • Loading branch information
tiulpin committed Jul 18, 2023
1 parent f8bf038 commit 9a2e0b6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/branch.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Sync branches
name: Sync branches main with latest

on:
push:
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Sync version branches with tags
on:
push:
tags:
- 'v*'

jobs:
update:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Update version branch
run: |
TAG_REF=${{ github.ref }}
TAG_NAME=${TAG_REF:10} # Extract tag name from the ref string
BRANCH_VERSION=${TAG_NAME:0:7} # Extract version without the patch level
BRANCH_NAME="v$BRANCH_VERSION"
echo "Detected tag: $TAG_NAME"
echo "Checking for existing branch: $BRANCH_NAME"
# Check if the branch exists in the remote repository
BRANCH_EXISTS=$(git ls-remote --heads origin $BRANCH_NAME)
if [[ -z "$BRANCH_EXISTS" ]]; then
echo "Creating new branch: $BRANCH_NAME"
git checkout -b $BRANCH_NAME
else
echo "Switching to existing branch: $BRANCH_NAME"
git checkout $BRANCH_NAME
fi
# Reset the branch to point at the tag's commit
echo "Resetting branch $BRANCH_NAME to commit of tag $TAG_NAME"
git reset --hard $TAG_NAME
git push -u origin $BRANCH_NAME --force

0 comments on commit 9a2e0b6

Please sign in to comment.