Add comment(s) on PR with command(s) for running image(s) built for PR #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: Build Spring Boot Admin Server | |
on: | |
pull_request: | |
branches: | |
- main | |
paths: | |
- '.github/workflows/build_springboot_admin_server.yaml' | |
- 'spring-boot-admin/**' | |
push: | |
branches: | |
- main | |
paths: | |
- '.github/workflows/build_springboot_admin_server.yaml' | |
- 'spring-boot-admin/**' | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
permissions: | |
contents: read | |
pull-requests: 'write' | |
env: | |
IMAGE_NAME: spring-boot-admin | |
REGISTRY: ${{ vars.DOCKER_REGISTRY }} | |
jobs: | |
build-push: | |
name: Build and push image | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Build Image | |
run: ./build.ps1 -Name '${{ env.IMAGE_NAME }}' -Registry '${{ env.REGISTRY }}' -Tag '${{ env.TAG }}' | |
shell: pwsh | |
env: | |
TAG: ${{ github.event_name == 'pull_request' && format('-t {0}/{1}:pr-{2}', env.REGISTRY, env.IMAGE_NAME, github.event.number) || '' }} | |
- name: Login to container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ vars.DOCKER_REGISTRY }} | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Push image | |
run: docker push --all-tags ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- uses: actions/github-script@v7 | |
if: ${{ github.event_name == 'pull_request' }} | |
with: | |
script: | | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `To run the Spring Boot Admin server image built for this pull request: | |
\`\`\`bash | |
docker run --rm -d --pull=always -p 9099:9099 --name sba-pr steeltoe.azurecr.io/spring-boot-admin:pr-${{ github.event.number }} | |
\`\`\`` | |
}) |