Update Node.js Adapter Version #2
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: Update Node.js Adapter Version | |
on: | |
workflow_dispatch: | |
inputs: | |
new_version: | |
description: "New Node.js adapter version to update" | |
required: true | |
type: string | |
jobs: | |
update-nodejs-adapter-version: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Get current Node.js adapter version | |
id: get-current-version | |
run: | | |
CURRENT_NODEJS_VERSION=$(grep -oP '"keycloak-connect": "\K[^"]+' nodejs/resource-server/package.json) | |
echo "Current version: $CURRENT_NODEJS_VERSION" | |
echo "CURRENT_NODEJS_VERSION=$CURRENT_NODEJS_VERSION" >> $GITHUB_ENV | |
- name: Check version difference | |
id: check-version | |
run: | | |
if [ "${{ github.event.inputs.new_version }}" = "$CURRENT_NODEJS_VERSION" ]; then | |
echo "The version is already up-to-date." | |
echo "update_needed=false" >> $GITHUB_ENV | |
else | |
echo "A version update is needed." | |
echo "update_needed=true" >> $GITHUB_ENV | |
fi | |
- name: Update Node.js adapter version | |
if: env.update_needed == 'true' | |
run: | | |
NEW_VERSION=${{ github.event.inputs.new_version }} | |
echo "Updating Node.js adapter to version $NEW_VERSION" | |
sed -i 's|"keycloak-connect": "[^"]*"|"keycloak-connect": "'"$NEW_VERSION"'"|g' nodejs/resource-server/package.json | |
- name: Configure Git | |
if: env.update_needed == 'true' | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Commit and push changes | |
if: env.update_needed == 'true' | |
run: | | |
git add nodejs/resource-server/package.json | |
git commit -m "Update Node.js adapter version to ${{ github.event.inputs.new_version }}" | |
git push origin main |