Hotfix/login translation #470
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: Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| types: [ opened, synchronize, reopened ] | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| release-snapshot: | |
| if: github.event_name == 'pull_request' | |
| name: Release Snapshot | |
| concurrency: | |
| group: docker-${{ github.head_ref || github.ref_name }} | |
| cancel-in-progress: true | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'adopt' | |
| java-version: '17' | |
| - name: Make Gradlew Executable | |
| run: chmod +x ./gradlew | |
| - name: Get Project Name | |
| id: project_name | |
| run: echo "PROJECT_NAME=$(./gradlew -q properties | grep '^name:' | awk '{print $2}')" >> $GITHUB_ENV | |
| - name: Get Project Version | |
| id: project_version | |
| run: echo "VERSION=$(./gradlew -q properties | grep '^version:' | awk '{print $2}')" >> $GITHUB_ENV | |
| - name: Compute PR-based snapshot suffix | |
| if: github.event_name == 'pull_request' | |
| run: echo "SNAPSHOT_SUFFIX=-pr-${{ github.event.number }}" >> $GITHUB_ENV | |
| - name: Check for existing release tag (only on PR) | |
| if: github.event_name == 'pull_request' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| VERSION: ${{ env.VERSION }} | |
| run: | | |
| TAG_EXISTS=$(curl -H "Authorization: token $GITHUB_TOKEN" -s https://api.github.com/repos/${{ github.repository }}/releases | jq -r ".[] | select(.tag_name == \"v$VERSION\") | .tag_name") | |
| if [ "$TAG_EXISTS" == "v$VERSION" ]; then | |
| echo "Release tag v$VERSION already exists. Rejecting PR." | |
| exit 1 | |
| else | |
| echo "No existing release with tag v$VERSION found. Proceeding with build." | |
| fi | |
| # Logins | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_PAT }} | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ secrets.AWS_REGION }} | |
| - name: Login to Amazon ECR | |
| id: ecr | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| - name: Build and Push docker image (DockerHub + ECR) | |
| env: | |
| PROJECT_NAME: ${{ env.PROJECT_NAME }} | |
| VERSION: ${{ env.VERSION }} | |
| SNAPSHOT_SUFFIX: ${{ env.SNAPSHOT_SUFFIX }} | |
| DOCKERHUB_ORG: ${{ secrets.DOCKERHUB_ORG }} | |
| ECR_REGISTRY: ${{ steps.ecr.outputs.registry }} | |
| ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }} | |
| run: | | |
| set -euo pipefail | |
| TAG="v${VERSION}${SNAPSHOT_SUFFIX}" | |
| DH_IMAGE="docker.io/${DOCKERHUB_ORG}/${PROJECT_NAME}:${TAG}" | |
| ECR_IMAGE="${ECR_REGISTRY}/${ECR_REPOSITORY}:${TAG}" | |
| docker build -f Dockerfile --build-arg SKIP_TESTS=true -t "${DH_IMAGE}" . | |
| docker tag "${DH_IMAGE}" "${ECR_IMAGE}" | |
| docker push "${DH_IMAGE}" | |
| docker push "${ECR_IMAGE}" | |
| release: | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| name: Release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'adopt' | |
| java-version: '17' | |
| - name: Make Gradlew Executable | |
| run: chmod +x ./gradlew | |
| - name: Get Project Name | |
| id: project_name | |
| run: echo "PROJECT_NAME=$(./gradlew -q properties | grep '^name:' | awk '{print $2}')" >> $GITHUB_ENV | |
| - name: Get Project Version | |
| id: project_version | |
| run: echo "VERSION=$(./gradlew -q properties | grep '^version:' | awk '{print $2}')" >> $GITHUB_ENV | |
| - name: Check for existing release tag (only on PR) | |
| if: github.event_name == 'pull_request' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| VERSION: ${{ env.VERSION }} | |
| run: | | |
| TAG_EXISTS=$(curl -H "Authorization: token $GITHUB_TOKEN" -s https://api.github.com/repos/${{ github.repository }}/releases | jq -r ".[] | select(.tag_name == \"v$VERSION\") | .tag_name") | |
| if [ "$TAG_EXISTS" == "v$VERSION" ]; then | |
| echo "Release tag v$VERSION already exists. Rejecting PR." | |
| exit 1 | |
| else | |
| echo "No existing release with tag v$VERSION found. Proceeding with build." | |
| fi | |
| # Logins | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_PAT }} | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ secrets.AWS_REGION }} | |
| - name: Login to Amazon ECR | |
| id: ecr | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| - name: Build and Push docker image (DockerHub + ECR) | |
| env: | |
| PROJECT_NAME: ${{ env.PROJECT_NAME }} | |
| VERSION: ${{ env.VERSION }} | |
| DOCKERHUB_ORG: ${{ secrets.DOCKERHUB_ORG }} | |
| ECR_REGISTRY: ${{ steps.ecr.outputs.registry }} | |
| ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }} | |
| run: | | |
| set -euo pipefail | |
| TAG="v${VERSION}" | |
| DH_IMAGE="docker.io/${DOCKERHUB_ORG}/${PROJECT_NAME}:${TAG}" | |
| DH_LATEST="docker.io/${DOCKERHUB_ORG}/${PROJECT_NAME}:latest" | |
| ECR_IMAGE="${ECR_REGISTRY}/${ECR_REPOSITORY}:${TAG}" | |
| ECR_LATEST="${ECR_REGISTRY}/${ECR_REPOSITORY}:latest" | |
| docker build -f Dockerfile --build-arg SKIP_TESTS=true -t "${DH_IMAGE}" . | |
| docker tag "${DH_IMAGE}" "${DH_LATEST}" | |
| docker tag "${DH_IMAGE}" "${ECR_IMAGE}" | |
| docker tag "${DH_IMAGE}" "${ECR_LATEST}" | |
| docker push "${DH_IMAGE}" | |
| docker push "${DH_LATEST}" | |
| docker push "${ECR_IMAGE}" | |
| docker push "${ECR_LATEST}" | |
| - name: Create GitHub Release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: "v${{ env.VERSION }}" | |
| release_name: "v${{ env.VERSION }}" | |
| body: "Release of version v${{ env.VERSION }}" | |
| draft: false | |
| prerelease: false |