11name : Build and Deploy
22
3- on :
4- push :
5- branches : [main]
3+ on : [push, pull_request]
64
75jobs :
8- build-and-deploy :
6+ build :
97 runs-on : ubuntu-latest
108 steps :
119 - uses : actions/checkout@v3
@@ -14,14 +12,47 @@ jobs:
1412 run : docker build -t qcext-server .
1513
1614 - name : Save Docker image
15+ if : github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
1716 run : docker save -o qcext-server.tar qcext-server
1817
1918 - name : Compress Docker image
19+ if : github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
2020 run : bzip2 -z qcext-server.tar
2121
22+ - name : Upload artifact
23+ if : github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
24+ uses : actions/upload-artifact@v3
25+ with :
26+ name : qcext-server-tar-bz2
27+ path : |
28+ qcext-server.tar.bz2
29+ docker-compose.yml
30+ deploy.sh
31+
32+ deploy :
33+ runs-on : ubuntu-latest
34+ needs : build
35+ if : github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
36+ steps :
37+ - name : Download artifact
38+ uses : actions/download-artifact@v3
39+ with :
40+ name : qcext-server-tar-bz2
41+
2242 - name : Deploy
2343 run : docker-compose run deploy
2444 env :
2545 DEPLOY_KEY : ${{ secrets.deploy_key }}
2646 DEPLOY_TARGET : ${{ secrets.deploy_target }}
2747 DEPLOY_USER : ${{ secrets.deploy_user }}
48+
49+ cleanup_job :
50+ needs : [deploy]
51+ runs-on : ubuntu-latest
52+ steps :
53+ - name : Delete artifacts
54+ env :
55+ FOR_WEBHOOKS_SECRET : ${{ secrets.FOR_WEBHOOKS_SECRET }}
56+ run : |
57+ echo "::add-mask::$FOR_WEBHOOKS_SECRET"
58+ curl --verbose --fail --show-error --location --request POST "https://api.github.com/repos/$GITHUB_REPOSITORY/dispatches" --header "Authorization: token $FOR_WEBHOOKS_SECRET" --header 'Content-Type: application/json' --header 'Accept: application/vnd.github.everest-preview+json' --data-raw "{ \"event_type\": \"delete_all_artifacts\", \"client_payload\": {\"parent_runid\": \"$GITHUB_RUN_ID\", \"parent_repo\": \"$GITHUB_REPOSITORY\"} }"
0 commit comments