User Service Build and Push to GHCR #14
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: User Service Build and Push to GHCR | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'services/user-service/java/**' | |
workflow_dispatch: | |
env: | |
REGISTRY: ghcr.io | |
REPOSITORY: ${{ github.repository }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.main.outputs.version }} | |
created: ${{ steps.main.outputs.created }} | |
project: ${{ steps.main.outputs.project }} | |
image: ${{ steps.main.outputs.image }} | |
repository: ${{ steps.main.outputs.repository }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set short_sha | |
id: vars | |
run: echo "short_sha=$(git rev-parse --short HEAD)" >> ${GITHUB_ENV} | |
- name: Login to GHCR | |
uses: docker/login-action@v1 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: downcase env.REPOSITORY | |
run: | | |
echo "REPOSITORY=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} | |
- name: Setup Java | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
cache: 'maven' | |
- name: Set up Maven | |
uses: stCarolas/[email protected] | |
with: | |
maven-version: 3.8.2 | |
- name: Build with Maven | |
run: mvn -B package --file ./services/user-service/java/pom.xml -DskipTests | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v2 | |
with: | |
context: services/user-service/java | |
push: true | |
tags: ${{ env.REGISTRY }}/${{ env.REPOSITORY }}/user-service:${{ env.short_sha }} |