-
Notifications
You must be signed in to change notification settings - Fork 1
63 lines (51 loc) · 2.59 KB
/
merging.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
name: demo-merging
on:
pull_request:
types: [closed]
env:
PROJECT_ID: 538e459351a847058fe28f1e6679b87b #Demo project id (under 'Permit.io Tests' workspace), project Demo
jobs:
demo-merging:
if: ${{ github.event.pull_request.merged == true && contains( github.event.pull_request.labels.*.name, 'permissions') }}
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 PR env ID
echo "PR 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 production env ID
echo "Production 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 }}'