Merge Python Requirements Upgrade PRs #170
This file contains 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
# This file contains a workflow which will be run on schedule every day, | |
# or can be call from other workflows and | |
# will collect all the eligible (PRs which are labelled "Ready to merge" by our | |
# script) python upgrade PRs from openedx or edx org. | |
# After fetching all PRs, it will check if all the checks passing on the PR, if yes | |
# then it will merge that PR, otherwise it will fail. | |
# Note: | |
# When workflow triggered from this repo(under openedx) will merge only openedx PRs | |
# and will merge edx orgs' PRs only when it will be called from the edx/.github repo | |
name: Merge Python Requirements Upgrade PRs | |
on: | |
workflow_call: | |
secrets: | |
REQUIREMENTS_BOT_GITHUB_TOKEN: | |
description: "Github token with read/write access used to merge PRs" | |
required: true | |
inputs: | |
ORG_NAME: | |
description: "Organisation name to merge PRs for, default openedx" | |
type: string | |
schedule: | |
# will run the job at 10 AM every day (UTC), | |
# https://crontab.guru/#0_10_*_*_* | |
- cron: "0 10 * * *" | |
workflow_dispatch: | |
jobs: | |
get_list_of_prs: | |
name: Get list of PRs | |
runs-on: ubuntu-20.04 | |
outputs: | |
urls: ${{ steps.generate_urls.outputs.urls }} | |
steps: | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.8' | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Install dependencies | |
run: pip install requests | |
- name: Download script file | |
# Only download the script file if the repository is not openedx/.github | |
# Because, we were not able to download correctly outside of openedx due to calling reusable workflow call | |
if: ${{ github.repository != 'openedx/.github' }} | |
run: | | |
mkdir -p scripts | |
curl -o scripts/get_ready_to_merge_prs.py https://raw.githubusercontent.com/openedx/.github/master/scripts/get_ready_to_merge_prs.py | |
- name: Get urls of all eligible prs | |
env: | |
GIT_TOKEN: ${{ secrets.requirements_bot_github_token }} | |
id: generate_urls | |
run: | | |
echo "urls=$(python scripts/get_ready_to_merge_prs.py ${{ inputs.ORG_NAME || 'openedx' }})" >> $GITHUB_OUTPUT | |
merge_pr: | |
runs-on: ubuntu-20.04 | |
needs: | |
- get_list_of_prs | |
if: needs.get_list_of_prs.outputs.urls != '[]' # Skip if there are no URLs found | |
strategy: | |
fail-fast: false | |
matrix: | |
url: ${{ fromJSON(needs.get_list_of_prs.outputs.urls) }} | |
steps: | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.8' | |
- name: Checkout tools repo | |
uses: actions/checkout@v4 | |
with: | |
repository: openedx/tubular | |
path: tubular | |
- name: Setup tubular | |
run: | | |
cd tubular | |
pip install -e . | |
- name: Extract parameters from URL | |
run: | | |
url="${{ matrix.url }}" | |
# Extract the parameters | |
org_name=$(echo $url | awk -F/ '{print $4}') | |
repo_name=$(echo $url | awk -F/ '{print $5}') | |
pr_number=$(echo $url | awk -F/ '{print $7}') | |
# store for next steps | |
echo "org_name=${org_name}" >> $GITHUB_ENV | |
echo "repo_name=${repo_name}" >> $GITHUB_ENV | |
echo "pr_number=${pr_number}" >> $GITHUB_ENV | |
#print out | |
echo "Organization: $org_name" | |
echo "Repo: $repo_name" | |
echo "PR: $pr_number" | |
- name: Check test status of pr | |
env: | |
GIT_TOKEN: ${{ secrets.requirements_bot_github_token }} | |
run: | | |
check_pr_tests_status.py --org "${{ env.org_name }}" --repo "${{ env.repo_name }}" --pr_number \ | |
"${{ env.pr_number }}" --exclude-contexts 'Renovate|[Cc]odecov|Dependabot|edx-platform-ci' --all-checks | |
- name: Merge pull request | |
env: | |
GIT_TOKEN: ${{ secrets.requirements_bot_github_token }} | |
run: | | |
merge_pr.py --org "${{ env.org_name }}" --repo "${{ env.repo_name }}" --pr_number "${{ env.pr_number }}" | |