add CICD #13
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: minimal-app-workflow | |
on: | |
pull_request: | |
paths: | |
- minimal-app/** | |
- .github/workflows/minimal-app.yml | |
env: | |
WORKING_DIR: ./minimal-app | |
REGISTRY: ghcr.io/octoconsulting | |
IMAGE_NAME: keip/minimal-app | |
JAVA_VERSION: 17 | |
jobs: | |
build: | |
name: build image | |
if: github.ref != 'refs/heads/main' | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: bash | |
working-directory: ${{ env.WORKING_DIR }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-java@v3 | |
with: | |
java-version: "${{ env.JAVA_VERSION }}" | |
distribution: "temurin" | |
- run: mvn --batch-mode --update-snapshots verify | |
name: build image | |
release: | |
name: push image | |
if: github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: bash | |
working-directory: ${{ env.WORKING_DIR }} | |
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-java@v3 | |
with: | |
java-version: "${{ env.JAVA_VERSION }}" | |
distribution: "temurin" | |
- run: echo "IMAGE_TAG=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> "$GITHUB_OUTPUT" | |
id: image-name-selector | |
name: generate image name | |
- run: "! docker manifest inspect ${{ steps.image-name-selector.outputs.IMAGE_TAG }}" | |
name: confirm image is not already pushed | |
- run: mvn --batch-mode --update-snapshots verify | |
name: build image | |
- uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- run: docker push ${{ steps.image-name-selector.outputs.IMAGE_TAG }} | |
# TODO git tag after push with "keip-default-image:version" |