|
| 1 | +name: CI |
1 | 2 | on:
|
2 |
| - push |
3 |
| - |
4 |
| -name: ci |
5 |
| - |
| 3 | + pull_request: |
| 4 | + push: |
6 | 5 | jobs:
|
7 |
| - build: |
| 6 | + build-tag-push-deploy: |
8 | 7 | runs-on: ubuntu-latest
|
| 8 | + if: > |
| 9 | + github.ref == 'refs/heads/main' || |
| 10 | + github.ref == 'refs/heads/dev' |
9 | 11 | steps:
|
10 |
| - - uses: actions/checkout@v2 |
11 |
| - with: |
12 |
| - # submodules: true # Fetch Hugo themes (true OR recursive) |
13 |
| - fetch-depth: 1 |
14 |
| - |
| 12 | + - name: Checkout code |
| 13 | + uses: actions/checkout@v2 |
15 | 14 | - name: Login to GitHub Container Registry
|
16 | 15 | uses: docker/login-action@v1
|
17 | 16 | with:
|
18 | 17 | registry: ghcr.io
|
19 | 18 | username: cmu-delphi-deploy-machine
|
20 | 19 | password: ${{ secrets.CMU_DELPHI_DEPLOY_MACHINE_PAT }}
|
21 |
| - |
22 |
| - - name: Build, tag, and push image to Github |
23 |
| - env: |
24 |
| - DEVOPS_DOCKER_FILE: ./devops/Dockerfile |
| 20 | + - name: Build, tag, and push image to GitHub Container Registry |
| 21 | + id: image |
25 | 22 | run: |
|
26 | 23 | baseRef="${GITHUB_REF#*/}"
|
27 | 24 | baseRef="${baseRef#*/}"
|
28 | 25 | case "${baseRef}" in
|
29 | 26 | main)
|
30 |
| - imageTag="latest" |
| 27 | + image_tag="latest" |
31 | 28 | ;;
|
32 | 29 | *)
|
33 |
| - imageTag="${baseRef//\//_}" # replace `/` with `_` in branch name |
| 30 | + image_tag="${baseRef//\//_}" # replace `/` with `_` in branch name |
34 | 31 | ;;
|
35 | 32 | esac
|
36 |
| - echo "using tag: --${imageTag}--" |
37 |
| - docker build -t ghcr.io/${{ github.repository }}:$imageTag --file ${DEVOPS_DOCKER_FILE} . |
38 |
| - docker push ghcr.io/${{ github.repository }}:$imageTag |
39 |
| -
|
40 |
| - # trigger a webhook update |
| 33 | + cd ${{ github.workspace }} |
| 34 | + echo "using tag: --${image-tag}--" |
| 35 | + docker build -t ghcr.io/${{ github.repository }}:${image_tag} --file ./devops/Dockerfile . |
| 36 | + docker push ghcr.io/${{ github.repository }}:${image_tag} |
| 37 | + echo "IMAGE_TAG=${image_tag}" >> $GITHUB_OUTPUT |
| 38 | + - name: Trigger smee.io webhook to deploy new container image |
| 39 | + run: | |
41 | 40 | curl -H "Authorization: Bearer ${{ secrets.DELPHI_DEPLOY_WEBHOOK_TOKEN }}" \
|
42 | 41 | -X POST ${{ secrets.DELPHI_DEPLOY_WEBHOOK_URL }} \
|
43 | 42 | -H "Content-Type: application/x-www-form-urlencoded" \
|
44 |
| - -d "repository=ghcr.io/${{ github.repository }}&tag=$imageTag" |
| 43 | + -d "repository=ghcr.io/${{ github.repository }}&tag=${{ steps.image.outputs.IMAGE_TAG }}" |
0 commit comments