Skip to content

Commit

Permalink
ci: build project on all branches/PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyvion committed Mar 25, 2023
1 parent 953d2c2 commit 840f839
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/webhook_target.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Delete calling job's artifacts
on: repository_dispatch
jobs:
main:
runs-on: ubuntu-latest
steps:
- name: Delete artifacts
if: github.event.action == 'delete_all_artifacts'
uses: christian-korneck/delete-run-artifacts-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
parent_runid: ${{ github.event.client_payload.parent_runid }}
parent_repo: ${{ github.event.client_payload.parent_repo }}
38 changes: 34 additions & 4 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
name: Build and Deploy

on:
push:
branches: [main]
on: [push, pull_request]

jobs:
build-and-deploy:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -14,14 +12,46 @@ jobs:
run: docker build -t qcext-server .

- name: Save Docker image
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
run: docker save -o qcext-server.tar qcext-server

- name: Compress Docker image
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
run: bzip2 -z qcext-server.tar

- name: Upload artifact
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
uses: actions/upload-artifact@v3
with:
name: qcext-server-tar-bz2
path: |
qcext-server.tar.bz2
docker-compose.yml
deploy:
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: qcext-server-tar-bz2

- name: Deploy
run: docker-compose run deploy
env:
DEPLOY_KEY: ${{ secrets.deploy_key }}
DEPLOY_TARGET: ${{ secrets.deploy_target }}
DEPLOY_USER: ${{ secrets.deploy_user }}

cleanup_job:
needs: [deploy]
runs-on: ubuntu-latest
steps:
- name: Delete artifacts
env:
FOR_WEBHOOKS_SECRET: ${{ secrets.FOR_WEBHOOKS_SECRET }}
run: |
echo "::add-mask::$FOR_WEBHOOKS_SECRET"
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 comments on commit 840f839

Please sign in to comment.