1+ name : Deploy PR Preview
2+ on :
3+ pull_request :
4+ types : [opened, reopened, synchronize, ready_for_review]
5+ jobs :
6+ build :
7+ runs-on : ubuntu-latest
8+ steps :
9+ - name : Check Out Repo
10+ uses : actions/checkout@v2
11+ with :
12+ registry-url : ' https://npm.pkg.github.com'
13+ - run : echo "registry=https://registry.yarnpkg.com/" > .npmrc
14+ - run : echo "@internxt:registry=https://npm.pkg.github.com" >> .npmrc
15+ # You cannot read packages from other private repos with GITHUB_TOKEN
16+ # You have to use a PAT instead https://github.com/actions/setup-node/issues/49
17+ - run : echo //npm.pkg.github.com/:_authToken=${{ secrets.PERSONAL_ACCESS_TOKEN }} >> .npmrc
18+ - run : echo "always-auth=true" >> .npmrc
19+ - name : Login to DockerHub
20+ uses : docker/login-action@v1
21+ with :
22+ username : ${{ secrets.DOCKERHUB_USERNAME }}
23+ password : ${{ secrets.DOCKERHUB_TOKEN }}
24+ - name : Set up Docker Buildx
25+ uses : docker/setup-buildx-action@v1
26+ - name : Build and push to ${{ github.event.repository.name}}-dev
27+ uses : docker/build-push-action@v2
28+ with :
29+ context : ./
30+ file : ./infrastructure/preview.Dockerfile
31+ push : true
32+ tags : ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}-dev:preview-${{ github.event.number }}-${{ github.event.pull_request.head.sha }}
33+ add_ready_for_preview_label :
34+ if : github.event.pull_request.draft == false
35+ runs-on : ubuntu-latest
36+ needs : build
37+ steps :
38+ - uses : actions-ecosystem/action-add-labels@v1
39+ with :
40+ labels : |
41+ ready-for-preview
42+ dispatch_update_deployment :
43+ needs : add_ready_for_preview_label
44+ runs-on : ubuntu-latest
45+ if : ${{ contains(github.event.pull_request.labels.*.name, 'deployed') }}
46+ steps :
47+ - name : Dispatch Update Preview Repository Command
48+ uses : myrotvorets/trigger-repository-dispatch-action@1.0.0
49+ with :
50+ token : ${{ secrets.PAT }}
51+ repo : internxt/environments
52+ type : update-preview-command
53+ payload : |
54+ {
55+ "github": {
56+ "payload": {
57+ "repository": {
58+ "name": "${{ github.event.repository.name }}",
59+ "full_name": "${{ github.event.repository.full_name }}"
60+ },
61+ "issue": {
62+ "number": ${{ github.event.number }},
63+ "labels": ${{ toJSON(github.event.pull_request.labels) }}
64+ }
65+ }
66+ },
67+ "slash_command": {
68+ "args": {
69+ "named": {
70+ "deployment": "${{ github.event.repository.name }}",
71+ "tag": "preview-${{ github.event.number }}-${{ github.event.pull_request.head.sha }}",
72+ "imageSuffix": "-dev"
73+ }
74+ }
75+ }
76+ }
77+ dispatch_check_deployment :
78+ needs : add_ready_for_preview_label
79+ runs-on : ubuntu-latest
80+ if : ${{ contains(github.event.pull_request.labels.*.name, 'preview') }}
81+ steps :
82+ - name : Dispatch Check Preview Repository Command
83+ uses : myrotvorets/trigger-repository-dispatch-action@1.0.0
84+ with :
85+ token : ${{ secrets.PAT }}
86+ repo : internxt/environments
87+ type : check-preview-command
88+ payload : |
89+ {
90+ "github": {
91+ "payload": {
92+ "repository": {
93+ "name": "${{ github.event.repository.name }}",
94+ "full_name": "${{ github.event.repository.full_name }}",
95+ "html_url": "${{ github.event.repository.html_url }}"
96+ },
97+ "issue": {
98+ "number": ${{ github.event.number }},
99+ "labels": ${{ toJSON(github.event.pull_request.labels) }},
100+ "pull_request": {
101+ "html_url": "${{ github.event.pull_request.html_url }}"
102+ }
103+ }
104+ }
105+ },
106+ "slash_command": {
107+ "args": {
108+ "named": {
109+ "notify": "true"
110+ }
111+ }
112+ }
113+ }
0 commit comments