Skip to content

Commit

Permalink
Merge pull request #21437 from Expensify/Rory-FixCPLookingForVersionBump
Browse files Browse the repository at this point in the history
[No QA] Fix cp looking for version bump
  • Loading branch information
luacmartins authored Jun 23, 2023
2 parents 5200aaf + 4f5e877 commit 5b04440
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 160 deletions.
3 changes: 0 additions & 3 deletions .github/actions/javascript/getPullRequestDetails/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ inputs:
PULL_REQUEST_NUMBER:
description: The number of the pull request
required: false
TITLE_REGEX:
description: Regex to match PR titles for
required: false
USER:
description: The creator of the pull request
required: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const DEFAULT_PAYLOAD = {

const pullRequestNumber = ActionUtils.getJSONInput('PULL_REQUEST_NUMBER', {required: false}, null);
const user = core.getInput('USER', {required: true});
let titleRegex = core.getInput('TITLE_REGEX', {required: false});

if (pullRequestNumber) {
console.log(`Looking for pull request w/ number: ${pullRequestNumber}`);
Expand All @@ -21,11 +20,6 @@ if (user) {
console.log(`Looking for pull request w/ user: ${user}`);
}

if (titleRegex) {
titleRegex = new RegExp(titleRegex);
console.log(`Looking for pull request w/ title matching: ${titleRegex.toString()}`);
}

/**
* Output pull request merge actor.
*
Expand All @@ -52,69 +46,26 @@ function outputForkedRepoUrl(PR) {
}
}

/**
* Output pull request data.
*
* @param {Object} PR
*/
function outputPullRequestData(PR) {
core.setOutput('MERGE_COMMIT_SHA', PR.merge_commit_sha);
core.setOutput('HEAD_COMMIT_SHA', PR.head.sha);
core.setOutput('IS_MERGED', PR.merged);
outputMergeActor(PR);
outputForkedRepoUrl(PR);
}

/**
* Process a pull request and output its data.
*
* @param {Object} PR
*/
function processPullRequest(PR) {
if (!_.isEmpty(PR)) {
console.log(`Found matching pull request: ${PR.html_url}`);
outputPullRequestData(PR);
} else {
const err = new Error('Could not find matching pull request');
console.error(err);
GithubUtils.octokit.pulls
.get({
...DEFAULT_PAYLOAD,
pull_number: pullRequestNumber,
})
.then(({data: PR}) => {
if (!_.isEmpty(PR)) {
console.log(`Found matching pull request: ${PR.html_url}`);
core.setOutput('MERGE_COMMIT_SHA', PR.merge_commit_sha);
core.setOutput('HEAD_COMMIT_SHA', PR.head.sha);
core.setOutput('IS_MERGED', PR.merged);
outputMergeActor(PR);
outputForkedRepoUrl(PR);
} else {
const err = new Error('Could not find matching pull request');
console.error(err);
core.setFailed(err);
}
})
.catch((err) => {
console.log(`An unknown error occurred with the GitHub API: ${err}`);
core.setFailed(err);
}
}

/**
* Handle an unknown API error.
*
* @param {Error} err
*/
function handleUnknownError(err) {
console.log(`An unknown error occurred with the GitHub API: ${err}`);
core.setFailed(err);
}

if (pullRequestNumber) {
GithubUtils.octokit.pulls
.get({
...DEFAULT_PAYLOAD,
pull_number: pullRequestNumber,
})
.then(({data}) => {
processPullRequest(data);
})
.catch(handleUnknownError);
} else {
GithubUtils.octokit.pulls
.list({
...DEFAULT_PAYLOAD,
state: 'all',
})
.then(({data}) => _.find(data, (PR) => PR.user.login === user && titleRegex.test(PR.title)).number)
.then((matchingPRNum) =>
GithubUtils.octokit.pulls.get({
...DEFAULT_PAYLOAD,
pull_number: matchingPRNum,
}),
)
.then(({data}) => {
processPullRequest(data);
});
}
});
93 changes: 22 additions & 71 deletions .github/actions/javascript/getPullRequestDetails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const DEFAULT_PAYLOAD = {

const pullRequestNumber = ActionUtils.getJSONInput('PULL_REQUEST_NUMBER', {required: false}, null);
const user = core.getInput('USER', {required: true});
let titleRegex = core.getInput('TITLE_REGEX', {required: false});

if (pullRequestNumber) {
console.log(`Looking for pull request w/ number: ${pullRequestNumber}`);
Expand All @@ -31,11 +30,6 @@ if (user) {
console.log(`Looking for pull request w/ user: ${user}`);
}

if (titleRegex) {
titleRegex = new RegExp(titleRegex);
console.log(`Looking for pull request w/ title matching: ${titleRegex.toString()}`);
}

/**
* Output pull request merge actor.
*
Expand All @@ -62,72 +56,29 @@ function outputForkedRepoUrl(PR) {
}
}

/**
* Output pull request data.
*
* @param {Object} PR
*/
function outputPullRequestData(PR) {
core.setOutput('MERGE_COMMIT_SHA', PR.merge_commit_sha);
core.setOutput('HEAD_COMMIT_SHA', PR.head.sha);
core.setOutput('IS_MERGED', PR.merged);
outputMergeActor(PR);
outputForkedRepoUrl(PR);
}

/**
* Process a pull request and output its data.
*
* @param {Object} PR
*/
function processPullRequest(PR) {
if (!_.isEmpty(PR)) {
console.log(`Found matching pull request: ${PR.html_url}`);
outputPullRequestData(PR);
} else {
const err = new Error('Could not find matching pull request');
console.error(err);
GithubUtils.octokit.pulls
.get({
...DEFAULT_PAYLOAD,
pull_number: pullRequestNumber,
})
.then(({data: PR}) => {
if (!_.isEmpty(PR)) {
console.log(`Found matching pull request: ${PR.html_url}`);
core.setOutput('MERGE_COMMIT_SHA', PR.merge_commit_sha);
core.setOutput('HEAD_COMMIT_SHA', PR.head.sha);
core.setOutput('IS_MERGED', PR.merged);
outputMergeActor(PR);
outputForkedRepoUrl(PR);
} else {
const err = new Error('Could not find matching pull request');
console.error(err);
core.setFailed(err);
}
})
.catch((err) => {
console.log(`An unknown error occurred with the GitHub API: ${err}`);
core.setFailed(err);
}
}

/**
* Handle an unknown API error.
*
* @param {Error} err
*/
function handleUnknownError(err) {
console.log(`An unknown error occurred with the GitHub API: ${err}`);
core.setFailed(err);
}

if (pullRequestNumber) {
GithubUtils.octokit.pulls
.get({
...DEFAULT_PAYLOAD,
pull_number: pullRequestNumber,
})
.then(({data}) => {
processPullRequest(data);
})
.catch(handleUnknownError);
} else {
GithubUtils.octokit.pulls
.list({
...DEFAULT_PAYLOAD,
state: 'all',
})
.then(({data}) => _.find(data, (PR) => PR.user.login === user && titleRegex.test(PR.title)).number)
.then((matchingPRNum) =>
GithubUtils.octokit.pulls.get({
...DEFAULT_PAYLOAD,
pull_number: matchingPRNum,
}),
)
.then(({data}) => {
processPullRequest(data);
});
}
});


/***/ }),
Expand Down
17 changes: 7 additions & 10 deletions .github/workflows/cherryPick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,15 @@ jobs:
echo "New version is ${{ env.NEW_VERSION }}"
fi;
- name: Get merge commit for version-bump pull request
id: getVersionBumpMergeCommit
uses: Expensify/App/.github/actions/javascript/getPullRequestDetails@main
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
USER: OSBotify
TITLE_REGEX: Update version to ${{ env.NEW_VERSION }}

- name: Cherry-pick the version-bump to staging
run: |
git fetch main
git cherry-pick -S -x --mainline 1 --strategy=recursive -Xtheirs ${{ steps.getVersionBumpMergeCommit.outputs.MERGE_COMMIT_SHA }}
# Find the commit for the version-bump
git switch main
VERSION_BUMP_COMMIT="$(git log --format='%H' --author='OSBotify' --grep 'Update version to ${{ env.NEW_VERSION }}')"
# Cherry-pick it to staging
git switch staging
git cherry-pick -S -x --mainline 1 --strategy=recursive -Xtheirs "$VERSION_BUMP_COMMIT"
- name: Cherry-pick the merge commit of target PR
id: cherryPick
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/e2ePerformanceTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ jobs:
with:
GITHUB_TOKEN: ${{ github.token }}
PULL_REQUEST_NUMBER: ${{ inputs.PR_NUMBER }}
user: ${{ github.actor }}
USER: ${{ github.actor }}

- name: Merged PR - Get merge commit sha for the pull request
if: ${{ fromJSON(steps.getPullRequestDetails.outputs.IS_MERGED) }}
id: getMergeCommitShaIfMergedPR
run: |
echo "MERGE_COMMIT_SHA=${{ steps.getPullRequestDetails.outputs.MERGE_COMMIT_SHA }}" >> "$GITHUB_OUTPUT"
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Unmerged PR - Fetch changes from forked repository if necessary
if: ${{ !fromJSON(steps.getPullRequestDetails.outputs.IS_MERGED) && (steps.getPullRequestDetails.outputs.FORKED_REPO_URL != '') }}
run: |
Expand All @@ -89,7 +89,7 @@ jobs:
run: |
git config --global user.email "test@test.com"
git config --global user.name "Test"
- name: Unmerged PR - Merge pull request locally and get merge commit sha
if: ${{ !fromJSON(steps.getPullRequestDetails.outputs.IS_MERGED) }}
id: getMergeCommitShaIfUnmergedPR
Expand Down Expand Up @@ -197,4 +197,4 @@ jobs:
echo '✅ no performance regression detected'
fi
env:
GITHUB_TOKEN: ${{ github.token }}
GITHUB_TOKEN: ${{ github.token }}

0 comments on commit 5b04440

Please sign in to comment.