-
Notifications
You must be signed in to change notification settings - Fork 47
85 lines (75 loc) · 2.84 KB
/
deploy-test.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: Test Deploy
on:
workflow_run:
workflows: ["Build & test"]
types: [completed]
jobs:
deploy:
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success' && github.repository_owner == 'elan-ev'
steps:
- name: Prepare deploy key
run: |
mkdir ~/.ssh
chmod 700 ~/.ssh
echo "${{ secrets.STUDIO_TEST_DEPLOY_KEY }}" | base64 -d > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
# Unfortunately we cannot use `actions/download-artifact` here since that
# only allows to download artifacts from the same run.
- name: Download artifacts from build workflow
uses: actions/github-script@v6
with:
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
const deployFiles = artifacts.data.artifacts
.filter(a => a.name == "test-deployment-files")[0];
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: deployFiles.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.writeFileSync('${{github.workspace}}/artifacts.zip', Buffer.from(download.data));
// The artifact is not needed anymore
github.rest.actions.deleteArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: deployFiles.id,
})
- name: extract artifacts
run: unzip artifacts.zip
- name: Checkout test deployment repo
run: |
rm -rf studio-test || :
git clone "[email protected]:elan-ev/studio-test.git"
cd studio-test
git checkout gh-pages
- name: Prepare deployment files
run: |
deploydir=$(cat deploydir.tmp)
mkdir studio-test/${deploydir}
mv .github/.deploy-settings.toml studio-test/${deploydir}/settings.toml
mv build/* studio-test/${deploydir}/
rmdir build
- name: Build new index HTML
working-directory: studio-test
run: |
echo '<html><body><ul>' > index.html
find . -maxdepth 1 -name '20*' -type d \
| sort -r \
| sed 's/^\(.*\)$/<li><a href=\1>\1<\/a><\/li>/' >> index.html
echo '</ul></body></html>' >> index.html
- name: Commit and push
working-directory: studio-test
run: |
git add .
git config --global user.name 'GitHub Actions'
git config --global user.email '[email protected]'
git commit -m "Deploy ${{ github.event.workflow_run.head_sha }} ($(date))"
git push origin gh-pages