-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (68 loc) · 3.07 KB
/
Copy pathdeployStatic.yaml
File metadata and controls
82 lines (68 loc) · 3.07 KB
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
# This workflow generates the API Portal using APIMatic and publishes to Cloudflare Pages
name: Generate API Portal
on:
workflow_dispatch:
jobs:
Generate-Portal:
runs-on: ubuntu-latest
steps:
# Checkout repo
- uses: actions/checkout@v3
- name: Print branch
run: echo '${{ github.ref }}'
# Zip only the src folder
- name: Zip src folder for production deployment
if: endsWith(github.ref, '/main')
run: zip -qq -r portal-input.zip src -x '/.git/*' '/.github/*' '/portal/*'
# Call Apimatic Endpoint to generate Portal
- name: Generate Portal
id: generate-portal
run: |
RESPONSE=`curl -s --write-out '%{http_code}\t%{content_type}' --request POST --url 'https://api.apimatic.io/portal' \
-H 'Authorization:X-Auth-Key ${{ secrets.API_KEY }}' -F 'file=@portal-input.zip' -OJ`;
HTTP_CODE=$(echo $RESPONSE | cut -d " " -f 1);
CONTENT_TYPE=$(echo $RESPONSE | cut -d " " -f 2);
echo "HTTP_CODE=$HTTP_CODE" >> $GITHUB_OUTPUT;
echo "CONTENT_TYPE=$CONTENT_TYPE" >> $GITHUB_OUTPUT;
# Print error output if portal generation fails
- name: Print Portal Generation Error
if: steps.generate-portal.outputs.HTTP_CODE != '200'
run: |
echo "Portal generation failed. Printing error output:"
if [ -f error.zip ]; then
unzip -p error.zip error.txt || echo "Could not extract error.txt from error.zip"
elif [ -f error.txt ]; then
cat error.txt
else
echo "No error.txt or error.zip found. Check previous logs for details."
fi
# Unzip the generated Portal output
- name: Unzip Portal
if: ${{ steps.generate-portal.outputs.HTTP_CODE == '200' }}
run: unzip -qq portal.zip -d portal
# Upload Portal Artifact
- name: Upload Artifact
if: ${{ steps.generate-portal.outputs.HTTP_CODE == '200' }}
uses: actions/upload-artifact@v4
with:
name: portal
path: portal
# Unzip error file if error code is 422 with a zip file
- name: Unzip error file
if: ${{ steps.generate-portal.outputs.HTTP_CODE == '422' && steps.generate-portal.outputs.CONTENT_TYPE == 'application/zip' }}
run: unzip -qq error.zip -d error
# Upload error.zip if error code is 422 with a zip file
- name: Upload error.zip
if: ${{ steps.generate-portal.outputs.HTTP_CODE == '422' && steps.generate-portal.outputs.CONTENT_TYPE == 'application/zip' }}
uses: actions/upload-artifact@v4
with:
name: error
path: error.zip
# Publish updates to Cloudflare
- name: Publish to Cloudflare Pages to test
if: steps.generate-portal.outputs.HTTP_CODE == '200'
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy portal --branch=main --project-name=${{ secrets.CLOUDFLARE_PROJECT_NAME }}