diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d31accf --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,65 @@ +name: Create Docker image and release + +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: Install xmllint + run: | + sudo apt-get update + sudo apt-get install -y libxml2-utils + + - name: Extract version from pom.xml + if: github.event.inputs.version == '' + id: extract-version + run: | + VERSION=$(xmllint --xpath 'string(/*[local-name()="project"]/*[local-name()="version"])' pom.xml) + 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