-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rc
- Loading branch information
Showing
1 changed file
with
61 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,66 @@ | ||
name: Deployable | ||
|
||
on: | ||
workflow_call: | ||
# TODO: REMOVE: input is for testing only | ||
inputs: | ||
user: | ||
description: 'user to check for deploy permissions' | ||
required: true | ||
default: ${{ github.actor }} | ||
type: string | ||
workflow_call: | ||
# TODO: REMOVE: input is for testing only | ||
inputs: | ||
user: | ||
description: 'user to check for deploy permissions' | ||
required: true | ||
default: ${{ github.actor }} | ||
type: string | ||
|
||
jobs: | ||
deployable: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# verify required secrets are set | ||
- name: Check secrets | ||
run: | | ||
if [[ -z "${{ secrets.PRODUCTION_DEPLOYERS }}" ]]; then | ||
echo "PRODUCTION_DEPLOYERS is not set" | ||
exit 1 | ||
fi | ||
if [[ -z "${{ secrets.DEPLOY_TOKEN }}" ]]; then | ||
echo "DEPLOY_TOKEN is not set" | ||
exit 1 | ||
fi | ||
- name: Get team ID | ||
run: | | ||
org_name=$(echo "${{ github.repository }}" | cut -d / -f 1) | ||
team_info=$(curl \ | ||
-H "Authorization: token ${{ secrets.DEPLOY_TOKEN }}" \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
https://api.github.com/orgs/$org_name/teams) | ||
team_id=$(echo "$team_info" | jq '.[] | select(.name=="${{ secrets.PRODUCTION_DEPLOYERS }}") | .id') | ||
echo "::set-output name=team_id::$team_id" | ||
- name: Get organization ID | ||
run: | | ||
org_name=$(echo "${{ github.repository }}" | cut -d / -f 1) | ||
org_info=$(curl \ | ||
-H "Authorization: token ${{ secrets.DEPLOY_TOKEN }}" \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
https://api.github.com/orgs/$org_name) | ||
org_id=$(echo "$org_info" | jq .id) | ||
echo "The organization ID is $org_id" | ||
echo "::set-output name=org_id::$org_id" | ||
- name: Check team membership | ||
run: | | ||
team_id=${{ steps.get-team-id.outputs.team_id }} | ||
org_id=${{ steps.get-org-id.outputs.org_id }} | ||
user="${{ inputs.user }}" # TODO: UPDATE: change to ${{ github.actor }} when testing is done | ||
response=$(curl \ | ||
-H "Authorization: token ${{ secrets.DEPLOY_TOKEN }}" \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
https://api.github.com/organizations/$org_id/team/$team_id/memberships/$user) | ||
if [[ $response == *"active"* ]]; then | ||
echo "$user is a member of the team" | ||
else | ||
echo "$user does not have permissions to deploy" | ||
exit 1 | ||
fi | ||
deployable: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# verify required secrets are set | ||
- name: Check secrets | ||
run: | | ||
if [[ -z "${{ secrets.PRODUCTION_DEPLOYERS }}" ]]; then | ||
echo "PRODUCTION_DEPLOYERS is not set" | ||
exit 1 | ||
fi | ||
if [[ -z "${{ secrets.DEPLOY_TOKEN }}" ]]; then | ||
echo "DEPLOY_TOKEN is not set" | ||
exit 1 | ||
fi | ||
- name: Get team ID | ||
run: | | ||
org_name=$(echo "${{ github.repository }}" | cut -d / -f 1) | ||
team_info=$(curl \ | ||
-H "Authorization: token ${{ secrets.DEPLOY_TOKEN }}" \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
https://api.github.com/orgs/$org_name/teams) | ||
team_id=$(echo "$team_info" | jq '.[] | select(.name=="${{ secrets.PRODUCTION_DEPLOYERS }}") | .id') | ||
echo "TEAM_ID=$team_id" >> $GITHUB_ENV | ||
echo "::set-output name=team_id::$team_id" | ||
- name: Get organization ID | ||
run: | | ||
org_name=$(echo "${{ github.repository }}" | cut -d / -f 1) | ||
org_info=$(curl \ | ||
-H "Authorization: token ${{ secrets.DEPLOY_TOKEN }}" \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
https://api.github.com/orgs/$org_name) | ||
org_id=$(echo "$org_info" | jq .id) | ||
echo "The organization ID is $org_id" | ||
echo "::set-output name=org_id::$org_id" | ||
# TODO: UPDATE: change to input.user to github.actor when testing is done | ||
- name: Check team membership | ||
run: | | ||
team_id=${{ env.TEAM_ID }} | ||
org_id=${{ steps.get-org-id.outputs.org_id }} | ||
user="${{ inputs.user }}" | ||
response=$(curl \ | ||
-H "Authorization: token ${{ secrets.DEPLOY_TOKEN }}" \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
https://api.github.com/organizations/$org_id/team/$team_id/memberships/$user) | ||
if [[ $response == *"active"* ]]; then | ||
echo "$user is a member of the team" | ||
else | ||
echo "$user does not have permissions to deploy" | ||
exit 1 | ||
fi |