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,46 @@ 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+
31+ deploy :
32+ runs-on : ubuntu-latest
33+ needs : build
34+ if : github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
35+ steps :
36+ - name : Download artifact
37+ uses : actions/download-artifact@v3
38+ with :
39+ name : qcext-server-tar-bz2
40+
2241 - name : Deploy
2342 run : docker-compose run deploy
2443 env :
2544 DEPLOY_KEY : ${{ secrets.deploy_key }}
2645 DEPLOY_TARGET : ${{ secrets.deploy_target }}
2746 DEPLOY_USER : ${{ secrets.deploy_user }}
47+
48+ cleanup_job :
49+ needs : [deploy]
50+ runs-on : ubuntu-latest
51+ steps :
52+ - name : Delete artifacts
53+ env :
54+ FOR_WEBHOOKS_SECRET : ${{ secrets.FOR_WEBHOOKS_SECRET }}
55+ run : |
56+ echo "::add-mask::$FOR_WEBHOOKS_SECRET"
57+ 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