Be a bit more lenient with parsing semver bumps (#236) #188
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: "Prettybot Automation" | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: # Add manual trigger | |
# Increase the access for the GITHUB_TOKEN | |
permissions: | |
# This Allows the GITHUB_TOKEN to approve pull requests | |
pull-requests: write | |
# This Allows the GITHUB_TOKEN to auto merge pull requests | |
contents: write | |
env: | |
PR_URL: ${{github.event.pull_request.html_url}} | |
# By default, GitHub Actions workflows triggered by Dependabot get a GITHUB_TOKEN with read-only permissions. | |
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
BRANCH_NAME: prettybot/automation-${{ github.run_number }} | |
jobs: | |
create-pr: | |
runs-on: ubuntu-latest | |
concurrency: | |
group: prettybot | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Create new branch | |
run: | | |
git checkout -b ${{ env.BRANCH_NAME }} | |
- name: Log in to Docker Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ secrets.INTERNAL_DOCKER_REGISTRY_URL }} | |
username: ${{ secrets.INTERNAL_DOCKER_READ_ONLY_USER_NAME }} | |
password: ${{ secrets.INTERNAL_DOCKER_READ_ONLY_ACCESS_TOKEN }} | |
- name: Run Cleanup Code | |
# Make the workspace writable to github actions runner user | |
run: | | |
chmod -R a+w ${{ github.workspace }} | |
docker run -v ${{ github.workspace }}:/src ${{ secrets.INTERNAL_DOCKER_REGISTRY_URL }}/octopusdeploy/tool-containers/tool-resharper-cli:latest /scripts/prettybot.sh | |
- name: Git Check for file changes | |
id: git-check | |
run: | | |
if [ -z "$(git status --porcelain)" ]; then | |
echo "changed=false" >> $GITHUB_OUTPUT | |
else | |
echo "changed=true" >> $GITHUB_OUTPUT | |
fi | |
- name: Commit and push changes | |
if: steps.git-check.outputs.changed == 'true' | |
run: | | |
git config user.email "[email protected]" | |
git config user.name "Github Actions" | |
git commit -am "Run ReSharper code cleanup" | |
git push origin ${{ env.BRANCH_NAME }} | |
- name: Create Pull Request | |
if: steps.git-check.outputs.changed == 'true' | |
run: | | |
EXISTING_PRS=$(gh pr list --author "github-actions[bot]" --state open --head "prettybot" --json number --template '{{range .}}{{.number}}{{ "\n" }}{{end}}') | |
NEW_PR=$(gh pr create --base main --head ${{ env.BRANCH_NAME }} --title "Automated PR for Prettybot" --body "This is an automated PR.") | |
# close existing PRs | |
for pr in $EXISTING_PRS; do | |
gh pr close "$pr" --comment "Superseded by $NEW_PR." --delete-branch | |
done | |