From f034bc0285139db253352fa53279890fb9270813 Mon Sep 17 00:00:00 2001 From: Aleksandr Shmaraiev Date: Tue, 18 Apr 2023 23:05:26 +0300 Subject: [PATCH] Modify files --- .ci/openshift-ci/common.sh | 4 +++- .github/workflows/build-pr-check.yml | 31 +++++++++++++++++----------- shared-files/pr-image-tag | 1 - 3 files changed, 22 insertions(+), 14 deletions(-) delete mode 100644 shared-files/pr-image-tag diff --git a/.ci/openshift-ci/common.sh b/.ci/openshift-ci/common.sh index f08bbb8611..1dfba2dcf6 100644 --- a/.ci/openshift-ci/common.sh +++ b/.ci/openshift-ci/common.sh @@ -15,7 +15,9 @@ set -e # only exit with zero if all commands of the pipeline exit successfully set -o pipefail -source shared-files/pr-image-tag +git fetch origin +BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) +PR_IMAGE_TAG=$(git show origin/pr-number-${BRANCH_NAME}:shared-files/pr-image-tag) export CHE_NAMESPACE=${CHE_NAMESPACE:-"eclipse-che"} export CHE_SERVER_IMAGE=${CHE_SERVER_IMAGE:-"quay.io/eclipse/che-server:${PR_IMAGE_TAG}"} diff --git a/.github/workflows/build-pr-check.yml b/.github/workflows/build-pr-check.yml index b44dd4eb13..87beff520e 100644 --- a/.github/workflows/build-pr-check.yml +++ b/.github/workflows/build-pr-check.yml @@ -11,6 +11,9 @@ name: build-pr-check on: [push, pull_request] +env: + PR_IMAGE_TAG: pr-${{ github.event.number }} + jobs: set-pr-number: runs-on: ubuntu-22.04 @@ -19,25 +22,34 @@ jobs: - name: Set PR number if: github.event_name == 'pull_request' env: + BRANCH_NAME: ${{ github.head_ref }} GIT_COMMITTER_NAME: ${{ github.event.pull_request.user.login }} GIT_COMMITTER_EMAIL: ${{ github.actor }}@users.noreply.github.com run: | + git fetch origin + REMOTE_BRANCH_EXISTS=$(git ls-remote --heads origin pr-number-${{ env.BRANCH_NAME }}) + git config --local user.name "${{ env.GIT_COMMITTER_NAME }}" + git config --local user.email "${{ env.GIT_COMMITTER_EMAIL }}" mkdir -p ./shared-files - if [ -f ./shared-files/pr-image-tag ] && [[ $(cat ./shared-files/pr-image-tag) == *"pr-${{ github.event.number }}"* ]]; then - echo "File already exists with correct value. Skipping write." - else - echo -n "PR_IMAGE_TAG=pr-${{ github.event.number }}" > ./shared-files/pr-image-tag - git config --local user.name "${{ env.GIT_COMMITTER_NAME }}" - git config --local user.email "${{ env.GIT_COMMITTER_EMAIL }}" + if [[ -z "${REMOTE_BRANCH_EXISTS}" ]]; then + git checkout -b pr-number-${{ env.BRANCH_NAME }} + echo -n "PR_IMAGE_TAG=${{ env.PR_IMAGE_TAG }}" > ./shared-files/pr-image-tag git add ./shared-files/pr-image-tag git commit -m "Set PR_IMAGE_TAG" - git push origin HEAD:${{ github.head_ref }} + git push origin HEAD:pr-number-${{ env.BRANCH_NAME }} + else + git checkout pr-number-${{ env.BRANCH_NAME }} + if [ -f ./shared-files/pr-image-tag ] && [[ $(cat ./shared-files/pr-image-tag) == *"pr-${{ github.event.number }}"* ]]; then + echo "File already exists with correct value. Skipping write." + fi fi build: needs: [set-pr-number] runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Check all properties have description run: ./check_properties_description.sh - name: Set up JDK 11 @@ -62,11 +74,6 @@ jobs: registry: quay.io - name: Build with Maven run: mvn -B clean install -U -Pintegration - - name: Load PR_IMAGE_TAG - if: github.event_name == 'pull_request' - run: | - source ./shared-files/pr-image-tag - echo "PR_IMAGE_TAG=${PR_IMAGE_TAG}" >> $GITHUB_ENV - name: Build docker images if: github.event_name == 'pull_request' run: ./dockerfiles/build.sh --tag:${{ env.PR_IMAGE_TAG }} diff --git a/shared-files/pr-image-tag b/shared-files/pr-image-tag deleted file mode 100644 index b8ad4716f6..0000000000 --- a/shared-files/pr-image-tag +++ /dev/null @@ -1 +0,0 @@ -PR_IMAGE_TAG=pr-494 \ No newline at end of file