Cherry-pick CE commit PR from Enterprise to OSS #160
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
name: Cherry-pick CE commit PR from Enterprise to OSS | |
on: | |
schedule: | |
- cron: "0 0 * * *" # Runs daily at midnight | |
workflow_dispatch: | |
jobs: | |
cherry-pick-ce-commits: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout OSS repo | |
uses: actions/checkout@v2 | |
with: | |
repository: Multiwoven/multiwoven | |
ref: main | |
- name: Set up SSH | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Configure Git | |
run: | | |
git config --global user.name 'ai-squared' | |
git config --global user.email '[email protected]' | |
- name: Add enterprise remote | |
run: | | |
git remote add enterprise [email protected]:Multiwoven/multiwoven-ee.git | |
git fetch enterprise | |
- name: Get previous day date | |
id: prev-date | |
run: | | |
PREV_DATE=$(date -d "yesterday" +'%Y-%m-%d') | |
echo "::set-output name=date::$PREV_DATE" | |
- name: Authenticate GitHub CLI | |
run: | | |
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token | |
- name: Create PRs for each CE commit | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
PREV_DATE=${{ steps.prev-date.outputs.date }} | |
git log enterprise/main --since="$PREV_DATE 00:00" --until="$PREV_DATE 23:59" --grep="(CE)" --format="%H" --no-merges | while read sha; do | |
AUTHOR_NAME=$(git log -1 --pretty=format:'%an' $sha) | |
AUTHOR_EMAIL=$(git log -1 --pretty=format:'%ae' $sha) | |
COMMIT_MESSAGE=$(git log -1 --pretty=format:'%s' $sha) | |
BRANCH_NAME="cherry-pick-ce-commit-${sha}" | |
git checkout -b $BRANCH_NAME | |
git cherry-pick $sha || { | |
echo "Conflict in commit $sha, resolving manually." | |
git add . | |
git commit -am "Resolve conflict in cherry-pick of $sha and change the commit message" | |
} | |
git push --force --set-upstream origin $BRANCH_NAME | |
PR_TITLE="${COMMIT_MESSAGE}" | |
PR_BODY="This PR cherry-picks the CE commit ${sha} from the Enterprise repository. Commit author: ${AUTHOR_NAME} (${AUTHOR_EMAIL})" | |
AUTHOR_GH_USERNAME=$(gh api graphql -f query='query { search(query: "${AUTHOR_EMAIL}", type: USER, first: 1) { nodes { ... on User { login } } } }' -q '.data.search.nodes[0].login') | |
if [ -n "$AUTHOR_GH_USERNAME" ]; then | |
PR_BODY="${PR_BODY}\n\ncc @${AUTHOR_GH_USERNAME}" | |
gh pr create --title "$PR_TITLE" --body "$PR_BODY" --base main --head $BRANCH_NAME --assignee "$AUTHOR_GH_USERNAME" | |
else | |
gh pr create --title "$PR_TITLE" --body "$PR_BODY" --base main --head $BRANCH_NAME | |
fi | |
git checkout main | |
git branch -D $BRANCH_NAME | |
done | |
on_failure: | |
environment: staging | |
if: ${{ failure() }} | |
needs: [ cherry-pick-ce-commits ] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Report error to AppSignal | |
env: | |
ACTION: Sync Commits | |
APPSIGNAL_PUSH_API_KEY: ${{ secrets.APPSIGNAL_PUSH_API_KEY }} | |
MESSAGE: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
NAME: Sync Commits from EE to CE failed | |
run: | | |
EPOCH=$(date +%s) | |
curl -verbose -H \"Content-Type: application/json\" \ | |
-d "{ \"action\": \"$ACTION\", \"timestamp\": $EPOCH, \"namespace\": \"github\", \"error\": { \"name\": $NAME, \"message\": $MESSAGE } }" \ | |
-X POST \ | |
https://appsignal-endpoint.net/errors?api_key=$APPSIGNAL_PUSH_API_KEY |