Merge pull request #1276 from chethann-007/release-8.0.0 #12
Workflow file for this run
This file contains hidden or 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 | |
| # Trigger this workflow whenever there is a new tag push | |
| on: | |
| push: | |
| tags: | |
| - '*' | |
| jobs: | |
| ghcr-build-and-deploy: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read # Read access to repository contents | |
| packages: write # Permission to write to GitHub Packages (GHCR) | |
| # Define container registry to be GitHub Container Registry and store it as an env | |
| env: | |
| REGISTRY: ghcr.io | |
| steps: | |
| # Set up Java Development Kit (JDK) version 11 using Temurin distribution | |
| - name: Set up JDK 11 | |
| uses: actions/setup-java@v2 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '11' | |
| # Checkout the repository code with full history (fetch-depth: 0) | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| with: | |
| fetch-depth: 0 | |
| # Cache Maven dependencies to speed up subsequent builds | |
| - name: Cache Maven packages | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.m2/repository | |
| key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-maven- | |
| # Build the project and run test cases | |
| - name: Build and run test cases | |
| run: | | |
| mvn clean install | |
| # Package the build artifact using Play Framework's `dist` goal | |
| - name: Package build artifact (Play dist) | |
| run: mvn -f controller/pom.xml play2:dist | |
| # Upload the build artifact as an artifact to GitHub Actions | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4.3.1 | |
| with: | |
| name: userorg-service-dist | |
| path: | | |
| controller/target/userorg-service-*-dist.zip | |
| # Extract repository and tag info to form image name and tag | |
| - name: Extract image tag details | |
| id: image_vars | |
| run: | | |
| REPO_LOWER=$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]') | |
| SHORT_SHA=$(git rev-parse HEAD | cut -c1-7) | |
| TAG_LOWER=$(echo "${GITHUB_REF_NAME}" | tr '[:upper:]' '[:lower:]') | |
| IMAGE_NAME=${{ env.REGISTRY }}/${REPO_LOWER} | |
| IMAGE_TAG=${TAG_LOWER}_${SHORT_SHA}_${GITHUB_RUN_NUMBER} | |
| echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV | |
| echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV | |
| # Log in to GitHub Container Registry using the GitHub Actions token | |
| - name: Log in to GitHub Container Registry (GHCR) | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # Build and push Docker image to GitHub Container Registry (GHCR) | |
| - name: Build and push Docker image to GHCR | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} |