Skip to content

Commit d0cddd6

Browse files
authored
Add Github action to automatically update branch alias (#160)
1 parent 1e712e8 commit d0cddd6

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

.github/workflows/branch-alias.yml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Update branch alias
2+
3+
on:
4+
push:
5+
tags: ['*']
6+
7+
jobs:
8+
branch-alias:
9+
name: Update branch alias
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Set up PHP
14+
uses: shivammathur/setup-php@v2
15+
with:
16+
php-version: 7.4
17+
coverage: none
18+
19+
- name: Checkout code
20+
uses: actions/checkout@v2
21+
with:
22+
ref: main
23+
24+
- name: Find branch alias
25+
id: find_alias
26+
run: |
27+
TAG=$(echo $GITHUB_REF | cut -d'/' -f 3)
28+
echo "Last tag was $TAG"
29+
ARR=(${TAG//./ })
30+
ARR[1]=$((${ARR[1]}+1))
31+
echo ::set-output name=alias::${ARR[0]}.${ARR[1]}
32+
33+
- name: Update branch alias
34+
run: |
35+
CURRENT_ALIAS=$(composer config extra.branch-alias.dev-main | cut -d'-' -f 1)
36+
37+
# If there is a current value on the branch alias
38+
if [ ! -z $CURRENT_ALIAS ]; then
39+
NEW_ALIAS=${{ steps.find_alias.outputs.alias }}
40+
CURRENT_ARR=(${CURRENT_ALIAS//./ })
41+
NEW_ARR=(${NEW_ALIAS//./ })
42+
43+
if [ ${CURRENT_ARR[0]} -gt ${NEW_ARR[0]} ]; then
44+
echo "The current value for major version is larger"
45+
exit 1;
46+
fi
47+
48+
if [ ${CURRENT_ARR[0]} -eq ${NEW_ARR[0]} ] && [ ${CURRENT_ARR[1]} -gt ${NEW_ARR[1]} ]; then
49+
echo "The current value for minor version is larger"
50+
exit 1;
51+
fi
52+
fi
53+
54+
composer config extra.branch-alias.dev-main ${{ steps.find_alias.outputs.alias }}-dev
55+
56+
- name: Commit & push the new files
57+
run: |
58+
echo "::group::git status"
59+
git status
60+
echo "::endgroup::"
61+
62+
git add -N .
63+
if [[ $(git diff --numstat | wc -l) -eq 0 ]]; then
64+
echo "No changes found. Exiting."
65+
exit 0;
66+
fi
67+
68+
git config --local user.email "[email protected]"
69+
git config --local user.name "GitHub"
70+
71+
echo "::group::git push"
72+
git add .
73+
git commit -m "Update branch alias"
74+
git push
75+
echo "::endgroup::"

0 commit comments

Comments
 (0)