-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
90 lines (83 loc) · 3.13 KB
/
action.yml
File metadata and controls
90 lines (83 loc) · 3.13 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
83
84
85
86
87
88
89
90
name: 'Shipstatic'
description: 'Deploy a static site to Shipstatic and link it to your domain'
branding:
icon: 'upload-cloud'
color: 'blue'
inputs:
api-key:
description: 'Shipstatic API key'
required: true
path:
description: 'Directory to deploy'
required: false
default: '.'
domain:
description: 'Domain to link to the deployment'
required: false
github-token:
description: 'GitHub token for PR comments and deployment tracking'
required: false
outputs:
id:
description: 'Deployment ID'
value: ${{ steps.deploy.outputs.id }}
url:
description: 'Deployment URL'
value: ${{ steps.deploy.outputs.url }}
runs:
using: 'composite'
steps:
- name: Install Shipstatic CLI
shell: bash
run: npm install -g @shipstatic/ship@latest
- name: Deploy
id: deploy
shell: bash
env:
SHIP_API_KEY: ${{ inputs.api-key }}
SHIP_VIA: git
DEPLOY_PATH: ${{ inputs.path }}
GIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
run: |
OUTPUT=$(ship "$DEPLOY_PATH" --label "${GIT_SHA:0:7}" --json --no-color)
echo "id=$(echo "$OUTPUT" | jq -r 'select(.deployment) | .deployment')" >> "$GITHUB_OUTPUT"
echo "url=$(echo "$OUTPUT" | jq -r 'select(.url) | .url')" >> "$GITHUB_OUTPUT"
- name: Link domain
if: ${{ inputs.domain != '' && steps.deploy.outputs.id != '' }}
shell: bash
env:
SHIP_API_KEY: ${{ inputs.api-key }}
DOMAIN: ${{ inputs.domain }}
DEPLOYMENT_ID: ${{ steps.deploy.outputs.id }}
run: ship domains set "$DOMAIN" "$DEPLOYMENT_ID" --json --no-color
- name: Create GitHub deployment
if: ${{ inputs.github-token != '' && steps.deploy.outputs.url != '' }}
continue-on-error: true
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token }}
GH_REPO: ${{ github.repository }}
GH_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
GH_EVENT: ${{ github.event_name }}
DEPLOY_URL: ${{ steps.deploy.outputs.url }}
run: |
ENVIRONMENT=$([[ "$GH_EVENT" == "pull_request" ]] && echo "preview" || echo "production")
PAYLOAD=$(jq -n --arg ref "$GH_SHA" --arg env "$ENVIRONMENT" \
'{ref: $ref, environment: $env, auto_merge: false, required_contexts: []}')
ID=$(echo "$PAYLOAD" | gh api "repos/$GH_REPO/deployments" --input - --jq '.id')
gh api "repos/$GH_REPO/deployments/$ID/statuses" \
-f state=success \
-f environment_url="$DEPLOY_URL"
- name: Comment on PR
if: ${{ inputs.github-token != '' && steps.deploy.outputs.url != '' && github.event_name == 'pull_request' }}
continue-on-error: true
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token }}
GH_REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
DEPLOY_URL: ${{ steps.deploy.outputs.url }}
run: |
COMMENT="Deployed to $DEPLOY_URL"
gh pr comment "$PR_NUMBER" --repo "$GH_REPO" --body "$COMMENT" --edit-last 2>/dev/null ||
gh pr comment "$PR_NUMBER" --repo "$GH_REPO" --body "$COMMENT"