Repository navigation
161 lines (144 loc) · 5.84 KB
/
Copy pathpr-batch-test-deploy.yml
File metadata and controls
161 lines (144 loc) · 5.84 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
name: PR Batch Test Deploy
on:
workflow_dispatch:
inputs:
pr_numbers:
description: "Comma/newline separated PR numbers to merge onto the base branch"
required: true
type: string
base_ref:
description: "Base branch to build from"
required: false
default: main
type: string
deploy_channel:
description: "Floating image tag used by the shared HK test machine"
required: false
default: manual-test-hk
type: string
concurrency:
group: pr-batch-test-runtime
cancel-in-progress: false
permissions:
contents: read
packages: write
pull-requests: read
env:
DOCKER_PLATFORM: linux/amd64
jobs:
build-and-deploy:
name: Build And Deploy Manual Test Batch
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Ensure helper scripts are executable
run: chmod +x scripts/prepare-pr-batch.sh scripts/deploy-test-runtime.sh
- name: Validate deploy secrets
env:
TEST_RUNTIME_SSH_HOST: ${{ secrets.TEST_RUNTIME_SSH_HOST }}
TEST_RUNTIME_SSH_KEY: ${{ secrets.TEST_RUNTIME_SSH_KEY }}
run: |
[[ -n "${TEST_RUNTIME_SSH_HOST}" ]] || { echo "::error::Missing secret TEST_RUNTIME_SSH_HOST"; exit 1; }
[[ -n "${TEST_RUNTIME_SSH_KEY}" ]] || { echo "::error::Missing secret TEST_RUNTIME_SSH_KEY"; exit 1; }
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Merge selected PRs onto base ref
id: batch
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
scripts/prepare-pr-batch.sh \
--pr-list "${{ inputs.pr_numbers }}" \
--base-ref "${{ inputs.base_ref }}" \
--deploy-channel "${{ inputs.deploy_channel }}"
- name: Build and push backend image
uses: docker/build-push-action@v6
with:
context: ./server
file: ./server/Dockerfile
platforms: ${{ env.DOCKER_PLATFORM }}
push: true
provenance: false
sbom: false
tags: |
ghcr.io/${{ github.repository_owner }}/skillhub-server:${{ steps.batch.outputs.deploy_tag }}
ghcr.io/${{ github.repository_owner }}/skillhub-server:${{ steps.batch.outputs.immutable_tag }}
cache-from: type=gha,scope=manual-test-server
cache-to: type=gha,mode=max,scope=manual-test-server
- name: Build and push frontend image
uses: docker/build-push-action@v6
with:
context: ./web
file: ./web/Dockerfile
platforms: ${{ env.DOCKER_PLATFORM }}
push: true
provenance: false
sbom: false
tags: |
ghcr.io/${{ github.repository_owner }}/skillhub-web:${{ steps.batch.outputs.deploy_tag }}
ghcr.io/${{ github.repository_owner }}/skillhub-web:${{ steps.batch.outputs.immutable_tag }}
cache-from: type=gha,scope=manual-test-web
cache-to: type=gha,mode=max,scope=manual-test-web
- name: Build and push scanner image
uses: docker/build-push-action@v6
with:
context: ./scanner
file: ./scanner/Dockerfile
platforms: ${{ env.DOCKER_PLATFORM }}
push: true
provenance: false
sbom: false
tags: |
ghcr.io/${{ github.repository_owner }}/skillhub-scanner:${{ steps.batch.outputs.deploy_tag }}
ghcr.io/${{ github.repository_owner }}/skillhub-scanner:${{ steps.batch.outputs.immutable_tag }}
cache-from: type=gha,scope=manual-test-scanner
cache-to: type=gha,mode=max,scope=manual-test-scanner
- name: Prepare deploy key
id: ssh
env:
TEST_RUNTIME_SSH_KEY: ${{ secrets.TEST_RUNTIME_SSH_KEY }}
run: |
key_file="${RUNNER_TEMP}/test-runtime.key"
printf '%s\n' "${TEST_RUNTIME_SSH_KEY}" > "${key_file}"
chmod 600 "${key_file}"
echo "key_file=${key_file}" >> "${GITHUB_OUTPUT}"
- name: Deploy batch images to HK test runtime
env:
TEST_RUNTIME_SSH_HOST: ${{ secrets.TEST_RUNTIME_SSH_HOST }}
TEST_RUNTIME_SSH_USER: ${{ secrets.TEST_RUNTIME_SSH_USER }}
TEST_RUNTIME_SSH_PORT: ${{ secrets.TEST_RUNTIME_SSH_PORT }}
run: |
ssh_port="${TEST_RUNTIME_SSH_PORT:-22}"
ssh_user="${TEST_RUNTIME_SSH_USER:-skillhub-deploy}"
scripts/deploy-test-runtime.sh \
--host "${TEST_RUNTIME_SSH_HOST}" \
--user "${ssh_user}" \
--port "${ssh_port}" \
--key-file "${{ steps.ssh.outputs.key_file }}" \
--deploy-tag "${{ steps.batch.outputs.deploy_tag }}" \
--immutable-tag "${{ steps.batch.outputs.immutable_tag }}" \
--merged-sha "${{ steps.batch.outputs.merged_sha }}" \
--pr-csv "${{ steps.batch.outputs.pr_csv }}" \
--run-url "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
- name: Publish final summary
run: |
{
echo "### HK manual test runtime updated"
echo
echo "- URL: \`https://skill.xf-yun.com.cn\`"
echo "- Base ref: \`${{ steps.batch.outputs.base_ref }}\`"
echo "- Floating tag: \`${{ steps.batch.outputs.deploy_tag }}\`"
echo "- Immutable tag: \`${{ steps.batch.outputs.immutable_tag }}\`"
echo "- Merged SHA: \`${{ steps.batch.outputs.merged_sha }}\`"
echo "- PR list: \`${{ steps.batch.outputs.pr_csv }}\`"
} >> "${GITHUB_STEP_SUMMARY}"