Merge pull request #18 from atilara/develop #26
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 deploy API to Docker Hub | |
on: | |
push: | |
branches: | |
- master | |
permissions: | |
contents: write | |
jobs: | |
build-deploy: | |
environment: production | |
name: Build and deploy | |
runs-on: ubuntu-latest | |
env: | |
DATABASE_URL: ${{ secrets.DATABASE_URL }} | |
DATABASE_USER: ${{ secrets.DATABASE_USER }} | |
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }} | |
JWT_SECRET_KEY: ${{ secrets.JWT_SECRET_KEY }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 # Checkout the code in the action workspace, in this case ubuntu-latest | |
- name: Setup Java JDK | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'corretto' | |
java-version: 17 | |
- name: Build with Maven | |
run: | | |
mvn clean | |
mvn -B package --file pom.xml | |
- name: Login to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }} | |
- name: Extract Maven project version | |
run: echo ::set-output name=version::$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec) | |
id: project | |
- name: Push to Docker Hub | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
dockerfile: Dockerfile | |
push: true | |
tags: | | |
${{ secrets.DOCKERHUB_USERNAME }}/authentication-jwt-spring-boot:${{ steps.project.outputs.version }} | |
${{ secrets.DOCKERHUB_USERNAME }}/authentication-jwt-spring-boot:latest | |
- name: Create a GitHub release | |
uses: ncipollo/release-action@v1 | |
with: | |
tag: ${{ steps.project.outputs.version }} | |
name: v${{ steps.project.outputs.version }} | |
generateReleaseNotes: true | |
artifacts: ./target/*.jar |