-
Notifications
You must be signed in to change notification settings - Fork 2
141 lines (116 loc) · 4.08 KB
/
deno-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: CI
on:
push:
branches: [ main ]
tags: [ v* ]
pull_request: {}
jobs:
check:
runs-on: ubuntu-latest
name: Check w/ ${{ matrix.deno-version }}
strategy:
matrix:
deno-version:
- v1.43
- canary
fail-fast: false # run each branch to completion
steps:
- name: Checkout source
uses: actions/checkout@v3
- name: Use Deno ${{ matrix.deno-version }}
uses: denoland/setup-deno@v1
with:
deno-version: ${{ matrix.deno-version }}
# "file" cache: code from source control
# We're more selective here to prevent cross-branch contamination
# Disabled for now because https://github.com/denoland/deno/pull/12830
# - name: Cache file://
# uses: actions/cache@v2
# with:
# path: ~/.cache/deno/gen/file
# key: deno/${{ matrix.deno-version }}-file/v1-${{ github.ref }}-${{ github.sha }}
# restore-keys: deno/${{ matrix.deno-version }}-file/v1-${{ github.ref }}-
# "https" cache: code from the Internet
# External sources won't change much so we use less precise keys
- name: Cache https://
uses: actions/cache@v2
with:
path: ~/.cache/deno/deps/https
key: deno-https/v1-${{ hashFiles('**/deps.ts') }}
restore-keys: deno-https/v1-
- name: Check entrypoint
run: time deno check server.ts
- name: Run any tests
run: time deno test
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
needs: check
runs-on: ubuntu-latest
name: 'Push container image'
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v3
- name: Log into GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log into Google Container Registry
uses: docker/login-action@v3
with:
registry: gcr.io
username: _json_key
password: ${{ secrets.GCP_SA_KEY }}
- name: Pull latest image for cache
run: docker pull ghcr.io/${{ github.repository }}
- name: Build image
run: |
docker build . \
--cache-from ghcr.io/${{ github.repository }} \
--file Dockerfile \
--tag built-image
- name: Inspect image
run: docker images built-image
- name: Push image to GitHub Container Registry
id: push_ghcr
run: |
IMAGE_ID=ghcr.io/${{ github.repository }}
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
[ "$VERSION" == "main" ] && VERSION=latest
docker tag built-image $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
echo "Pushed $IMAGE_ID:$VERSION"
echo "::set-output name=docker_image::$IMAGE_ID:$VERSION"
- name: Push image to Google Container Registry
id: push_gcr
run: |
IMAGE_ID=gcr.io/stardust-156404/deno-module-visualizer
VERSION=${{ github.sha }}
docker tag built-image $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
echo "Pushed $IMAGE_ID:$VERSION"
echo "::set-output name=docker_image::$IMAGE_ID:$VERSION"
outputs:
ghcr_image: ${{ steps.push_ghcr.outputs.docker_image }}
gcr_image: ${{ steps.push_gcr.outputs.docker_image }}
deploy:
needs: push
runs-on: ubuntu-latest
name: 'Deploy to live site'
if: github.ref == 'refs/heads/main'
steps:
- name: Log in
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Deploy to Cloud Run
uses: google-github-actions/deploy-cloudrun@v1
with:
project_id: stardust-156404
service: deno-module-visualizer
region: us-central1
image: ${{ needs.push.outputs.gcr_image }}