Skip to content

Update file "issue templates.yml" #61

Update file "issue templates.yml"

Update file "issue templates.yml" #61

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: |
# List all branches sorted by commit date, then take the last two excluding "master"
branches=$(git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short)' | head -n 2)
branch_array=($branches)
# Set the outputs for use in other steps or jobs
echo "branch_default=${branch_array[0]}"
echo "branch_last=" "${branch_array[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."