Skip to content

Commit 840f839

Browse files
committed
ci: build project on all branches/PRs
1 parent 953d2c2 commit 840f839

2 files changed

Lines changed: 48 additions & 4 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Delete calling job's artifacts
2+
on: repository_dispatch
3+
jobs:
4+
main:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Delete artifacts
8+
if: github.event.action == 'delete_all_artifacts'
9+
uses: christian-korneck/delete-run-artifacts-action@v1
10+
env:
11+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12+
with:
13+
parent_runid: ${{ github.event.client_payload.parent_runid }}
14+
parent_repo: ${{ github.event.client_payload.parent_repo }}

.github/workflows/workflow.yml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
name: Build and Deploy
22

3-
on:
4-
push:
5-
branches: [main]
3+
on: [push, pull_request]
64

75
jobs:
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

Comments
 (0)