-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
158 lines (142 loc) · 5.46 KB
/
action.yml
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
name: 'Paragraph Push Runner'
description: 'Pushes updated code from GitHub to sync with Paragon.'
branding:
icon: upload-cloud
color: gray-dark
inputs:
paragonKey:
type: string
required: true
paragonZeusUrl:
type: string
required: false
default: "https://zeus.useparagon.com"
paragonDashboardUrl:
type: string
required: false
default: "https://dashboard.useparagon.com"
subfolder:
type: string
required: false
default: '.'
runs:
using: 'composite'
steps:
- name: Validate Paragon Git-sync Connection
id: validateGitSync
env:
PARAGON_CLI_KEY: ${{ inputs.paragonKey }}
PARAGON_HOST_ZEUS: ${{ inputs.paragonZeusUrl }}
COMMIT_AUTHOR: ${{ github.event.head_commit.author.name }}
shell: bash
run: |
request_output=$(curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $PARAGON_CLI_KEY" \
-d "{ \"branchName\": \"${{ github.ref_name }}\", \"author\": \"$COMMIT_AUTHOR\", \"runId\": \"${{ github.run_id }}\", \"hash\": \"${{ github.sha }}\" }" \
$PARAGON_HOST_ZEUS/graphite/projects/commit)
commitId=$(echo "$request_output" | jq -r '.commitId')
projectId=$(echo "$request_output" | jq -r '.projectId')
subfolder=$(echo "$request_output" | jq -r '.subfolder')
echo "commitId=$commitId" >> $GITHUB_OUTPUT
echo "projectId=$projectId" >> $GITHUB_OUTPUT
echo "subfolder=$subfolder" >> $GITHUB_OUTPUT
- name: Validate Dependency
id: validate
shell: bash
run: |
if [ "${{ steps.validateGitSync.outputs.projectId }}" = "null" ] || [ "${{ steps.validateGitSync.outputs.commitId }}" = "null" ]; then
echo "::warning::Branch \"${{ github.ref_name }}\" is not linked to any projects in Paragon.
See docs on setting up Git Sync for a branch: https://docs.useparagon.com/paragraph/setting-up-git-sync
Proceeding with a build-only run (no contents will be pushed to Paragon)..."
echo "valid=false" >> $GITHUB_OUTPUT
elif [ -z "${{ inputs.paragonKey }}" ]; then
echo "::warning:: \"paragonKey\" is not provided."
echo "valid=false" >> $GITHUB_OUTPUT
elif [ -z "${{ inputs.paragonZeusUrl }}" ]; then
echo "::warning:: \"paragonZeusUrl\" is not provided."
echo "valid=false" >> $GITHUB_OUTPUT
elif [ -z "${{ inputs.paragonDashboardUrl }}" ]; then
echo "::warning:: \"paragonDashboardUrl\" is not provided."
echo "valid=false" >> $GITHUB_OUTPUT
else
echo "valid=true" >> $GITHUB_OUTPUT
fi
- name: Setup Node.js environment
uses: actions/[email protected]
with:
node-version: v18.17.1
- name: Install para CLI globally
shell: bash
run: |
npm install -g @useparagon/cli
- name: Authenticate into CLI
env:
PARAGON_CLI_KEY: ${{ inputs.paragonKey }}
PARAGON_HOST_DASHBOARD: ${{ inputs.paragonDashboardUrl }}
PARAGON_HOST_ZEUS: ${{ inputs.paragonZeusUrl }}
shell: bash
run: |
mkdir -p ~/.paragon
cat << EOF > ~/.paragon/credentials.json
{
"default": {
"profile": "default",
"token": "$PARAGON_CLI_KEY"
}
}
EOF
cat << EOF > ~/.paragon/profiles.json
{
"default": {
"name": "default",
"default": true,
"services": {
"zeus": "$PARAGON_HOST_ZEUS",
"dashboard": "$PARAGON_HOST_DASHBOARD"
}
}
}
EOF
- name: Build Paragraph project
shell: bash
working-directory: ${{ inputs.subfolder }}
run: |
npx para install
npx para build
- name: Push to Paragon
shell: bash
working-directory: ${{ inputs.subfolder }}
if: github.event_name == 'push' && steps.validate.outputs.valid == 'true'
run: npx para push
# Post steps
- name: Update success status in Paragon
shell: bash
env:
PARAGON_CLI_KEY: ${{ inputs.paragonKey }}
PARAGON_HOST_ZEUS: ${{ inputs.paragonZeusUrl }}
PROJECT_ID: ${{ steps.validateGitSync.outputs.projectId }}
COMMIT_ID: ${{ steps.validateGitSync.outputs.commitId }}
if: success() && steps.validate.outputs.valid == 'true'
run: |
echo "Commit succeeded!"
curl -X PATCH \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $PARAGON_CLI_KEY" \
-d "{ \"projectId\": \"$PROJECT_ID\", \"commitId\": \"$COMMIT_ID\", \"runId\": \"${{ github.run_id }}\", \"success\": true, \"hash\": \"${{ github.sha }}\" }" \
$PARAGON_HOST_ZEUS/graphite/projects/commit
- name: Update failed status in Paragon
shell: bash
env:
PARAGON_CLI_KEY: ${{ inputs.paragonKey }}
PARAGON_HOST_ZEUS: ${{ inputs.paragonZeusUrl }}
PROJECT_ID: ${{ steps.validateGitSync.outputs.projectId }}
COMMIT_ID: ${{ steps.validateGitSync.outputs.commitId }}
if: failure() && steps.validate.outputs.valid == 'true'
run: |
echo "Commit failed!"
curl -X PATCH \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $PARAGON_CLI_KEY" \
-d "{ \"projectId\": \"$PROJECT_ID\", \"commitId\": \"$COMMIT_ID\", \"runId\": \"${{ github.run_id }}\", \"success\": false }" \
$PARAGON_HOST_ZEUS/graphite/projects/commit