Repository navigation
92 lines (84 loc) · 3.39 KB
/
Copy pathplotly-cloud-deploy.yml
File metadata and controls
92 lines (84 loc) · 3.39 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
91
92
name: Plotly Cloud deploy
# PR opened/updated -> publish each changed app as "<app>-staging"
# PR merged -> delete "<app>-staging", then update/create the production app
# PR closed unmerged -> delete "<app>-staging"
on:
pull_request:
types: [opened, synchronize, reopened, closed]
branches: [main]
# One run per PR at a time; a new push cancels an in-flight staging deploy,
# but never cancel a merge deploy halfway through.
concurrency:
group: plotly-cloud-${{ github.event.pull_request.number }}
cancel-in-progress: ${{ github.event.action != 'closed' }}
permissions:
contents: read
pull-requests: write
env:
PLOTLY_API_KEY: ${{ secrets.PLOTLY_API_KEY }}
PLOTLY_TEAM: ${{ vars.PLOTLY_TEAM || 'Marketing' }}
PLOTLY_CLOUD_VERSION: "0.6.0"
GH_TOKEN: ${{ github.token }}
jobs:
changes:
runs-on: ubuntu-latest
outputs:
apps: ${{ steps.detect.outputs.apps }}
any: ${{ steps.detect.outputs.any }}
steps:
- uses: actions/checkout@v4
- id: detect
run: |
apps=$(python3 .github/scripts/plotly_cloud_ci.py changed "${{ github.event.pull_request.number }}")
echo "Changed apps: $apps"
echo "apps=$apps" >> "$GITHUB_OUTPUT"
[ "$apps" = "[]" ] && echo "any=false" >> "$GITHUB_OUTPUT" || echo "any=true" >> "$GITHUB_OUTPUT"
staging:
needs: changes
if: github.event.action != 'closed' && needs.changes.outputs.any == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install "plotly-cloud==${PLOTLY_CLOUD_VERSION}"
- name: Publish staging apps
env:
PR_COMMENT_FILE: ${{ runner.temp }}/comment.md
run: |
echo "<!-- plotly-cloud-staging -->" > "$PR_COMMENT_FILE"
python .github/scripts/plotly_cloud_ci.py staging $(echo '${{ needs.changes.outputs.apps }}' | jq -r '.[]')
- name: Comment staging links on the PR
if: always()
run: |
gh pr comment "${{ github.event.pull_request.number }}" \
--body-file "${{ runner.temp }}/comment.md" --edit-last --create-if-none
teardown:
needs: changes
if: github.event.action == 'closed' && needs.changes.outputs.any == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install "plotly-cloud==${PLOTLY_CLOUD_VERSION}"
- name: Delete staging apps
run: python .github/scripts/plotly_cloud_ci.py teardown $(echo '${{ needs.changes.outputs.apps }}' | jq -r '.[]')
production:
needs: [changes, teardown]
# Run even if teardown failed: a leftover staging app shouldn't block the release.
if: ${{ !cancelled() && github.event.action == 'closed' && github.event.pull_request.merged == true && needs.changes.outputs.any == 'true' }}
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.merge_commit_sha }}
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install "plotly-cloud==${PLOTLY_CLOUD_VERSION}"
- name: Publish production apps
run: python .github/scripts/plotly_cloud_ci.py production $(echo '${{ needs.changes.outputs.apps }}' | jq -r '.[]')