|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + paths-ignore: |
| 7 | + - '.github/workflows/pullrequest.yml' |
| 8 | + - '.idea/copyright/*.xml' |
| 9 | + - '.gitignore' |
| 10 | + - 'LICENSE' |
| 11 | + - 'README.md' |
| 12 | + |
| 13 | +env: |
| 14 | + DOCKER_OWNER: ${{ github.repository_owner }} |
| 15 | + DOCKER_CONTAINER: server-ping-api |
| 16 | + DOCKER_TAG: ${{ github.ref_name }} |
| 17 | + |
| 18 | +jobs: |
| 19 | + build: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Set up JDK 17 |
| 24 | + uses: actions/setup-java@v3 |
| 25 | + with: |
| 26 | + java-version: 17 |
| 27 | + distribution: temurin |
| 28 | + |
| 29 | + - name: Checkout repository |
| 30 | + uses: actions/checkout@v3 |
| 31 | + |
| 32 | + - name: Build ServerPingApi |
| 33 | + uses: gradle/gradle-build-action@v2 |
| 34 | + with: |
| 35 | + arguments: build |
| 36 | + |
| 37 | + - name: Archive artifacts |
| 38 | + uses: actions/upload-artifact@v3 |
| 39 | + if: success() |
| 40 | + with: |
| 41 | + name: ServerPingApi |
| 42 | + path: build/libs/ServerPingApi.jar |
| 43 | + |
| 44 | + # Docker image build |
| 45 | + - name: Fix Docker environment variables |
| 46 | + run: | |
| 47 | + # Make lowercase |
| 48 | + echo "DOCKER_OWNER=$(echo $DOCKER_OWNER | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV |
| 49 | + echo "DOCKER_CONTAINER=$(echo $DOCKER_CONTAINER | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV |
| 50 | + echo "DOCKER_TAG=$(echo $DOCKER_TAG | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV |
| 51 | +
|
| 52 | + # Replace / with _ |
| 53 | + echo "DOCKER_TAG=$(echo $DOCKER_TAG | sed -e 's/\//_/g')" >> $GITHUB_ENV |
| 54 | +
|
| 55 | + - name: Build the Docker image |
| 56 | + run: | |
| 57 | + docker build . --file Dockerfile --tag $DOCKER_CONTAINER:$DOCKER_TAG |
| 58 | + [[ "${{ github.ref }}" == "refs/heads/master" ]] && docker tag $DOCKER_CONTAINER:$DOCKER_TAG ghcr.io/$DOCKER_OWNER/$DOCKER_CONTAINER:latest |
| 59 | + docker tag $DOCKER_CONTAINER:$DOCKER_TAG ghcr.io/$DOCKER_OWNER/$DOCKER_CONTAINER:$DOCKER_TAG |
| 60 | +
|
| 61 | + - name: Log in to registry |
| 62 | + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin |
| 63 | + |
| 64 | + - name: Push to GHCR |
| 65 | + run: | |
| 66 | + [[ "${{ github.ref }}" == "refs/heads/master" ]] && docker push ghcr.io/$DOCKER_OWNER/$DOCKER_CONTAINER:latest |
| 67 | + docker push ghcr.io/$DOCKER_OWNER/$DOCKER_CONTAINER:$DOCKER_TAG |
0 commit comments