Update Compose File #1047
This file contains hidden or 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 Compose File | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| service: | |
| required: true | |
| type: string | |
| version: | |
| required: true | |
| type: string | |
| branch: | |
| required: true | |
| type: string | |
| workflow_call: | |
| inputs: | |
| service: | |
| required: true | |
| type: string | |
| version: | |
| required: true | |
| type: string | |
| branch: | |
| required: true | |
| type: string | |
| jobs: | |
| update-compose: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout target branch | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.event.inputs.branch }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: actions/create-github-app-token@v1 | |
| name: Generate GitHub token | |
| id: app-token | |
| with: | |
| app-id: ${{ vars.PROTEGEPROJECT_BOT_APP_ID }} | |
| private-key: ${{ secrets.PROTEGEPROJECT_BOT_APP_PRIVATE_KEY }} | |
| - name: Update docker-compose image tag | |
| id: update-compose | |
| run: | | |
| SERVICE="${{ github.event.inputs.service }}" # Use the input parameter 'service' | |
| VERSION="${{ github.event.inputs.version }}" # Use the input parameter 'version' | |
| FILE=docker-compose.yml | |
| echo "Updating service '$SERVICE' to version '$VERSION' in $FILE" | |
| # Save the original file checksum | |
| cp "$FILE" "$FILE.bak" | |
| # Attempt to update the image line | |
| sed -i "s|\(image: protegeproject/$SERVICE:\)[^[:space:]]*|\1$VERSION|" "$FILE" | |
| echo "Result:" | |
| grep "image: protegeproject/$SERVICE" "$FILE" || echo "No matching image line found." | |
| # Check if the file was actually changed | |
| if cmp -s "$FILE" "$FILE.bak"; then | |
| echo "No change made to docker-compose.yml." | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "docker-compose.yml updated." | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Set up SSH | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.WEBPROTEGE_BUMP_KEY }}" > ~/.ssh/id_ed25519 | |
| chmod 600 ~/.ssh/id_ed25519 | |
| ssh-keyscan github.com >> ~/.ssh/known_hosts | |
| - name: Commit and push changes | |
| if: steps.update-compose.outputs.changed == 'true' | |
| run: | | |
| git config user.name "webprotege-bot" | |
| git config user.email "webprotege@users.noreply.github.com" | |
| git add docker-compose.yml | |
| git commit -m "chore: bump ${{ github.event.inputs.service }} to ${{ github.event.inputs.version }}" | |
| git remote set-url origin git@github.com:protegeproject/webprotege-deploy.git | |
| git push origin ${{ github.event.inputs.branch }} | |
| - name: Set service/version outputs | |
| id: set-vars | |
| run: | | |
| echo "service=${{ github.event.inputs.service }}" >> $GITHUB_OUTPUT | |
| echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT |