Repository navigation
feat: add a workflow to create sync PRs #444
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| # Create a PR to sync with the upstream template repo. | ||
| # The template repo is https://github.com/jenstroeger/python-package-template. | ||
|
|
||
| name: Sync with template repository | ||
| on: | ||
| schedule: | ||
| - cron: 11 11 * * * | ||
|
|
||
| permissions: | ||
| contents: read | ||
| env: | ||
| # This is the username and email for the user who creates a branch and commits | ||
| # the changes. In an organisation that should be a dedicated devops account. | ||
| USER_NAME: jenstroeger | ||
| USER_EMAIL: jenstroeger@users.noreply.github.com | ||
|
|
||
| jobs: | ||
| sync: | ||
| if: github.repository != 'jenstroeger/python-package-template' | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| steps: | ||
|
|
||
| - name: Check out template repository | ||
| uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 | ||
| with: | ||
| # If you decide to change the upstream template repository to a private one, uncomment | ||
| # the following argument to pass the required token to be able to check it out. | ||
| # token: ${{ secrets.<TEMPLATE_REPO_TOKEN> }} | ||
| repository: jenstroeger/python-package-template | ||
| fetch-depth: 0 | ||
| path: template | ||
|
|
||
| - name: Check out current repository | ||
| uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 | ||
| with: | ||
| token: ${{ secrets.REPO_ACCESS_TOKEN }} | ||
| fetch-depth: 0 | ||
| ref: main | ||
| path: repo | ||
|
|
||
| - name: Sync with template | ||
| env: | ||
| GH_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} | ||
| run: | | ||
| LATEST_VERSION=$(cd template && git describe --tags --abbrev=0) | ||
| CURRENT_VERSION=$(test -f repo/.github/workflows/.template_version \ | ||
| && cat repo/.github/workflows/.template_version || echo "v0.0.0") | ||
| echo "Latest version is $LATEST_VERSION and current version is $CURRENT_VERSION." | ||
|
|
||
| if [ $CURRENT_VERSION == $LATEST_VERSION ]; then | ||
| echo "Unable to find a new version, exiting..." | ||
| else | ||
|
|
||
| # Copy the files from the template to the current repo. | ||
| rsync --recursive --verbose --verbose --exclude tests/ --exclude src/ \ | ||
| --exclude .git/ --exclude .github/workflows/.template_version template/ repo/ | ||
|
jenstroeger marked this conversation as resolved.
Resolved
|
||
|
|
||
| # Check if the branch exists in the current repo. | ||
| cd repo/ | ||
| if [ $(git rev-parse --verify origin/sync-$LATEST_VERSION 2>/dev/null) ]; then | ||
| echo "Branch sync-$LATEST_VERSION already exists. Exiting..." | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Create a branch, commit, and push the changeset. | ||
| git checkout -b sync-$LATEST_VERSION | ||
| echo $LATEST_VERSION > .github/workflows/.template_version | ||
| git add . | ||
| git config --global user.name $USER_NAME | ||
| git config --global user.email $USER_EMAIL | ||
| git config --list --global # For debug purposes. | ||
| git commit -m "chore: sync with template" | ||
| git push --set-upstream origin sync-$LATEST_VERSION | ||
|
|
||
| # Create the pull request. | ||
| gh pr create --base main --title "chore: sync with package template $LATEST_VERSION" \ | ||
| --body "This PR was automatically generated." --head sync-$LATEST_VERSION | ||
|
jenstroeger marked this conversation as resolved.
Resolved
|
||
| fi | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.