|
1 | | -on: |
2 | | - push: |
3 | | - paths: # run only when an Rmd file changes |
4 | | - - "**.Rmd" |
5 | | - - "environment.yml" |
6 | | - - ".github/workflows/ci.yaml" |
7 | | - |
8 | 1 | name: ci |
9 | 2 |
|
| 3 | +on: push |
| 4 | + |
10 | 5 | jobs: |
11 | 6 | build: |
12 | 7 | runs-on: ubuntu-latest |
13 | 8 | steps: |
14 | 9 | - uses: actions/checkout@v2 |
15 | 10 | with: |
16 | 11 | # submodules: true # Fetch Hugo themes (true OR recursive) |
17 | | - fetch-depth: 3 |
18 | | - - name: Cache Conda |
19 | | - uses: actions/cache@v1 |
20 | | - with: |
21 | | - path: ~/conda_pkgs_dir |
22 | | - key: ${{ runner.os }}-conda6-${{ hashFiles('environment.yml') }} |
23 | | - restore-keys: | |
24 | | - ${{ runner.os }}-conda6- |
25 | | - - uses: conda-incubator/setup-miniconda@v2 |
26 | | - with: |
27 | | - python-version: 3.9 |
28 | | - mamba-version: "*" |
29 | | - channels: conda-forge,defaults |
30 | | - channel-priority: true |
31 | | - activate-environment: www-main |
32 | | - environment-file: environment.yml |
33 | | - auto-activate-base: false |
34 | | - use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly! |
35 | | - # - name: Conda info |
36 | | - # shell: bash -l {0} |
37 | | - # run: | |
38 | | - # conda info |
39 | | - # conda list |
40 | | - - name: Install R dependencies |
41 | | - shell: bash -l {0} |
42 | | - run: | |
43 | | - Rscript ./dependencies.R |
44 | | - - name: Restore Blogdown Cache |
45 | | - uses: actions/cache@v2 |
46 | | - with: |
47 | | - path: | |
48 | | - ./blogdown |
49 | | - key: ${{ runner.os }}-blogdown2-${{ hashFiles('environment.yml') }}-${{ hashFiles('content/blog/**.Rmd') }} |
50 | | - restore-keys: | |
51 | | - ${{ runner.os }}-blogdown2-${{ hashFiles('environment.yml') }}- |
52 | | - ${{ runner.os }}-blogdown2- |
53 | | - - name: Build site |
54 | | - shell: bash -l {0} |
55 | | - run: | |
56 | | - npm run build:blog |
57 | | -
|
58 | | - - uses: actions/upload-artifact@v2 |
59 | | - with: |
60 | | - name: blog |
61 | | - path: | |
62 | | - ./content/blog |
63 | | - ./static/blog |
| 12 | + fetch-depth: 3 # Fetch all history for .GitInfo and .Lastmod |
64 | 13 |
|
65 | | - - uses: actions/setup-node@v1 |
| 14 | + - uses: actions/setup-node@v2.1.5 |
66 | 15 | with: |
67 | | - node-version: "12" |
| 16 | + node-version: "14" |
68 | 17 | - uses: actions/cache@v2 |
69 | 18 | with: |
70 | 19 | path: ~/.npm |
71 | | - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} |
| 20 | + key: ${{ runner.os }}-node3-${{ hashFiles('**/package-lock.json') }} |
72 | 21 | restore-keys: | |
73 | | - ${{ runner.os }}-node- |
| 22 | + ${{ runner.os }}-node3- |
74 | 23 | - run: npm ci |
75 | 24 | - name: Lint |
76 | 25 | run: npm run lint |
|
81 | 30 | with: |
82 | 31 | name: website |
83 | 32 | path: ./public |
| 33 | + |
| 34 | + image: |
| 35 | + needs: build |
| 36 | + # only on tags and dev branch |
| 37 | + if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/dev' |
| 38 | + runs-on: ubuntu-latest |
| 39 | + steps: |
| 40 | + - name: Check out code |
| 41 | + uses: actions/checkout@v2 |
| 42 | + - name: Login to GitHub Container Registry |
| 43 | + uses: docker/login-action@v1 |
| 44 | + with: |
| 45 | + registry: ghcr.io |
| 46 | + username: cmu-delphi-deploy-machine |
| 47 | + password: ${{ secrets.CMU_DELPHI_DEPLOY_MACHINE_PAT }} |
| 48 | + - name: Build Image |
| 49 | + env: |
| 50 | + DEVOPS_DOCKER_FILE: ./devops/Dockerfile |
| 51 | + run: | |
| 52 | + docker build -t repo --file ${DEVOPS_DOCKER_FILE} . |
| 53 | + - name: Resolve Tag |
| 54 | + id: tagname |
| 55 | + run: | |
| 56 | + baseRef="${GITHUB_REF#*/}" |
| 57 | + imageTag="${baseRef#*/}" |
| 58 | + echo -n "::set-output name=tag::$imageTag" |
| 59 | + echo -n "::set-output name=repo::ghcr.io/${{ github.repository }}" |
| 60 | + - name: Push Image Tag |
| 61 | + run: | |
| 62 | + docker tag repo ${{ steps.tagname.outputs.repo }}:${{ steps.tagname.outputs.tag }} |
| 63 | + docker push ${{ steps.tagname.outputs.repo }}:${{ steps.tagname.outputs.tag }} |
| 64 | + - name: Trigger Webhook |
| 65 | + run: | |
| 66 | + # trigger a webhook update |
| 67 | + curl -H "Authorization: Bearer ${{ secrets.DELPHI_DEPLOY_WEBHOOK_TOKEN }}" \ |
| 68 | + -X POST ${{ secrets.DELPHI_DEPLOY_WEBHOOK_URL }} \ |
| 69 | + -H "Content-Type: application/x-www-form-urlencoded" \ |
| 70 | + -d "repository=${{ steps.tagname.outputs.repo }}&tag=${{ steps.tagname.outputs.tag }}" |
| 71 | + - name: Push Latest Tag |
| 72 | + if: startsWith(github.ref, 'refs/tags/v') |
| 73 | + run: | |
| 74 | + docker tag repo ${{ steps.tagname.outputs.repo }}:latest |
| 75 | + docker push ${{ steps.tagname.outputs.repo }}:latest |
| 76 | + - name: Trigger Latest Webhook |
| 77 | + if: startsWith(github.ref, 'refs/tags/v') |
| 78 | + run: | |
| 79 | + # trigger a webhook update |
| 80 | + curl -H "Authorization: Bearer ${{ secrets.DELPHI_DEPLOY_WEBHOOK_TOKEN }}" \ |
| 81 | + -X POST ${{ secrets.DELPHI_DEPLOY_WEBHOOK_URL }} \ |
| 82 | + -H "Content-Type: application/x-www-form-urlencoded" \ |
| 83 | + -d "repository=${{ steps.tagname.outputs.repo }}&tag=latest" |
0 commit comments