Workflow fix to prevent adding multiple ' - Development Version'. #11
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 Script Header | |
on: | |
push: | |
branches: | |
- main | |
- develop | |
pull_request: | |
branches: | |
- main | |
- develop | |
permissions: | |
contents: write | |
jobs: | |
update-header: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Determine current branch | |
id: vars | |
run: echo "::set-output name=branch::$(git rev-parse --abbrev-ref HEAD)" | |
- name: Update script header for main branch | |
if: steps.vars.outputs.branch == 'main' | |
run: | | |
script_file="dist/BlockWebsites.js" | |
sed -i '/Block Websites - Development Version/s//Block Websites/' "$script_file" | |
sed -i 's/\/develop\//\/main\//g' "$script_file" | |
- name: Update script header for develop branch | |
if: steps.vars.outputs.branch == 'develop' | |
run: | | |
script_file="dist/BlockWebsites.js" | |
# Ensure only one instance of ' - Development Version' | |
sed -i '/Block Websites$/s//& - Development Version/' "$script_file" | |
sed -i 's/\/main\//\/develop\//g' "$script_file" | |
- name: Commit and push changes | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git add dist/BlockWebsites.js | |
git commit -m "Update script header for ${{ steps.vars.outputs.branch }} branch" | |
git push | |
if: steps.vars.outputs.branch == 'main' || steps.vars.outputs.branch == 'develop' |