Skip to content

Commit

Permalink
final
Browse files Browse the repository at this point in the history
  • Loading branch information
EliMoshkovich committed Apr 14, 2024
1 parent 5a780a3 commit 07606e4
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/merging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: demo-merging

on:
pull_request:
types: [closed]

env:
PROJECT_ID: 538e459351a847058fe28f1e6679b87b #Demo project id (under 'Permit.io Tests' workspace), project Demo
PR_LABEL: authz

jobs:
demo-merging:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Extract branch name
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch

- name: Fetch pr-${{ steps.extract_branch.outputs.branch }} env id
run: |
response=$(curl -s -X GET https://api.permit.io/v2/projects/${{ env.PROJECT_ID }}/envs \
-H 'Authorization: Bearer ${{ secrets.PROJECT_API_KEY }}' \
-H 'Content-Type: application/json')
# Extract and echo the ID of the "pr-${{ steps.extract_branch.outputs.branch }}" environment
EXISTING_ID=$(echo "$response" | jq -r '.[] | select(.key == "pr-${{ steps.extract_branch.outputs.branch }}") | .id')
echo "EXISTING_ID=$(echo "$response" | jq -r '.[] | select(.key == "pr-${{ steps.extract_branch.outputs.branch }}") | .id')" >> $GITHUB_ENV
# Print the Development env ID
echo "Development env ID is: $EXISTING_ID"
- name: Fetch production env id
run: |
response=$(curl -s -X GET https://api.permit.io/v2/projects/${{ env.PROJECT_ID }}/envs \
-H 'Authorization: Bearer ${{ secrets.PROJECT_API_KEY }}' \
-H 'Content-Type: application/json')
# Extract and echo the ID of the "production" environment
PROD_ID=$(echo "$response" | jq -r '.[] | select(.key == "production") | .id')
echo "PROD_ID=$(echo "$response" | jq -r '.[] | select(.key == "production") | .id')" >> $GITHUB_ENV
# Print the Development env ID
echo "Development env ID is: $PROD_ID"
- name: Copy from 'pr-${{ steps.extract_branch.outputs.branch }}' to Production
run: |
curl -X POST https://api.permit.io/v2/projects/${{ env.PROJECT_ID }}/envs/${{ env.EXISTING_ID }}/copy \
-H 'Authorization: Bearer ${{ secrets.PROJECT_API_KEY }}' \
-H 'Content-Type: application/json' \
-d '{
"target_env": {
"existing": "${{ env.PROD_ID }}"
}
}'
- name: Delete env pr-${{ steps.extract_branch.outputs.branch }}
run: |
curl -X DELETE \
https://api.permit.io/v2/projects/${{ env.PROJECT_ID }}/envs/${{ env.EXISTING_ID }} \
-H 'Authorization: Bearer ${{ secrets.PROJECT_API_KEY }}'
5 changes: 2 additions & 3 deletions .github/workflows/new-env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ env:
#PR_NUMBER: ${{ github.event.number }} # PR number optional - cheange ${{ steps.extract_branch.outputs.branch }} with ${{ env.PR_NUMBER }} in the job

jobs:
demo-label:
if: ${{ github.event.label.name == '${{ env.PR_LABEL }}' }}
demo-new-env:
if: github.event.label.name == ${{ env.PR_LABEL }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand Down Expand Up @@ -79,7 +79,6 @@ jobs:
}
}'
- name: Comment PR with api_key of new env
uses: actions/github-script@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-pdp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
PR_LABEL: authz

jobs:
demo-label:
demo-run-pdp-and-tests:
if: ${{ github.event.label.name == '${{ env.PR_LABEL }}' }}
runs-on: ubuntu-latest
steps:
Expand Down

0 comments on commit 07606e4

Please sign in to comment.