diff --git a/.github/workflows/cherry-pick-openedx.yml b/.github/workflows/cherry-pick-openedx.yml new file mode 100644 index 0000000000..f4b86bf01d --- /dev/null +++ b/.github/workflows/cherry-pick-openedx.yml @@ -0,0 +1,75 @@ +name: cherry-pick target commit from openedx repo into fork + +on: + workflow_dispatch: + inputs: + targetCommitHash: + description: 'Hash of the target commit to pull into the edX fork' + required: true + type: string + +jobs: + cherry-pick: + name: Cherry pick file + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v5 + + - name: configure git + run: | + git config user.name "${{ github.actor }}" + git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com" + git remote add -f openedx https://github.com/openedx/frontend-app-learning.git + git remote rename origin edx + + - name: check that commit exists and load commit info + id: commit-info + run: | + PRETTY="" + PRETTY+="hash=%h%n" + PRETTY+="commit_subject=%s%n" + PRETTY+="author_name=%an%n" + PRETTY+="author_email=%ae%n" + PRETTY+="date=%ad%n" + + git log -1 --pretty=$PRETTY --remotes=openedx ${{ inputs.targetCommitHash }} >> $GITHUB_OUTPUT + + - name: Cherry pick target commit onto new branch + run: | + BRANCH_NAME="${{ github.actor }}/cherry-pick-${{ steps.commit-info.outputs.hash }}" + git checkout -b $BRANCH_NAME + git cherry-pick ${{ inputs.targetCommitHash }} 2>&1 | tee cherry_pick_output + if [[ ${PIPESTATUS[0]} != 0 ]]; then + echo "## Unable to cherry-pick commit" >> $GITHUB_STEP_SUMMARY + cat cherry_pick_output >> $GITHUB_STEP_SUMMARY + exit 1 + fi + + git push -u edx $BRANCH_NAME 2>&1 | tee push_output + if [[ ${PIPESTATUS[0]} != 0 ]]; then + echo "## Unable to push to branch" >> $GITHUB_STEP_SUMMARY + cat push_output >> $GITHUB_STEP_SUMMARY + exit 1 + fi + + - name: Open pull request + env: + GH_TOKEN: ${{ github.token }} + run: | + BODY=$(cat <<-EOF + This PR cherry-picks commit ${{ steps.commit-info.outputs.hash }} from the openedx repo into the edx fork. + + Author: ${{ steps.commit-info.outputs.author_name }} <${{ steps.commit-info.outputs.author_email }}> + Date: ${{ steps.commit-info.outputs.date }} + EOF + ) + gh pr create --title "${{ steps.commit-info.outputs.commit_subject }}" --body "$BODY" 1> pr_url 2> pr_errors + if [[ $? == 0 ]]; then + echo "## Pull Request Created! 🎉" >> $GITHUB_STEP_SUMMARY + echo $(cat pr_url) >> $GITHUB_STEP_SUMMARY + else + echo "## Pull request creation failed" >> $GITHUB_STEP_SUMMARY + echo $(cat pr_errors) >> $GITHUB_STEP_SUMMARY + exit 1 + fi