-
Notifications
You must be signed in to change notification settings - Fork 2
89 lines (76 loc) · 3.15 KB
/
test-meticulous-create-deployment.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
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
# Demo workflow for tagging GitHub commits with existing preview URLs
#
# For this to work preview URLs must be:
#
# 1. Per commit, so that even if new commits are pushed to the same branch the old build override URL still serves the original commit
# 2. Live for at least one week, ideally 2 weeks
#
# Rolling your own preview URLs is complex. We strongly recommend using [Vercel](https://app.meticulous.ai/docs/cloud-replay) or
# the [Meticulous GitHub action to run Meticulous tests](https://app.meticulous.ai/docs/github-actions-v2).
name: Create GitHub deployment
on:
push:
branches:
- main
- releases/*
pull_request: {}
workflow_dispatch: {}
permissions:
contents: write
deployments: write
jobs:
create-deployment:
name: Create GitHub deployment
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Create Preview URL
id: create-url
run: |
# Generate the preview URL (you can modify this logic to suit your needs)
PREVIEW_URL="https://example.org/example/preview/url/for/$GITHUB_SHA"
echo "Preview URL: $PREVIEW_URL"
# Set it as an output for the next step
echo "preview_url=$PREVIEW_URL" >> $GITHUB_OUTPUT
- name: Create Deployment
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_SHA: ${{ github.sha }}
GITHUB_REF: ${{ github.ref }}
PREVIEW_URL: ${{ steps.create-url.outputs.preview_url }}
ENVIRONMENT_NAME: "preview"
run: |
OWNER=$(echo $GITHUB_REPOSITORY | cut -d'/' -f1)
REPO=$(echo $GITHUB_REPOSITORY | cut -d'/' -f2)
DESCRIPTION="Deployment of $GITHUB_SHA"
LOG_URL="https://github.com/$OWNER/$REPO/commit/$GITHUB_SHA/checks"
echo "$GITHUB_REPOSITORY"
echo "Curling https://api.github.com/repos/$OWNER/$REPO/deployments"
# Create deployment
RESPONSE=$(curl -X POST \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/$OWNER/$REPO/deployments \
-d "{\"ref\":\"$GITHUB_REF\",\"environment\":\"$ENVIRONMENT_NAME\",\"payload\":{ \"web_url\": \"$PREVIEW_URL\" },\"description\":\"$DESCRIPTION\"}")
echo $RESPONSE
DEPLOYMENT_ID=$(echo $RESPONSE | jq -r '.id')
echo "Created deployment with ID: $DEPLOYMENT_ID"
# Create deployment status
curl -s -X POST \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/$OWNER/$REPO/deployments/$DEPLOYMENT_ID/statuses \
-d @- <<EOF
{
"state": "success",
"log_url": "$LOG_URL",
"environment": "$ENVIRONMENT_NAME",
"environment_url": "$PREVIEW_URL",
"description": "$DESCRIPTION"
}
EOF
echo "Created deployment status"