From b56f3ebcf070ea310cd268af0bf2ab9f6b050fd0 Mon Sep 17 00:00:00 2001 From: Julien Carsique Date: Wed, 18 Dec 2024 11:26:16 +0100 Subject: [PATCH] BUILD-7112 skip if no version found --- releasability-status/action.yml | 11 +---------- releasability-status/find_version.sh | 25 +++++++++---------------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/releasability-status/action.yml b/releasability-status/action.yml index 5228c91f..eab014d2 100644 --- a/releasability-status/action.yml +++ b/releasability-status/action.yml @@ -26,21 +26,12 @@ runs: run: pip install pipenv shell: bash - - uses: octokit/request-action@dad4362715b7fb2ddedf9772c8670824af564f0d # v2.4.0 - id: get_commit_status - with: - route: 'GET /repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/commits/${{ github.sha }}/status' - env: - GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }} - # Find latest promoted version from the commit status - id: find_version shell: bash working-directory: ${{ github.action_path }} - env: - OUTPUTS: "${{ steps.get_commit_status.outputs.data }}" run: | - ./find_version.sh ${{ github.ref_name }} + ./find_version.sh - name: Trigger releasability checks id: checks diff --git a/releasability-status/find_version.sh b/releasability-status/find_version.sh index 7af0ed7c..8f069ae9 100755 --- a/releasability-status/find_version.sh +++ b/releasability-status/find_version.sh @@ -1,23 +1,16 @@ #!/bin/bash -# Find last promoted version from github commit status check results -set -xeuo pipefail - -version="" +# Find last promoted version from GitHub commit status check results: +# "description": "Latest promoted build of '${PROJECT_VERSION}' from branch '${GITHUB_BRANCH}'" +# "context": "repox-${GITHUB_BRANCH}", -readarray -t statuses < <(echo "$OUTPUTS" | jq -c ".statuses[]") -for i in "${statuses[@]}"; do - desc=$(echo "$i" | jq -r ".description") - v=$(echo "$desc" | cut -d\' -f 2 ) - branch=$(echo "$desc" | cut -d\' -f 4 ) - if [[ $branch == "$1" ]]; then - version=$v - break - fi -done +set -xeuo pipefail +description=$(gh api "/repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/statuses" \ + --jq '.[] | select(.state == "success" and .context == ("repox-'"$GITHUB_REF_NAME"'")) | .description') +version=$(echo "$description" | cut -d\' -f 2) if [ -z "${version}" ]; then echo "Unable to find promoted version" - exit 1 + echo "status=skipped" >> "$GITHUB_OUTPUT" + exit 0 fi - echo "version=$version" >> "$GITHUB_OUTPUT"