publish automatically on main and manually on other branches #2
Workflow file for this run
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 and publish on demand | ||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: [ "**" ] | ||
env: | ||
DOCKER_REGISTRY: ghcr.io | ||
DOCKER_IMAGE_REGISTRY: ghcr.io/${{ github.repository }} | ||
DOCKER_TAG_SHA: ${{ github.sha }} | ||
DOCKER_TAG_REF: ${{ replace(github.ref_name, '/', '_') }} | ||
Check failure on line 12 in .github/workflows/publish.yml GitHub Actions / build and publish on demandInvalid workflow file
|
||
DOCKER_REGISTRY_USERNAME: ${{ github.actor }} | ||
DOCKER_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }} | ||
jobs: | ||
build-and-publish-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
checks: write | ||
contents: read | ||
packages: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-java@v4 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
cache: maven | ||
- name: Log into registry ${{ env.DOCKER_REGISTRY }} | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.DOCKER_REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Build and push image except for main branch | ||
if: github.ref != 'refs/heads/main' | ||
run: | | ||
./mvnw install \ | ||
-B --no-transfer-progress --file pom.xml \ | ||
-D docker.app.image.registry=${{ env.DOCKER_IMAGE_REGISTRY }} \ | ||
-P exec.docker.image \ | ||
-D docker.app.image.tag.ref=${{ env.DOCKER_TAG_REF }} \ | ||
-D docker.app.image.tag.sha=${{ env.DOCKER_TAG_SHA }} \ | ||
-am -pl addondemo.app.image | ||
- name: Build and push image for main branch | ||
if: github.ref == 'refs/heads/main' | ||
run: | | ||
./mvnw install \ | ||
-B --no-transfer-progress --file pom.xml \ | ||
-D docker.app.image.registry=${{ env.DOCKER_IMAGE_REGISTRY }} \ | ||
-P exec.docker.image \ | ||
-D docker.app.image.tag.sha=${{ env.DOCKER_TAG_SHA }} \ | ||
-am -pl addondemo.app.image |