-
Notifications
You must be signed in to change notification settings - Fork 87
69 lines (66 loc) · 2.63 KB
/
preview.yml
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
name: PR preview
on:
pull_request:
types: [opened, reopened, synchronize, closed]
paths:
- 'src/**'
- 'public/**'
- 'package*.json'
- '.env'
- 'jsconfig.json'
- '.github/workflows/preview.yml'
env:
PULL_NUMBER: ${{ github.event.pull_request.number }}
jobs:
clean-up:
runs-on: ubuntu-latest
if: ${{ github.event.action == 'closed' }}
steps:
- name: 🧹 Remove preview dir
run: |
eval $(ssh-agent -s)
ssh-add - <<< "${{ secrets.PREVIEW_SSH_PRIVATE_KEY }}"
ssh -o StrictHostKeyChecking=no ${{ vars.PREVIEW_HOST_USERNAME }}@${{ vars.PREVIEW_HOST_IP }} "rm -rf ${{ vars.PREVIEW_HOST_TARGET_DIR }}/$PULL_NUMBER"
deploy:
runs-on: ubuntu-latest
if: ${{ github.event.action != 'closed' }}
steps:
- uses: actions/checkout@v3
- name: 🏠 Replace homepage URL
run: sed -i "s/https:\/\/valhalla.openstreetmap.de/https:\/\/valhalla-app-tests.gis-ops.com\/${PULL_NUMBER}/g" package.json
- uses: actions/setup-node@v3
with:
node-version: '20.x'
- name: 🔧 Create build
run: |
npm install
npm run build
- name: 🚀 Preview deploy
run: |
eval $(ssh-agent -s)
ssh-add - <<< "${{ secrets.PREVIEW_SSH_PRIVATE_KEY }}"
rsync -r --delete --rsync-path="mkdir -p ${{ vars.PREVIEW_HOST_TARGET_DIR }}/$PULL_NUMBER && rsync" -e "ssh -o StrictHostKeyChecking=no" ./build/ ${{ vars.PREVIEW_HOST_USERNAME }}@${{ vars.PREVIEW_HOST_IP }}:${{ vars.PREVIEW_HOST_TARGET_DIR }}/$PULL_NUMBER
- name: 🌐 Preview URL
if: ${{ success() }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.PAT }}
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
const existingComment = comments.find(comment => comment.body.includes('Preview is ready! 🚀'));
if (!existingComment) {
const body = `Preview is ready! 🚀 You can view it here: https://valhalla-app-tests.gis-ops.com/${{ github.event.pull_request.number }}`;
const { data } = await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
console.log('Comment created successfully');
} else {
console.log('Comment already exists');
}