Skip to content

Commit

Permalink
test: add token asserts (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
lkstrp authored Aug 19, 2024
1 parent 56a6652 commit a9650e7
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand All @@ -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"
Expand All @@ -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' }}
Expand Down

0 comments on commit a9650e7

Please sign in to comment.