Skip to content

Sync with Keycloak Server and send PR with changes #1

Sync with Keycloak Server and send PR with changes

Sync with Keycloak Server and send PR with changes #1

name: Sync with Keycloak Server and send PR with changes
on:
workflow_dispatch:
jobs:
sync:
runs-on: ubuntu-latest
env:
REPO_HEAD: "keycloak"
KEYCLOAK_CLIENT_BRANCH: "main"
steps:
- name: Find latest Keycloak release branch
id: latest_release
run: |
LATEST_RELEASE=$(git ls-remote --heads https://github.com/keycloak/keycloak.git 'release/*' | awk -F'/' '{print $NF}' | sort -V | tail -n1)
echo "KEYCLOAK_RELEASE_BRANCH_NAME=release/$LATEST_RELEASE" >> $GITHUB_ENV
- name: Checkout Keycloak latest release
uses: actions/checkout@v4
with:
repository: keycloak/keycloak
ref: ${{ env.KEYCLOAK_RELEASE_BRANCH_NAME }}
- name: Build Keycloak
uses: ./.github/actions/build-keycloak
- name: Checkout Keycloak Client
uses: actions/checkout@v4
with:
repository: ${{ env.REPO_HEAD }}/keycloak-client
ref: ${{ env.KEYCLOAK_CLIENT_BRANCH }}
- name: Build Keycloak Client
uses: ./.github/actions/build-keycloak-client
- name: Sync Keycloak sources
run: ./.github/scripts/sync-keycloak-sources.sh
- name: Config git and GitHub CLI
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Check for changes in client-common-synced
id: changes_check
run: |
if [ -z "$(git status --porcelain client-common-synced)" ]; then
echo "No changes detected in client-common-synced, stopping the workflow."
echo "CHANGES_CHECK=false" >> $GITHUB_ENV
else
echo "CHANGES_CHECK=true" >> $GITHUB_ENV
fi
- name: Create and push new branch
if: env.CHANGES_CHECK == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BRANCH_NAME="sync-with-keycloak-server-${{ env.KEYCLOAK_RELEASE_BRANCH_NAME }}"
git checkout -b $BRANCH_NAME
git add client-common-synced
git commit -m "Sync with Keycloak server release branch ${{ env.KEYCLOAK_RELEASE_BRANCH_NAME }}" --author="${GITHUB_ACTOR} <${GITHUB_ACTOR}@users.noreply.github.com>"
git push --set-upstream origin $BRANCH_NAME
- name: Create pull request with gh CLI
if: env.CHANGES_CHECK == 'true'
run: |
PR_TITLE="Sync with Keycloak server ${{ env.KEYCLOAK_RELEASE_BRANCH_NAME }} branch"
PR_BODY="This PR syncs keycloak-client with the latest Keycloak release branch ${{ env.KEYCLOAK_RELEASE_BRANCH_NAME }}"
gh pr create --base main --head "$BRANCH_NAME" --title "$PR_TITLE" --body "$PR_BODY"