Skip to content

Commit

Permalink
use GITHUB_ENV for step output
Browse files Browse the repository at this point in the history
rc
  • Loading branch information
elrayle committed Apr 11, 2024
1 parent cf3c0c7 commit 8a909d6
Showing 1 changed file with 61 additions and 57 deletions.
118 changes: 61 additions & 57 deletions .github/workflows/deployable.yml
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

0 comments on commit 8a909d6

Please sign in to comment.