generated from NellowTCS/Web-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (97 loc) · 3.56 KB
/
send-beta-build.yml
File metadata and controls
118 lines (97 loc) · 3.56 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
name: Deploy to Beta
on:
push:
branches:
- main
concurrency:
group: "deploy-beta"
cancel-in-progress: false
permissions:
contents: read
jobs:
send:
runs-on: ubuntu-latest
outputs:
artifact-url: ${{ steps.get-artifact.outputs.url }}
zip-name: ${{ steps.set-zip-name.outputs.zip_name }}
steps:
- name: Checkout source repo
uses: actions/checkout@v4
with:
ref: main
- name: Determine subfolder and zip name
id: set-zip-name
run: |
SUBFOLDER="${{ github.event.repository.name }}"
ZIP_NAME="$(echo "${SUBFOLDER}" | tr '[:upper:]' '[:lower:]')-build.zip"
echo "Subfolder: ${SUBFOLDER}"
echo "Zip name: ${ZIP_NAME}"
echo "subfolder=${SUBFOLDER}" >> "$GITHUB_OUTPUT"
echo "zip_name=${ZIP_NAME}" >> "$GITHUB_OUTPUT"
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install dependencies
working-directory: Build
run: npm i
- name: Build
working-directory: Build
run: npm run build
- name: Zip build artifacts
run: |
ZIP_NAME="${{ steps.set-zip-name.outputs.zip_name }}"
echo "Creating zip: ${ZIP_NAME}"
zip -r "${ZIP_NAME}" Build/dist
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.set-zip-name.outputs.zip_name }}
path: ${{ steps.set-zip-name.outputs.zip_name }}
retention-days: 1
- name: Get artifact download URL
id: get-artifact
uses: actions/github-script@v7
with:
script: |
const zipName = process.env.ZIP_NAME;
const { owner, repo } = context.repo;
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner,
repo,
run_id: context.runId
});
const artifact = artifacts.data.artifacts.find(a => a.name === zipName);
if (!artifact) {
core.setFailed(`Artifact with name ${zipName} not found`);
return;
}
core.setOutput('url', artifact.archive_download_url);
env:
ZIP_NAME: ${{ steps.set-zip-name.outputs.zip_name }}
- name: Dispatch to beta repo
run: |
set -euo pipefail
BETA_REPO="${{ github.repository_owner }}/beta"
SUBFOLDER="${{ steps.set-zip-name.outputs.subfolder }}"
ARTIFACT_URL="${{ steps.get-artifact.outputs.url }}"
ZIP_NAME="${{ steps.set-zip-name.outputs.zip_name }}"
echo "Dispatching to: ${BETA_REPO}"
echo "With:"
echo " subfolder: ${SUBFOLDER}"
echo " artifact_url: ${ARTIFACT_URL}"
echo " zip_name: ${ZIP_NAME}"
JSON=$(jq -n \
--arg event_type "deploy-build" \
--arg source_repo "${{ github.repository }}" \
--arg artifact_url "$ARTIFACT_URL" \
--arg token "${{ secrets.GITHUB_TOKEN }}" \
--arg subfolder "$SUBFOLDER" \
--arg zip_name "$ZIP_NAME" \
'{event_type: $event_type, client_payload: {source_repo: $source_repo, artifact_url: $artifact_url, token: $token, subfolder: $subfolder, zip_name: $zip_name}}' \
)
curl -X POST \
-H "Authorization: token ${{ secrets.BETA_PAT_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/${BETA_REPO}/dispatches \
-d "$JSON"