Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -44,7 +44,7 @@ on:
jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
Expand All @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=None, pr_title=None, ignore_actions=None):
self.repository = repository
self.base_branch = base_branch
self.token = token
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

Expand Down Expand Up @@ -183,7 +185,7 @@ def create_new_branch(self):
)
subprocess.run(['git', 'add', '.'])
subprocess.run(
['git', 'commit', '-m', 'Update GitHub Action Versions']
['git', 'commit', '-m', self.commit_message]
)

subprocess.run(['git', 'push', '-u', 'origin', new_branch])
Expand All @@ -196,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': 'Update GitHub Action Versions',
'title': self.pr_title,
'head': branch_name,
'base': self.base_branch,
'body': body,
Expand Down Expand Up @@ -312,6 +314,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']
Comment on lines +318 to +320
Copy link
Copy Markdown
Owner

@saadmk11 saadmk11 May 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should pass these to the GitHubActionsVersionUpdater classes __init__() method, just like ignore input.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am very much a newbie with Python, I will look into this and figure it out :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @saadmk11 - added it but I am not sure it was in the spirit of your suggestion. Let me know and thank you!


# Group: Configure Git
print_message('Configure Git', message_type='group')
Expand All @@ -326,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=commit_message, pr_title=pr_title, ignore_actions=ignore
)
actions_version_updater.run()

Expand Down