Skip to content

Commit

Permalink
ci/github: Fix repo contexts /cont (envoyproxy#28485)
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Northey <[email protected]>
  • Loading branch information
phlax authored Jul 19, 2023
1 parent 5e1b1e3 commit 2311e03
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 25 deletions.
55 changes: 36 additions & 19 deletions .github/actions/env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ inputs:

repo_ref_sha:
type: string
repo_name:
repo_ref_name:
type: string

trusted_bots:
Expand Down Expand Up @@ -64,6 +64,8 @@ outputs:
value: ${{ steps.context.outputs.repo_ref_sha }}
repo_ref_sha_short:
value: ${{ steps.context.outputs.repo_ref_sha_short }}
repo_ref_title:
value: ${{ steps.context.outputs.repo_ref_title }}
trusted:
value: ${{ steps.trusted.outputs.trusted }}
version_dev:
Expand All @@ -81,23 +83,6 @@ runs:
run: ./mobile/tools/what_to_run.sh
shell: bash

- id: context
name: 'CI context'
run: |
VERSION_DEV="$(cat VERSION.txt | cut -d- -f2)"
VERSION_PATCH="$(cat VERSION.txt | cut -d- -f1 | rev | cut -d. -f1 | rev)"
# TODO: strip merge from pr names
REF_NAME=${{ inputs.repo_ref_name || github.ref_name }}
REF_SHA=${{ inputs.repo_ref_sha || github.sha }}
{
echo "repo_ref_name=$REF_NAME"
echo "repo_ref_sha=$REF_SHA"
echo "repo_ref_sha_short=${REF_SHA:0:7}"
echo "version_dev=$VERSION_DEV"
echo "version_patch=$VERSION_PATCH"
} >> "$GITHUB_OUTPUT"
shell: bash

- id: trusted
name: 'Check if its a trusted run'
run: |
Expand All @@ -122,7 +107,39 @@ runs:
echo "Not trusted pull_request event"
TRUSTED=
fi
echo "trusted=$TRUSTED" >> "$GITHUB_OUTPUT"
if [[ -n "$TRUSTED" ]]; then
echo "trusted=true" >> "$GITHUB_OUTPUT"
else
echo "trusted=false" >> "$GITHUB_OUTPUT"
fi
shell: bash

- id: context
name: 'CI context'
run: |
VERSION_DEV="$(cat VERSION.txt | cut -d- -f2)"
VERSION_PATCH="$(cat VERSION.txt | cut -d- -f1 | rev | cut -d. -f1 | rev)"
# TODO: strip merge from pr names
REF_NAME=${{ inputs.repo_ref_name || github.ref_name }}
if [[ "$REF_NAME" =~ ^refs/pull/ ]]; then
REF_NAME="${REF_NAME:10}"
fi
REF_SHA=${{ inputs.repo_ref_sha || github.event.pull_request.head.sha || github.sha }}
REF_SHA_SHORT="${REF_SHA:0:7}"
REF_TITLE=(
"${{ steps.trusted.outputs.trusted == 'true' && 'postsubmit' || 'pr' }}/"
"${REF_NAME}"
"@${REF_SHA_SHORT}")
REF_TITLE="$(printf %s "${REF_TITLE[@]}" $'\n')"
{
echo "repo_ref_name=$REF_NAME"
echo "repo_ref_sha=$REF_SHA"
echo "repo_ref_title=$REF_TITLE"
echo "repo_ref_sha_short=$REF_SHA_SHORT"
echo "version_dev=$VERSION_DEV"
echo "version_patch=$VERSION_PATCH"
} >> "$GITHUB_OUTPUT"
shell: bash

- id: build
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/_env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ on:
value: ${{ jobs.repo.outputs.repo_ref_sha }}
repo_ref_sha_short:
value: ${{ jobs.repo.outputs.repo_ref_sha_short }}
repo_ref_title:
value: ${{ jobs.repo.outputs.repo_ref_title }}

trusted:
value: ${{ jobs.repo.outputs.trusted }}
Expand Down Expand Up @@ -114,6 +116,7 @@ jobs:
repo_ref_name: ${{ steps.env.outputs.repo_ref_name }}
repo_ref_sha: ${{ steps.env.outputs.repo_ref_sha }}
repo_ref_sha_short: ${{ steps.env.outputs.repo_ref_sha_short }}
repo_ref_title: ${{ steps.env.outputs.repo_ref_title }}
trusted: ${{ steps.env.outputs.trusted }}
version_dev: ${{ steps.env.outputs.version_dev }}
version_patch: ${{ steps.env.outputs.version_patch }}
Expand All @@ -125,6 +128,7 @@ jobs:
id: env
with:
check_mobile_run: ${{ inputs.check_mobile_run }}
repo_ref_name: ${{ inputs.repo_ref_name }}
repo_ref_sha: ${{ inputs.repo_ref_sha }}
build_image_repo: ${{ inputs.build_image_repo }}
build_image_tag: ${{ inputs.build_image_tag }}
Expand All @@ -136,6 +140,10 @@ jobs:
echo "version_dev=${{ steps.env.outputs.version_dev }}"
echo "version_patch=${{ steps.env.outputs.version_patch }}"
echo "trusted=${{ steps.env.outputs.trusted }}"
echo "repo_ref_name=${{ steps.env.outputs.repo_ref_name }}"
echo "repo_ref_sha=${{ steps.env.outputs.repo_ref_sha }}"
echo "repo_ref_sha_short=${{ steps.env.outputs.repo_ref_sha_short }}"
echo "repo_ref_title=${{ steps.env.outputs.repo_ref_title }}"
echo "build_image_ubuntu=${{ steps.env.outputs.build_image_ubuntu }}"
echo "build_image_ubuntu_mobile=${{ steps.env.outputs.build_image_ubuntu_mobile }}"
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/_stage_verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ on:
default: false
repo_ref:
type: string
default:
given_ref:
type: string

concurrency:
group: ${{ github.head_ref || github.run_id }}-${{ github.workflow }}-verify
Expand All @@ -34,7 +35,7 @@ jobs:
run_pre: ./.github/actions/verify/examples/setup
run_pre_with: |
bucket: envoy-${{ inputs.trusted && 'postsubmit' || 'pr' }}
ref: ${{ inputs.ref }}
ref: ${{ inputs.given_ref }}
env: |
export NO_BUILD_SETUP=1
uses: ./.github/workflows/_ci.yml
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/envoy-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
check_mobile_run: false
prime_build_image: true
start_check_status: Verify/examples
repo_ref_sha: ${{ inputs.ref_sha }}
repo_ref_sha: ${{ inputs.sha }}
repo_ref_name: ${{ inputs.head_ref }}

permissions:
Expand All @@ -41,9 +41,10 @@ jobs:

verify:
uses: ./.github/workflows/_stage_verify.yml
name: Verify (${{ inputs.trusted && 'postsubmit' || 'pr' }}:${{ needs.env.outputs.repo_ref_name }}@${{ needs.env.outputs.repo_ref_sha_short }})
name: Verify ${{ needs.env.outputs.repo_ref_title }}
needs:
- env
with:
trusted: ${{ needs.env.outputs.trusted && true || false }}
repo_ref: ${{ needs.env.outputs.trusted == 'false' && inputs.ref || '' }}
trusted: ${{ needs.env.outputs.trusted == 'true' && true || false }}
given_ref: ${{ inputs.ref }}
repo_ref: ${{ needs.env.outputs.trusted != 'true' && inputs.ref || '' }}

0 comments on commit 2311e03

Please sign in to comment.