From a9650e7021fe72a26eca31b7668f683b162356c4 Mon Sep 17 00:00:00 2001 From: Lukas Trippe Date: Mon, 19 Aug 2024 13:23:50 +0200 Subject: [PATCH] test: add token asserts (#9) --- action.yml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index e8a87e4a..7398eba3 100644 --- a/action.yml +++ b/action.yml @@ -56,6 +56,12 @@ runs: fork=false fi + # Assert Github Token is set + if [ -z "${{ github.token }}" ]; then + echo "Error: Github Token Secret not found" + exit 1 + fi + # Bot config git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" @@ -77,17 +83,17 @@ runs: fi # Fetch hash of main branch - _hash_main=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ + _hash_main=$(curl -s -H "Authorization: token ${{ github.token }}" \ "https://api.github.com/repos/${{ github.repository }}/commits/${{ github.base_ref }}" | jq -r '.sha') # Fetch hash of feature branch (via PR number, also works for branches from forks) - pr_details=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ + pr_details=$(curl -s -H "Authorization: token ${{ github.token }}" \ "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}") # Extract the repository and ref (branch name) source_repo=$(echo "$pr_details" | jq -r '.head.repo.full_name') branch_name=$(echo "$pr_details" | jq -r '.head.ref') # Get the latest commit hash from the source repository - _hash_feature=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ + _hash_feature=$(curl -s -H "Authorization: token ${{ github.token }}" \ "https://api.github.com/repos/$source_repo/commits/$branch_name" | jq -r '.sha') echo "Main branch (${{ github.base_ref }}) hash: $_hash_main" @@ -113,6 +119,15 @@ runs: # 'create-comment' step # ---------------------------------------- + - name: Create comment specific setup and checks + if: ${{ inputs.step == 'create-comment' }} + run: | + # Assert validator key is set + if [ -z ${{ inputs.validator_key }} ]; then + echo "Error: input 'validator_key' not set" + exit 1 + fi + shell: bash - name: Download artifacts if: ${{ inputs.step == 'create-comment' }}