diff --git a/.github/workflows/auto_dependency_pr.yml b/.github/workflows/auto_dependency_pr.yml new file mode 100644 index 0000000..4548bc2 --- /dev/null +++ b/.github/workflows/auto_dependency_pr.yml @@ -0,0 +1,101 @@ +name: Sync PR to Main Repo + +on: + workflow_call: + inputs: + base_branch: + type: string + default: "main" + python_versions: + type: string + default: '["3.12"]' + target_repo: + type: string + default: "rr_validation" + reviewers: + type: string + default: "" + +jobs: + update-main: + if: >- + ${{ + github.actor != 'dependabot[bot]' && + github.event.pull_request.user.login != 'dependabot[bot]' + }} + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: ${{ fromJSON(inputs.python_versions) }} + + steps: + - name: Checkout package repo + uses: actions/checkout@v4 + + - name: Generate Token + uses: tibdex/github-app-token@v1 + id: generate-token + with: + app_id: ${{ secrets.REG_APP_ID }} + private_key: ${{ secrets.REG_APP_KEY }} + + - name: Checkout main repo + uses: actions/checkout@v4 + with: + repository: renalreg/${{ inputs.target_repo }} + token: ${{ steps.generate-token.outputs.token }} + path: ${{ inputs.target_repo }} + fetch-depth: 0 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v6 + with: + python-version: "${{ matrix.python-version }}" + + - name: Install Poetry + run: | + python -m pip install --upgrade pip + python -m pip install poetry + + - name: Authenticate GitHub HTTPS for private deps + run: | + git config --global url."https://x-access-token:${{ steps.generate-token.outputs.token }}@github.com/".insteadOf "https://github.com/" + + - name: Update dependency (pin to PR SHA) and lock + run: | + cd ${{ inputs.target_repo }} + PR_SHA="${{ github.event.pull_request.head.sha }}" + SRC_REPO="${{ github.repository }}" + + poetry add --lock "git+https://github.com/${SRC_REPO}.git@${PR_SHA}" + + - name: Create or update PR in the main branch + uses: peter-evans/create-pull-request@v8 + with: + token: ${{ steps.generate-token.outputs.token }} + path: ${{ inputs.target_repo }} + base: ${{ inputs.base_branch }} + branch: bump-${{ github.event.repository.name }}-pr-${{ github.event.pull_request.number }} + commit-message: "[skip ci] Bump ${{ github.event.repository.name }} to PR #${{ github.event.pull_request.number }}" + title: "Bump and test ${{ github.event.repository.name }} PR #${{ github.event.pull_request.number }}" + body: | + Auto-generated PR to test changes from: + - Source PR: ${{ github.event.pull_request.html_url }} + - Source SHA: `${{ github.event.pull_request.head.sha }}` + - Package repo: `${{ github.repository }}` + + ## What this PR does + This PR pins `${{ github.event.repository.name }}` to the PR SHA above and updates `poetry.lock`. + + ## What to do next + 1. Review the dependencies + 2. Run CI and check that it passes + 3. Pull locally and build/run + + ## How to merge + - Merge only after the source PR is approved and ready. + - Alternatively, close this PR once the source PR is merged. + committer: bob-dependency-bot + author: bob-dependency-bot + reviewers: ${{ inputs.reviewers || '' }} diff --git a/README.md b/README.md index 200b2c7..1722100 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ You can also copy and paste the templates into any repo you wish without the nee - **UKKA Python File Checker** - **UKKA Conventional PR Title** - **UKKA Auto Pull Requests** +- **UKKA Auto Dependency Pull Requests** @@ -178,6 +179,34 @@ Automates the creation and management of pull requests, including branch name ex - [**actions/checkout**](https://github.com/actions/checkout) - [**tibdex/github-app-token**](https://github.com/tibdex/github-app-token) + + +## Auto Dependency PR + +This action automates the creation of PR in repository B, whenever a PR is created in repository A, designed for cases when A is a dependency of B. Runs whenever a PR is opened or changed (e.g., has new commits added to it). + +**Example Options** + +```yaml +with: + + python_versions: '["3.10", "3.11"]' + # Description: Python versions to test against + # Default: lowest supported Python version + + base_branch: "main" + # Description: Name of the base branch in target repo (generally main or master) + # Default: "main" + + target_repo: "rr_validation" + # Description: Name of the target repo to create PR in (e.g. rr_validation) + # Default: "rr_validation" + + reviewers: "GlebRysev-UKKA" + # Description: GitHub username of a PR reviewer + # Default: "" (no reviewers) +``` + ## Python Test Gen A reusable workflow for running tests with configurable Python versions and OS matrix. Intended to be called by other workflows. diff --git a/workflow-templates/auto_dependency_pr.properties.json b/workflow-templates/auto_dependency_pr.properties.json new file mode 100644 index 0000000..01ff040 --- /dev/null +++ b/workflow-templates/auto_dependency_pr.properties.json @@ -0,0 +1,4 @@ +{ + "name": "UKKA Auto Dependency Pull Requests", + "description": "!!Experimental!! Automatically creates a pull request in another repo when PR is created in a current one." +} \ No newline at end of file diff --git a/workflow-templates/auto_dependency_pr.yml b/workflow-templates/auto_dependency_pr.yml new file mode 100644 index 0000000..c5be059 --- /dev/null +++ b/workflow-templates/auto_dependency_pr.yml @@ -0,0 +1,37 @@ + +name: Sync PR to Main Repo + +on: + pull_request: + # Fire when PR is opened and updated + types: [opened, synchronize, reopened] + + workflow_dispatch: + +jobs: + call-workflow: + name: Sync PR to Main Repo + if: ${{ !startsWith(github.head_ref, 'release-please--') }} + uses: renalreg/.github/.github/workflows/auto_dependency_pr.yml@main + secrets: inherit + + # # Optional configuration. + # # Uncomment and adjust as required. + # + # with: + # + # python_versions: '["3.10", "3.11"]' + # # Description: Python versions to test against + # # Default: lowest supported Python version + # + # base_branch: "main" + # # Description: Name of the base branch in target repo (generally main or master) + # # Default: "main" + # + # target_repo: "rr_validation" + # # Description: Name of the target repo to create PR in (e.g. rr_validation) + # # Default: "rr_validation" + # + # reviewers: "GlebRysev-UKKA" + # # Description: GitHub username of a PR reviewer + # # Default: "" (no reviewers) \ No newline at end of file