From ce694f5bdf951e47e6c700c91a053e6d265e6a1d Mon Sep 17 00:00:00 2001 From: Giovanni Gargiulo Date: Tue, 16 Jan 2024 11:58:17 +0000 Subject: [PATCH] chore: gha publish job --- .github/workflows/publish.yaml | 85 +++++++++++++++++++ .github/workflows/release.yaml | 22 +++++ version.txt | 1 + .../codeql.yaml | 0 .../feature.yaml | 0 .../workflows => workflows_backup}/main.yaml | 0 .../maven-settings.xml | 0 7 files changed, 108 insertions(+) create mode 100644 .github/workflows/publish.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 version.txt rename {.github/workflows => workflows_backup}/codeql.yaml (100%) rename {.github/workflows => workflows_backup}/feature.yaml (100%) rename {.github/workflows => workflows_backup}/main.yaml (100%) rename {.github/workflows => workflows_backup}/maven-settings.xml (100%) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..8859d1a --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,85 @@ +name: Build and Publish Docker images + +on: + push: + branches: + - main + workflow_dispatch: + +env: + PRIVATE_DOCKER_REGISTRY_URL: ${{ secrets.GITLAB_DOCKER_REGISTRY_URL }} + PRIVATE_DOCKER_REGISTRY_USER: Deploy-Token + PRIVATE_DOCKER_REGISTRY_PASS: ${{ secrets.GITLAB_PKG_REGISTRY_TOKEN }} + +jobs: + + build-version: + runs-on: ubuntu-latest + outputs: + ARTIFACT_VERSION: ${{ steps.metadata.outputs.ARTIFACT_VERSION }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup dependencies + run: | + pip install yq + + - name: Set extra environment and metadata + id: metadata + run: | + CURRENT_VERSION=$(cat version.txt) + + if [ ${{github.event_name}} == "pull_request" ] + then + PR_NUMBER=$(echo $GITHUB_REF | awk -F/ '{ print $3 }') + echo "ARTIFACT_VERSION=${CURRENT_VERSION}-PR${PR_NUMBER}-$GITHUB_RUN_NUMBER" >> "$GITHUB_OUTPUT" + else + BRANCH=${GITHUB_REF##*/} + echo "BRANCH=${GITHUB_REF##*/}" >> "$GITHUB_OUTPUT" + echo "ARTIFACT_VERSION=${CURRENT_VERSION}" >> "$GITHUB_OUTPUT" + fi + + api: + runs-on: ubuntu-latest + env: + APP_NAME: cf-metadata-server-api + needs: build-version + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up JDK + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '18' + cache: maven + + - name: Build + run: mvn clean package + + - name: Private Docker Hub Login + uses: docker/login-action@v2 + with: + registry: ${{ env.PRIVATE_DOCKER_REGISTRY_URL }} + username: ${{ env.PRIVATE_DOCKER_REGISTRY_USER }} + password: ${{ env.PRIVATE_DOCKER_REGISTRY_PASS }} + + - name: Public Docker Hub Login + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_REGISTRY_USER }} + password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and Push docker image + uses: docker/build-push-action@v4 + env: + ARTIFACT_VERSION: ${{needs.build-version.outputs.ARTIFACT_VERSION}} + with: + context: api + push: true + tags: | + ${{ env.PRIVATE_DOCKER_REGISTRY_URL }}/${{ env.APP_NAME }}:${{ env.ARTIFACT_VERSION }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..dc55056 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,22 @@ +name: Create a new Release + +on: + push: + branches: ['main'] + + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +jobs: + create_release: + runs-on: self-hosted + steps: + - name: 🚀 release-please-action + uses: google-github-actions/release-please-action@v3 + with: + release-type: simple + bump-minor-pre-major: true + bump-patch-for-minor-pre-major: true diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..8acdd82 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.0.1 diff --git a/.github/workflows/codeql.yaml b/workflows_backup/codeql.yaml similarity index 100% rename from .github/workflows/codeql.yaml rename to workflows_backup/codeql.yaml diff --git a/.github/workflows/feature.yaml b/workflows_backup/feature.yaml similarity index 100% rename from .github/workflows/feature.yaml rename to workflows_backup/feature.yaml diff --git a/.github/workflows/main.yaml b/workflows_backup/main.yaml similarity index 100% rename from .github/workflows/main.yaml rename to workflows_backup/main.yaml diff --git a/.github/workflows/maven-settings.xml b/workflows_backup/maven-settings.xml similarity index 100% rename from .github/workflows/maven-settings.xml rename to workflows_backup/maven-settings.xml