Update file "issue templates.yml" #65
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update version placeholder | |
on: | |
push: | |
branches: | |
- '**' | |
workflow_dispatch: | |
jobs: | |
update-version-placeholder: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.GH_PAT }} | |
- name: Get last two branches name | |
id: get-branches | |
run: | | |
branches=$(git branch -r | sed 's/origin\///') | |
# Get last version branch by specific format | |
/* branches=$(git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short)' | grep -P '\b[a|b]?\d+\.\d+(\.\d+)?(\.\d{3})?\b' | head -n 1) */ | |
# Set the outputs for use in other steps or jobs | |
echo "branch_last=" "${branches[1]}" >> $GITHUB_ENV | |
- name: Get current placeholder name | |
id: extract-placeholder | |
run: | | |
# Get placeholder by specific format | |
placeholder=$(grep -oP '\b[a|b]?\d+\.\d+(\.\d+)?(\.\d{3})?\b' .github/ISSUE_TEMPLATE/bug.yml) | |
echo "placeholder=$placeholder" >> $GITHUB_ENV | |
- name: Update placeholder in bug.yml | |
run: | | |
# Announce settings | |
placeholder_to_replace=${{ env.placeholder }} | |
new_placeholder=${{ env.branch_last }} | |
# Check if placeholder to replace is same as the last branch name | |
if [ "$new_placeholder" != "$placeholder_to_replace" ]; then | |
#Change placeholder | |
sed -i "s/$placeholder_to_replace/$new_placeholder/g" .github/ISSUE_TEMPLATE/bug.yml | |
echo "Placeholder has been updated from ${{ env.placeholder}} to ${{ env.branch_last }} successfully" | |
else | |
echo "Placeholder failed to update. The last branch name is same as the current one!" | |
fi | |
- name: Commit changes | |
env: | |
GH_PAT: ${{ secrets.GH_PAT }} | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Actions" | |
git remote set-url origin https://${{ secrets.GH_PAT }}@github.com/JSarthurliao/FLRT_Minecraft-ResourcePack.git | |
git add .github/ISSUE_TEMPLATE/bug.yml | |
git commit -m "Update file 'bug.yml' placeholder" | |
git push origin HEAD:$(git symbolic-ref --short HEAD) | |
echo "Commit changes successfully." |