Skip to content

ci: implementing migrator workflow #3878

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

Open
wants to merge 62 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
4f956e6
fix: add reaction to issue comments in migrator workflow
germa89 Apr 24, 2025
a35a2be
feat: add workflow_dispatch input for issue number in migrator workflow
germa89 Apr 24, 2025
70ee48a
refactor: simplify PR checkout process in migrator workflow
germa89 Apr 24, 2025
3afcf2d
fix: add missing environment variable for GH_TOKEN in migrator workflow
germa89 Apr 24, 2025
059f03f
feat: add checkout step for PR branch and push to new remote in migra…
germa89 Apr 24, 2025
fde8d26
fix: comment out remote addition and push steps in migrator workflow
germa89 Apr 24, 2025
98cb949
feat: add logging for base ref in migrator workflow
germa89 Apr 24, 2025
0bf47f5
feat: add detailed logging for PR information in migrator workflow
germa89 Apr 24, 2025
639db31
refactor: enhance logging for PR data and update checkout reference i…
germa89 Apr 24, 2025
9c8e0b4
refactor: clean up logging in migrator workflow by removing unnecessa…
germa89 Apr 24, 2025
a3de3a4
fix: update logging to output GitHub event as JSON in migrator workflow
germa89 Apr 24, 2025
1f507ce
feat: add checkout step for PR branch in migrator workflow
germa89 Apr 24, 2025
1f28c74
fix: add GITHUB_TOKEN environment variable for branch checkout in mig…
germa89 Apr 24, 2025
6bf7f25
fix: update checkout step to use 'git status' instead of commented-ou…
germa89 Apr 24, 2025
4f9edc6
refactor: streamline PR migration workflow by removing unused steps a…
germa89 Apr 24, 2025
85ce0c7
refactor: rename job from 'recreate' to 'migrate' and enhance PR hand…
germa89 Apr 30, 2025
4bba7e8
fix: update branch name variable in remote check and push logic
germa89 Apr 30, 2025
306375a
fix: streamline remote branch handling by moving remote name export a…
germa89 Apr 30, 2025
e141039
refactor: enhance PR handling by improving branch existence checks an…
germa89 Apr 30, 2025
58e8448
fix: remove unnecessary environment variable export and improve PR ex…
germa89 Apr 30, 2025
319a5a0
fix: improve formatting of branch existence messages in PR handling
germa89 Apr 30, 2025
e871f0a
fix: update PR creation command to use single quotes for title
germa89 Apr 30, 2025
8d34d7d
fix: update PR creation command to use double quotes for title and im…
germa89 Apr 30, 2025
bc49a08
fix: improve PR creation command by enhancing title and body formatting
germa89 Apr 30, 2025
94278e3
fix: update PR title formatting to use single quotes
germa89 Apr 30, 2025
3e936b1
fix: update PR creation to use body file for improved formatting
germa89 Apr 30, 2025
a8fea79
fix: enhance user output in workflow dispatch and issue comment events
germa89 Apr 30, 2025
0390f07
fix: update GITHUB_TOKEN to use PYANSYS_CI_BOT_TOKEN for branch check…
germa89 Apr 30, 2025
9b4052a
fix: enhance migrator workflow to support sync command and improve br…
germa89 Apr 30, 2025
b9db5c7
fix: add checkout step before configuration in migrator workflow
germa89 Apr 30, 2025
4b031ab
fix: remove conditional check for is_sync in Migrate PR step
germa89 Apr 30, 2025
1254a38
fix: update branch sync messaging in migrator workflow
germa89 Apr 30, 2025
6e32c36
fix: add debug output for remote configuration in migrate PR step
germa89 Apr 30, 2025
c176cd2
fix: add debug output for PR source and GitHub context in migrator wo…
germa89 Apr 30, 2025
752ecfd
fix: update migrator workflow to enhance PR handling and data parsing
germa89 Apr 30, 2025
a947da0
fix: update PR data extraction to use jq for head repo information
germa89 Apr 30, 2025
d6e9fa9
fix: refactor configuration step to streamline output handling and im…
germa89 Apr 30, 2025
1e1adce
fix: enhance migrator workflow to determine PR number and parse PR da…
germa89 Apr 30, 2025
8ad5077
fix: comment out deprecated migration steps in workflow
germa89 Apr 30, 2025
4fe27a5
fix: update PR data extraction to correctly set PR number and branch/…
germa89 Apr 30, 2025
123228d
fix: correct PR number extraction in workflow for issue comments
germa89 Apr 30, 2025
8f91d9d
fix: update PR data extraction to use fromJson for branch and repo de…
germa89 Apr 30, 2025
7db12ee
fix: update PR data extraction to correctly reference head branch and…
germa89 Apr 30, 2025
c749bf6
fix: enhance migration workflow to correctly checkout and push branch…
germa89 Apr 30, 2025
f7c861b
fix: update migration workflow to correctly create PRs and handle com…
germa89 Apr 30, 2025
c884a1b
fix: update user triggering information in workflow for better contex…
germa89 Apr 30, 2025
a6dc8cd
fix: correct user triggering information assignment in workflow
germa89 Apr 30, 2025
24d9c72
fix: update base branch naming convention in migration workflow
germa89 Apr 30, 2025
01797d4
fix: rename variable for clarity in PR number retrieval
germa89 Apr 30, 2025
d8142cb
fix: remove unused input parameter and update base branch naming in m…
germa89 Apr 30, 2025
c2290a9
fix: update reaction to comment from "rocket" to "+1" and add confirm…
germa89 Apr 30, 2025
433ae02
fix: enable pull rebase and update PR creation confirmation message
germa89 Apr 30, 2025
ef4ea67
fix: add merge step before pushing changes in migrator workflow
germa89 Apr 30, 2025
a481183
fix: clean up whitespace and remove commented-out migration steps in …
germa89 Apr 30, 2025
a3afd2d
chore: merge remote-tracking branch 'origin/main' into fix/migrator-w…
germa89 Apr 30, 2025
2e7eb76
chore: adding changelog file 3878.maintenance.md [dependabot-skip]
pyansys-ci-bot Apr 30, 2025
f274517
fix: streamline git commands in migrator workflow by removing error h…
germa89 Apr 30, 2025
0036aec
Merge branch 'fix/migrator-workflow-2' of https://github.com/ansys/py…
germa89 Apr 30, 2025
ee5f300
chore: merge remote-tracking branch 'origin/main' into fix/migrator-w…
germa89 May 7, 2025
8412f3a
fix: enhance migrator workflow to run based on user belonging to a team
germa89 May 7, 2025
03bfc29
fix: enhance merge conflict handling in migrator workflow
germa89 May 7, 2025
dd54c04
Merge branch 'main' into fix/migrator-workflow-2
germa89 May 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 157 additions & 31 deletions .github/workflows/migrator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,188 @@ on:
required: true
type: number

permissions:
contents: write
pull-requests: read

jobs:
recreate:
migrate:
if: |
(
github.event.issue.pull_request != null &&
contains(github.event.comment.body, '@pyansys-ci-bot migrate') &&
github.event.comment.user.login == 'germa89'
(contains(github.event.comment.body, '@pyansys-ci-bot migrate') || contains(github.event.comment.body, '@pyansys-ci-bot sync') )
) || ( github.event_name == 'workflow_dispatch' )
runs-on: ubuntu-latest
steps:
- name: "Configuration"
id: config

- name: Determine PR Number and user triggering the workflow
id: pr_number
run: |
if [[ ${{ github.event_name }} == "workflow_dispatch" ]] ; then
echo "On workflow dispatch"
echo "issue_number=${{ inputs.issue_number }}" >> $GITHUB_OUTPUT
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "PR_NUMBER=${{ github.event.inputs.issue_number }}" >> $GITHUB_ENV
echo "USER_TRIGGERING=${{ github.actor }}" >> $GITHUB_ENV
else
echo "On ${{ github.event_name }}"
echo "issue_number=${{ github.event.issue.number }}" >> $GITHUB_OUTPUT
fi;
echo "PR_NUMBER=${{ github.event.issue.number }}" >> $GITHUB_ENV
echo "USER_TRIGGERING=${{ github.event.comment.user.login }}" >> $GITHUB_ENV
fi

- uses: tspascoal/get-user-teams-membership@v3
id: is_organization_member
with:
username: ${{ env.USER_TRIGGERING }}
organization: ansys
team: 'pymapdl-maintainers'
GITHUB_TOKEN: ${{ secrets.TOKEN_TEAMS_USER_READ }}

- name: React to comment
if : ${{ github.event_name == 'issue_comment' }}
if : ${{ steps.is_organization_member.outputs.isTeamMember == 'true' && github.event_name == 'issue_comment' }}
uses: dkershner6/reaction-action@v2
with:
token: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}
commentId: ${{ github.event.comment.id }} # Optional if the trigger is a comment. Use another action to find this otherwise.
reaction: "rocket"
commentId: ${{ github.event.comment.id }}
reaction: "+1"

- name: Get PR info
- name: React to comment
if : ${{ steps.is_organization_member.outputs.isTeamMember == 'false' && github.event_name == 'issue_comment' }}
uses: dkershner6/reaction-action@v2
with:
token: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}
commentId: ${{ github.event.comment.id }}
reaction: "-1"

- name: Get PR details
id: pr
if : ${{ steps.is_organization_member.outputs.isTeamMember == 'true' }}
uses: octokit/request-action@v2.x
with:
route: GET /repos/${{ github.repository }}/pulls/${{ steps.config.outputs.issue_number }}
route: GET /repos/${{ github.repository }}/pulls/${{ env.PR_NUMBER }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Clone PR branch from fork
- name: Parse PR data
id: extract
if : ${{ steps.is_organization_member.outputs.isTeamMember == 'true' }}
run: |
PR_HEAD_REPO=${{ github.event.pull_request.head.repo.full_name }}
PR_HEAD_REF=${{ steps.pr.outputs.data.head.ref }}
NEW_BRANCH=migrated/pr-${{ steps.config.outputs.issue_number }}
PR_HEAD_BRANCH="${{ fromJson(steps.pr.outputs.data).head.ref }}"
echo "PR_HEAD_BRANCH=$PR_HEAD_BRANCH" >> $GITHUB_ENV

PR_HEAD_REPO="${{ fromJson(steps.pr.outputs.data).head.repo.full_name }}"
echo "PR_HEAD_REPO=$PR_HEAD_REPO" >> $GITHUB_ENV

PR_BASE_BRANCH="migration3/pr-${{ env.PR_NUMBER }}"
echo "PR_BASE_BRANCH=$PR_BASE_BRANCH" >> $GITHUB_ENV
PR_BASE_REPO="${{ github.repository }}"
echo "PR_BASE_REPO=$PR_BASE_REPO" >> $GITHUB_ENV

git clone $PR_HEAD_REPO pr-source
cd pr-source
git checkout $PR_HEAD_REF
- name: Checkout repo
if : ${{ steps.is_organization_member.outputs.isTeamMember == 'true' }}
uses: actions/checkout@v4

- name: Clone head repo and checkout branch
if : ${{ steps.is_organization_member.outputs.isTeamMember == 'true' }}
env:
GITHUB_TOKEN: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}
run: |
git config --global user.name "${{ secrets.PYANSYS_CI_BOT_USERNAME }}"
git config --global user.email "${{ secrets.PYANSYS_CI_BOT_EMAIL}}"
git remote add dest https://x-access-token:${{ secrets.PYANSYS_CI_BOT_TOKEN }}@github.com/${{ github.repository }}.git
git push dest HEAD:refs/heads/$NEW_BRANCH
git config pull.rebase true

echo "Adding ${{ env.PR_HEAD_REPO }} as remote"
git remote add head_repo https://x-access-token:${{ secrets.PYANSYS_CI_BOT_TOKEN }}@github.com/${{ env.PR_HEAD_REPO }}.git

echo "Fetching '${{ env.PR_HEAD_BRANCH }}' branch from '${{ env.PR_HEAD_REPO }}'"
git fetch head_repo ${{ env.PR_HEAD_BRANCH }}
git pull head_repo ${{ env.PR_HEAD_BRANCH }}

echo "Checking out '${{ env.PR_BASE_BRANCH }}' branch from '${{ env.PR_HEAD_REPO }}/${{ env.PR_HEAD_BRANCH }}'"
git checkout -b ${{ env.PR_BASE_BRANCH }} head_repo/${{ env.PR_HEAD_BRANCH }}

echo "Merging '${{ env.PR_HEAD_BRANCH }}' branch into '${{ env.PR_BASE_BRANCH }}'"
git merge head_repo/${{ env.PR_HEAD_BRANCH }}
CONFLICTS=$(git ls-files -u | wc -l)
echo "CONFLICTS=$CONFLICTS"

if [ "$CONFLICTS" -gt 0 ]; then
echo "Merge conflicts detected: $CONFLICTS files"

# Show conflicting files
git status

# Resolve conflicts by taking "theirs" changes (optional, depending on your strategy)
echo "Resolving conflicts by taking 'theirs' changes"
git checkout --theirs .
git add .

# Verify if conflicts are resolved
REMAINING_CONFLICTS=$(git ls-files -u | wc -l)
if [ "$REMAINING_CONFLICTS" -gt 0 ]; then
echo "Error: Conflicts remain after resolution. Aborting."
exit 1
fi
Comment on lines +123 to +132
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Review automatic conflict resolution strategy.

Confirm that automatically using 'git checkout --theirs' won’t discard crucial PR changes.

Suggested implementation:

            # Resolve conflicts by taking "theirs" changes if AUTO_RESOLVE flag is set.
            if [ "$AUTO_RESOLVE" == "true" ]; then
              echo "Auto-resolving conflicts using 'theirs' strategy"
              git checkout --theirs .
              git add .
            else
              echo "Automatic conflict resolution is disabled. Please resolve conflicts manually."
              exit 1
            fi

Ensure that the environment variable AUTO_RESOLVE is defined in your workflow configuration or the environment. This change guarantees that using the "theirs" strategy does not inadvertently discard crucial PR changes without explicit confirmation.


# Continue the merge
git merge --continue || { echo "Merge failed. Aborting."; exit 1; }
else
echo "No merge conflicts detected."
fi

echo "Pushing changes to '${{ env.PR_BASE_REPO }}' repo"
git push origin ${{ env.PR_BASE_BRANCH }} --force-with-lease || { echo "Push failed. Aborting."; exit 1; }

- name: Create new PR
uses: peter-evans/create-pull-request@v7
- name: Opening PR if needed.
if : ${{ steps.is_organization_member.outputs.isTeamMember == 'true' }}
env:
GITHUB_TOKEN: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}
run: |
BASE_PR_NUMBER=$(gh pr list --head ${{ env.PR_BASE_BRANCH }} --state open --json number --jq '.[0].number')
echo "BASE_PR_NUMBER=$BASE_PR_NUMBER" >> $GITHUB_ENV

if [[ -n "$BASE_PR_NUMBER" ]]; then
echo "Open PR exists for branch '${{ env.PR_BASE_BRANCH }}': PR #$BASE_PR_NUMBER"
echo "COMMENT=false" >> $GITHUB_ENV

else
echo "No open PR exists for branch '${{ env.PR_BASE_BRANCH }}'. Creating PR..."
echo "COMMENT=true" >> $GITHUB_ENV

title_pr='chore: migrated PR ${{ env.PR_NUMBER }}'
echo -e "\nThis PR was migrated from a fork to allow secrets to run in workflows. Check the [original PR](https://github.com/${{ github.repository }}/pull/${{ env.PR_NUMBER }}) for more details.\n\nCloses #${{ env.PR_NUMBER }}" > body_pr

NEW_PR=$(gh pr create --head "${{ env.PR_BASE_BRANCH }}" --reviewer ${{ env.USER_TRIGGERING }} --title "$title_pr" --body-file body_pr | grep -o 'github\.com/.*/pull/[0-9]*' | sed -E 's#.*/pull/##')
echo "PR created: $NEW_PR"
echo "BASE_PR_NUMBER=$NEW_PR" >> $GITHUB_ENV

fi;

# Confirm with a reaction
- name: React to comment
if : ${{ steps.is_organization_member.outputs.isTeamMember == 'true' && github.event_name == 'issue_comment' }}
uses: dkershner6/reaction-action@v2
with:
token: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}
commentId: ${{ github.event.comment.id }}
reaction: "rocket"

- name: Create comment
if: ${{ steps.is_organization_member.outputs.isTeamMember == 'true' && env.COMMENT == 'true' }}
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ env.PR_NUMBER}}
body: |
**🚀 Migration completed!**

The PR [#${{ env.BASE_PR_NUMBER }}](https://github.com/${{ github.repository }}/pull/${{ env.BASE_PR_NUMBER }}) has been created successfully.

token: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}

- name: Create comment
if: ${{ steps.is_organization_member.outputs.isTeamMember == 'true' && failure() }}
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ env.PR_NUMBER}}
body: |
**Error**

An error occurred while migrating and syncing the PR. Please check the action logs for more details.

token: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}
title: "Migrated PR #${{ steps.config.outputs.issue_number }}"
body: "This PR was migrated from a fork to allow secrets to run in workflows."
branch: migrated/pr-${{ steps.config.outputs.issue_number }}
base: ${{ steps.pr.outputs.data.base.ref }}
1 change: 1 addition & 0 deletions doc/changelog.d/3878.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ci: implementing migrator workflow
Loading