Merge pull request #3 from ozgen/fix-docker-image #4
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: CI Pipeline | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v2 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
server-id: github | |
settings-path: ${{ github.workspace }} | |
cache: 'maven' | |
- name: Set up Maven | |
uses: stCarolas/[email protected] | |
with: | |
maven-version: 3.8.2 | |
- name: Run Tests | |
run: mvn clean test | |
- name: Set and Export Custom Version | |
id: set_version | |
run: | | |
VERSION="$(date +'%Y%m%d')-$(git rev-parse --short HEAD)" | |
echo "CUSTOM_VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Build with Maven | |
run: mvn package | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
- name: Build Docker Image | |
run: | | |
IMAGE_ID=docker.io/${{ secrets.DOCKER_HUB_USERNAME }}/binance-java-bot | |
echo "IMAGE_ID=$IMAGE_ID" >> $GITHUB_ENV | |
docker build -t $IMAGE_ID:${{ env.CUSTOM_VERSION }} . | |
- name: Push Docker Image | |
run: | | |
docker push ${{ env.IMAGE_ID }}:${{ env.CUSTOM_VERSION }} |