From cffc878917566ed4688ad041d9c7bfad7decb258 Mon Sep 17 00:00:00 2001 From: Max Cotton Date: Sat, 28 May 2022 15:02:44 -0400 Subject: [PATCH 1/6] feat: add custom commit message and PR title --- action.yaml | 8 ++++++++ main.py | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/action.yaml b/action.yaml index 6e10c79..0faab27 100644 --- a/action.yaml +++ b/action.yaml @@ -13,6 +13,14 @@ inputs: description: 'Email Address of that user who will commit' required: false default: 'github-actions[bot]@users.noreply.github.com' + commit_message: + description: 'Commit message for the commits by the action' + required: false + default: 'Update GitHub Action Versions' + pull_request_title: + description: 'Title for the pull requests generated by the action' + required: false + default: 'Update GitHub Action Versions' ignore: description: 'A JSON array which denotes the actions that should not be updated' required: false diff --git a/main.py b/main.py index 2547e54..a0c0b96 100644 --- a/main.py +++ b/main.py @@ -183,7 +183,7 @@ def create_new_branch(self): ) subprocess.run(['git', 'add', '.']) subprocess.run( - ['git', 'commit', '-m', 'Update GitHub Action Versions'] + ['git', 'commit', '-m', commit_message] ) subprocess.run(['git', 'push', '-u', 'origin', new_branch]) @@ -196,7 +196,7 @@ def create_pull_request(self, branch_name, body): """Create pull request on GitHub""" url = f'{self.github_api_url}/repos/{self.repository}/pulls' payload = { - 'title': 'Update GitHub Action Versions', + 'title': pr_title, 'head': branch_name, 'base': self.base_branch, 'body': body, @@ -312,6 +312,10 @@ def print_message(message, message_type=None): email = os.environ['INPUT_COMMITTER_EMAIL'] # Actions that should not be updated ignore = os.environ['INPUT_IGNORE'] + # Commit message + commit_message = os.environ['INPUT_COMMIT_MESSAGE'] + # Pull Request Title + pr_title = os.environ['INPUT_PULL_REQUEST_TITLE'] # Group: Configure Git print_message('Configure Git', message_type='group') From dd0c254e8ba156facc3d2c7f814821a7b58178b9 Mon Sep 17 00:00:00 2001 From: Max Cotton Date: Sat, 28 May 2022 15:45:42 -0400 Subject: [PATCH 2/6] docs: update readme with new feature --- README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index dbe2904..f6d06f7 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/saadmk11/github-actions-version-updater/Changelog%20CI?label=Changelog%20CI&style=flat-square) **GitHub Actions Version Updater** is GitHub Action that is used to **update other GitHub Actions** in a Repository -and create a **pull request** with the updates. It is an automated dependency updater similar to GitHub's **Dependabot**, +and create a **pull request** with the updates. It is an automated dependency updater similar to GitHub's **Dependabot**, but for GitHub Actions. ### How Does It Work: @@ -24,16 +24,16 @@ but for GitHub Actions. ### Usage: -We recommend running this action on a [`schedule`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#schedule) +We recommend running this action on a [`schedule`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#schedule) event or a [`workflow_dispatch`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch) event. -To integrate `GitHub Actions Version Updater` on your repository, create a `YAML` file +To integrate `GitHub Actions Version Updater` on your repository, create a `YAML` file inside `.github/workflows/` directory (`.github/workflows/updater.yaml`) add the following into the file: ```yaml name: GitHub Actions Version Updater -# Controls when the action will run. +# Controls when the action will run. on: # can be used to run workflow manually workflow_dispatch: @@ -44,7 +44,7 @@ on: jobs: build: runs-on: ubuntu-latest - + steps: - uses: actions/checkout@v2 with: @@ -58,6 +58,10 @@ jobs: # defaults to `github-actions[bot]` if not provided committer_username: 'test' committer_email: 'test@test.com' + # Optional, allows customizing the commit message and pull request title + # Both default to 'Update GitHub Action Versions' + commit_message: 'Commit Message' + pull_request_title: 'Pull Request Title' # Access token with `workflow` scope is required token: ${{ secrets.WORKFLOW_SECRET }} # Do not update these actions (Optional) From bfe1d2fb04e9d6efe9c0483fa6aaff2d0190322c Mon Sep 17 00:00:00 2001 From: Max Cotton Date: Sun, 29 May 2022 11:53:05 -0400 Subject: [PATCH 3/6] fix: add variables to init --- main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index a0c0b96..af84b4b 100644 --- a/main.py +++ b/main.py @@ -15,10 +15,12 @@ class GitHubActionsVersionUpdater: github_url = 'https://github.com/' action_label = 'uses' - def __init__(self, repository, base_branch, token, ignore_actions=None): + def __init__(self, repository, base_branch, token, commit_message, pr_title, ignore_actions=None): self.repository = repository self.base_branch = base_branch self.token = token + self.commit_message = commit_message + self.pr_title = pr_title self.ignore_actions = self.get_ignored_actions(ignore_actions) self.workflow_updated = False From dc424e46c1fde9d8db3eb9da79f924b5a8a22d77 Mon Sep 17 00:00:00 2001 From: Max Cotton Date: Sun, 29 May 2022 12:01:59 -0400 Subject: [PATCH 4/6] fix: add args to init --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index af84b4b..0aa1227 100644 --- a/main.py +++ b/main.py @@ -332,7 +332,7 @@ def print_message(message, message_type=None): # Initialize GitHubActionsVersionUpdater actions_version_updater = GitHubActionsVersionUpdater( - repository, base_branch, token, ignore_actions=ignore + repository, base_branch, token, commit_message, pr_title, ignore_actions=ignore ) actions_version_updater.run() From 0d6a9aacde3e6363fd54a6e7b882f8fc84ff4c7e Mon Sep 17 00:00:00 2001 From: Max <38590447+thehedgefrog@users.noreply.github.com> Date: Mon, 6 Jun 2022 09:20:49 -0400 Subject: [PATCH 5/6] fix: apply suggestions from code review Co-authored-by: Maksudul Haque --- main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 0aa1227..64bfc20 100644 --- a/main.py +++ b/main.py @@ -15,12 +15,12 @@ class GitHubActionsVersionUpdater: github_url = 'https://github.com/' action_label = 'uses' - def __init__(self, repository, base_branch, token, commit_message, pr_title, ignore_actions=None): + def __init__(self, repository, base_branch, token, commit_message=None, pr_title=None, ignore_actions=None): self.repository = repository self.base_branch = base_branch self.token = token - self.commit_message = commit_message - self.pr_title = pr_title + self.commit_message = commit_message or 'Update GitHub Action Versions' + self.pr_title = pr_title or 'Update GitHub Action Versions' self.ignore_actions = self.get_ignored_actions(ignore_actions) self.workflow_updated = False @@ -332,7 +332,7 @@ def print_message(message, message_type=None): # Initialize GitHubActionsVersionUpdater actions_version_updater = GitHubActionsVersionUpdater( - repository, base_branch, token, commit_message, pr_title, ignore_actions=ignore + repository, base_branch, token, commit_message=commit_message, pr_title=pr_title, ignore_actions=ignore ) actions_version_updater.run() From c47c62f92ce179a878fc68ba7b3a4e3f98541140 Mon Sep 17 00:00:00 2001 From: Max <38590447+thehedgefrog@users.noreply.github.com> Date: Mon, 11 Jul 2022 10:12:37 -0400 Subject: [PATCH 6/6] Apply suggestions from code review Co-authored-by: Maksudul Haque --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 64bfc20..e4c59b4 100644 --- a/main.py +++ b/main.py @@ -185,7 +185,7 @@ def create_new_branch(self): ) subprocess.run(['git', 'add', '.']) subprocess.run( - ['git', 'commit', '-m', commit_message] + ['git', 'commit', '-m', self.commit_message] ) subprocess.run(['git', 'push', '-u', 'origin', new_branch]) @@ -198,7 +198,7 @@ def create_pull_request(self, branch_name, body): """Create pull request on GitHub""" url = f'{self.github_api_url}/repos/{self.repository}/pulls' payload = { - 'title': pr_title, + 'title': self.pr_title, 'head': branch_name, 'base': self.base_branch, 'body': body,