-
Notifications
You must be signed in to change notification settings - Fork 1
135 lines (109 loc) · 4.81 KB
/
test-and-deploy.yml
File metadata and controls
135 lines (109 loc) · 4.81 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: Test & Deploy
on:
pull_request:
branches: [ staging, main ]
push:
branches: [ staging, main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: npm ci
- name: Install Playwright Chromium only
run: npx playwright install chromium
# Debug: show repo info for clarity
- name: Debug PR origin
run: |
echo "PR repo: ${{ github.event.pull_request.head.repo.full_name }}"
echo "Base repo: ${{ github.repository }}"
# Fetch locations — only for trusted branches & same-repo PRs
- name: Fetch locations JSON
if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository }}
env:
MONGODB_URI: ${{ secrets.MONGODB_URI }}
run: |
echo "Running fetch-locations with MONGODB_URI..."
npm run fetch:locations
# Skip fetch for fork PRs, log clearly
- name: Skip fetch for fork PRs
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository }}
run: |
echo "⏭️ Skipping fetch-locations: fork PRs cannot access secrets."
# Build & test: trusted branches / same-repo PRs
- name: Run all tests and build (trusted)
if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository }}
env:
MONGODB_URI: ${{ secrets.MONGODB_URI }}
run: |
echo "Running build with DB fetch..."
npm run build
# Build & test: fork PRs, skip prebuild by env flag
- name: Run all tests and build (fork PRs, skip prebuild)
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository }}
env:
SKIP_FETCH: "true"
run: |
echo "Running build with SKIP_FETCH=true for fork PR..."
npm run build
- name: Upload Playwright test results
if: always()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: playwright-report/
deploy:
needs: test
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Notify Slack that tests passed
if: success()
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
BRANCH=$(echo $GITHUB_REF | sed 's#refs/heads/##')
PAYLOAD="{
\"text\": \":white_check_mark: Tests passed on *$BRANCH* — <https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}|View Run>\"
}"
curl -X POST -H 'Content-type: application/json' --data "$PAYLOAD" $SLACK_WEBHOOK_URL
- name: Move Trello Card to Done (using PR title)
if: github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/main'
env:
TRELLO_API_KEY: ${{ secrets.TRELLO_API_KEY }}
TRELLO_API_TOKEN: ${{ secrets.TRELLO_API_TOKEN }}
TRELLO_BOARD_ID: ${{ secrets.TRELLO_BOARD_ID }}
TRELLO_DONE_LIST_ID: ${{ secrets.TRELLO_DONE_LIST_ID }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
MERGE_COMMIT_MSG=$(git log -1 --pretty=%B)
echo "Merge commit message: $MERGE_COMMIT_MSG"
PR_NUMBER=$(echo "$MERGE_COMMIT_MSG" | grep -oE '#[0-9]+' | tr -d '#')
echo "Extracted PR number: $PR_NUMBER"
if [ -z "$PR_NUMBER" ]; then
echo "No PR number found in commit message — skipping Trello move."
exit 0
fi
PR_TITLE=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/$PR_NUMBER" | jq -r '.title')
echo "Original PR title: $PR_TITLE"
NORMALISED_TITLE=$(echo "$PR_TITLE" | sed 's/ /-/g')
echo "Normalised PR title: $NORMALISED_TITLE"
CARD_ID=$(curl -s "https://api.trello.com/1/boards/$TRELLO_BOARD_ID/cards?key=$TRELLO_API_KEY&token=$TRELLO_API_TOKEN" \
| jq -r --arg TITLE "$NORMALISED_TITLE" '.[] | select(.name | test($TITLE; "i")) | .id')
if [ -z "$CARD_ID" ]; then
echo "⚠️ No matching Trello card found — skipping move."
exit 0
fi
echo "✅ Found Trello card ID: $CARD_ID"
curl -s -X PUT "https://api.trello.com/1/cards/$CARD_ID?idList=$TRELLO_DONE_LIST_ID&key=$TRELLO_API_KEY&token=$TRELLO_API_TOKEN"