-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create reusable validateActor action
- Loading branch information
1 parent
ba9e3fc
commit 528a734
Showing
7 changed files
with
131 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Validate actor | ||
description: Validate the the current actor has the permissions they need. By default, it validates that the user has write permissions. | ||
|
||
inputs: | ||
# If `REQUIRE_APP_DEPLOYER` is true, we check that they're an app deployer. If not, we just check that they have write access. | ||
REQUIRE_APP_DEPLOYER: | ||
description: Should this action require the actor to be an app deployer? | ||
required: false | ||
default: 'true' | ||
OS_BOTIFY_TOKEN: | ||
description: OSBotify token. Needed to access certain API endpoints the regular github.token can't | ||
required: true | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Get user permissions | ||
if: ${{ !fromJSON(inputs.REQUIRE_APP_DEPLOYER) }} | ||
id: getUserPermissions | ||
shell: bash | ||
run: | | ||
PERMISSION=$(gh api /repos/${{ github.repository }}/collaborators/${{ github.actor }}/permission | jq -r '.permission') | ||
if [[ "$PERMISSION" == 'write' || "$PERMISSION" == 'admin' ]]; then | ||
echo "::notice::✅ Actor ${{ github.actor }} has write permission" | ||
else | ||
echo "::error::❌ Actor ${{ github.actor }} does not have write permission" | ||
exit 1 | ||
fi | ||
env: | ||
GITHUB_TOKEN: ${{ inputs.OS_BOTIFY_TOKEN }} | ||
|
||
- name: Check if user is deployer | ||
id: isUserDeployer | ||
if: fromJSON(inputs.REQUIRE_APP_DEPLOYER) | ||
shell: bash | ||
run: | | ||
if [[ "${{ github.actor }}" == "OSBotify" || "${{ github.actor }}" == "os-botify[bot]" ]] || \ | ||
gh api /orgs/Expensify/teams/mobile-deployers/memberships/${{ github.actor }} --silent; then | ||
echo "::notice::✅ Actor ${{ github.actor }} is an app deployer" | ||
else | ||
echo "::error::❌ Actor ${{ github.actor }} is not an app deployer" | ||
exit 1 | ||
fi | ||
env: | ||
GITHUB_TOKEN: ${{ inputs.OS_BOTIFY_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.