Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MINOR: Create GitHub action to update NOTICE file automatically every year #18380

Open
wants to merge 22 commits into
base: trunk
Choose a base branch
from

Conversation

divijvaidya
Copy link
Contributor

@divijvaidya divijvaidya commented Jan 2, 2025

Change

Create a GitHub action that will update the copyright year automatically in the NOTICE file.

Testing

Tested the workflow in my fork which generated the PR divijvaidya#4

Permissions required

This action requires the following permissions:

  1. Actions Permissions > Allow actions created by GitHub (We should already have permission 1 because we use it in our existing workflows)
  2. Workflow Permissions > Read and write permissions (I need to check with Apache infra if we have "Workflows have read and write permissions in the repository for all scopes." permission enabled or not)

Reference

Apache Infra github actions policy - https://infra.apache.org/github-actions-policy.html. I have read through this and looks like we should be good here with this script. Please review again in case I missed something.

@github-actions github-actions bot added triage PRs from the community build Gradle build or GitHub Actions small Small PRs labels Jan 2, 2025
@divijvaidya
Copy link
Contributor Author

@mumrah would you like to take a look at this since you are familiar with the workflows for our repository.

@divijvaidya divijvaidya mentioned this pull request Jan 2, 2025
3 tasks
@divijvaidya divijvaidya marked this pull request as draft January 2, 2025 17:43
@divijvaidya divijvaidya marked this pull request as ready for review January 2, 2025 17:55
@divijvaidya divijvaidya requested a review from mumrah January 2, 2025 17:56
Comment on lines +28 to +29
contents: write
pull-requests: write
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note for reviewers

context: write is required to push commit to the new branch created below
pull-requests: write is required to create a pull request

Copy link
Member

@mumrah mumrah left a comment

Choose a reason for hiding this comment

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

Thanks @divijvaidya! Some comments inline.

run: |
git config user.name "github-actions"
git config user.email "[email protected]"
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository_owner }}/${{ github.event.repository.name }}.git
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need this. Check how we're updating the test-catalog branch here https://github.com/apache/kafka/blob/trunk/.github/workflows/build.yml#L269-L284

Also see the "magic" user.email in that code. I think this is still needed for commit to be correctly associated with the github actions bot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The link you provided uses persist-credentials: true which is not recommended by apache as per https://cwiki.apache.org/confluence/display/BUILDS/GitHub+Actions+Security

if using the 'checkout' action, always enable persist-credentials: false

Since, we use persist-credentials: false, we need a way to provide credential during git push for this action. That is why I used this alternative approach of setting origin with credentials.

I will change the user.email and user.name to the "magic" user mentioned at https://github.com/actions/checkout?tab=readme-ov-file#push-a-commit-using-the-built-in-token

Copy link
Member

Choose a reason for hiding this comment

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

I think setting the origin URL like this is essentially the same as persisting the credentials. However, I think either this approach or persist-credentials: true is fine for this workflow since it's not running any user code (like a PR).

.github/workflows/cron-update-new-year-copyright.yml Outdated Show resolved Hide resolved
base: "trunk",
body: `This PR is auto-generated to update the NOTICE file on Jan 1st every year.`
});
core.info(`Pull Request created: #${response.data.number}`);
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a label like needs-attention maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

woudn't the existing logic to add the label needs-attention after a few days on this PR?

.github/workflows/cron-update-new-year-copyright.yml Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the triage PRs from the community label Jan 3, 2025
@divijvaidya
Copy link
Contributor Author

@mumrah ready for review again

@slachiewicz
Copy link
Member

All this code, automation to update year in one file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Gradle build or GitHub Actions small Small PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants