From 0e20d3e6315939be409efb13f8836d960127a9c7 Mon Sep 17 00:00:00 2001 From: jarno Date: Mon, 7 Oct 2024 17:49:26 +0200 Subject: [PATCH] ADD: release workflow --- .github/workflows/release.yml | 60 +++++++++++++++++++++++++++++++++++ pom.xml | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..755177c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,60 @@ +name: Create Docker image + +on: + push: + branches: + - master + - release/* + workflow_dispatch: + inputs: + version: + description: 'Version of the application' + required: false + +jobs: + build: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.set-version.outputs.version }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set version + id: set-version + run: echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV + + - name: Extract version from pom.xml + if: github.event.inputs.version == '' + id: extract-version + run: | + VERSION=$(grep -m 1 '' pom.xml | sed 's/.*\(.*\)<\/version>.*/\1/' || grep -m 1 '' pom.xml | sed 's/.*\(.*\)<\/version>.*/\1/') + echo "VERSION=${VERSION}" >> $GITHUB_ENV + + - name: Authorize in Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: true + tags: | + ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_IMAGE_NAME }}:${{ env.VERSION }} + ${{ github.ref == 'refs/heads/master' && format('{0}/{1}:latest', secrets.DOCKER_HUB_USERNAME, vars.DOCKER_IMAGE_NAME) || '' }} + + - name: Create release + uses: marvinpinto/action-automatic-releases@latest + with: + repo_token: "${{ secrets.TOKEN }}" + automatic_release_tag: ${{ env.VERSION }} + prerelease: ${{ github.ref != 'refs/heads/master' }} + title: "${{ github.event.repository.name }} v${{ env.VERSION }}" \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3d7cf4a..1558485 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.wiemanboy WiemanApi - 0.0.1-SNAPSHOT + 0.0.1 WiemanApi WiemanApi