testing #36
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: Sync Changes to Farajaland | |
on: | |
pull_request: | |
types: | |
- closed | |
jobs: | |
sync_farajaland: | |
if: ${{ github.event.pull_request.merged == true }} | |
runs-on: ubuntu-latest | |
env: | |
BASE_BRANCH: ${{ github.event.pull_request.base.ref }} | |
GH_TOKEN: ${{ secrets.FORK_ORGANISATION_TOKEN }} | |
FORK_ORGANISATION: ${{ secrets.FORK_REPOSITORY_ORGANISATION }} | |
FORK_REPOSITORY_NAME: ${{ secrets.FORK_REPOSITORY_NAME }} | |
FORK_REPOSITORY_PATH: "${{ secrets.FORK_REPOSITORY_ORGANISATION }}/${{ secrets.FORK_REPOSITORY_NAME }}" | |
steps: | |
- name: Check if PR branch exists in Farajaland repository | |
id: check_branch | |
run: | | |
if git ls-remote --heads https://${GH_TOKEN}@github.com/${FORK_REPOSITORY_PATH}.git "$BASE_BRANCH" | grep "$BASE_BRANCH"; then | |
echo "branch_exists=true" >> $GITHUB_ENV | |
else | |
echo "==============================================" | |
echo " 🚀 Branch $BASE_BRANCH doesn't exist in repository ${FORK_REPOSITORY_PATH}" | |
echo " 🚪 Doing exit" | |
echo "==============================================" | |
echo "branch_exists=false" >> $GITHUB_ENV | |
fi | |
- name: Sync Farajaland forked repository | |
id: sync_fork | |
if: env.branch_exists == 'true' | |
continue-on-error: true | |
run: | | |
gh repo sync ${FORK_REPOSITORY_PATH} --branch ${BASE_BRANCH} | |
- uses: actions/checkout@v4 | |
with: | |
repository: ${{ secrets.FORK_REPOSITORY_ORGANISATION }}/${{ secrets.FORK_REPOSITORY_NAME }} | |
# TODO: replace https://github.com/opencrvs/poc-core-test.git with git variable | |
- run: | | |
git remote add upstream https://github.com/opencrvs/poc-core-test.git | |
git fetch upstream ${{ github.event.pull_request.base.ref }} | |
- name: Create Pull Request | |
if: steps.sync_fork.outcome == 'failure' | |
uses: peter-evans/create-pull-request@v7 | |
with: | |
token: ${{ secrets.FORK_ORGANISATION_TOKEN }} | |
branch: upstream-changes |