Created
October 20, 2021 12:30
-
-
Save tomfa/f389f3a96e95376d9c6738abca674695 to your computer and use it in GitHub Desktop.
Github Action: depend on test to succeed for deployment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# place this file in .github/workflows/ folder in repo | |
# | |
# This will run tests on push to master branch, then | |
# deploy if test succeeds | |
# | |
# This is controlled by the job "deploy" value "needs: test" | |
name: Deploy | |
on: | |
push: | |
branches: | |
- master | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
container: node:14 | |
services: | |
postgres: | |
image: postgres | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres_pass | |
POSTGRES_DB: vailable | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
ports: | |
- 5432:5432 | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/setup-node@v2 | |
with: | |
node-version: '14' | |
- name: Get yarn cache directory path | |
id: yarn-cache-dir-path | |
run: echo "::set-output name=dir::$(yarn cache dir)" | |
- uses: actions/cache@v2 | |
id: yarn-cache # use this to check for `cache-hit` | |
with: | |
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Yarn Install | |
run: | | |
yarn install | |
- name: Typescript check | |
run: | | |
yarn test:compile | |
- name: Run tests | |
run: | | |
yarn test:all | |
deploy: | |
needs: test | |
runs-on: ubuntu-latest | |
container: node:14 | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/setup-node@v2 | |
with: | |
node-version: '14' | |
- name: Get yarn cache directory path | |
id: yarn-cache-dir-path | |
run: echo "::set-output name=dir::$(yarn cache dir)" | |
- uses: actions/cache@v2 | |
id: yarn-cache # use this to check for `cache-hit` | |
with: | |
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Yarn Install | |
run: | | |
yarn install | |
- name: Deploy web | |
run: | | |
yarn deploy | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment