mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-24 19:39:11 +00:00
201 lines
6.3 KiB
YAML
201 lines
6.3 KiB
YAML
name: Roleypoly CI
|
|
|
|
on: push
|
|
|
|
jobs:
|
|
go_test:
|
|
runs-on: ubuntu-latest
|
|
name: Go CI
|
|
steps:
|
|
- uses: actions/checkout@master
|
|
- uses: actions/cache@v2
|
|
with:
|
|
path: ~/go/pkg/mod
|
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-go-
|
|
- uses: actions/setup-go@v2
|
|
with:
|
|
go-version: '^1.15.5'
|
|
|
|
- run: go vet ./...
|
|
|
|
- run: go test ./...
|
|
|
|
node_test:
|
|
runs-on: ubuntu-latest
|
|
name: Node CI
|
|
steps:
|
|
- uses: actions/checkout@master
|
|
|
|
- uses: actions/setup-node@v2-beta
|
|
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` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
|
|
with:
|
|
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
|
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-yarn-
|
|
|
|
- run: yarn install --frozen-lockfile
|
|
|
|
- run: yarn lint
|
|
|
|
- run: yarn test
|
|
|
|
worker_build:
|
|
runs-on: ubuntu-latest
|
|
name: Worker Build & Publish
|
|
needs:
|
|
- node_test
|
|
steps:
|
|
- uses: actions/checkout@master
|
|
|
|
- uses: actions/setup-node@v2-beta
|
|
with:
|
|
node-version: '14'
|
|
|
|
- run: npm i -g @cloudflare/wrangler
|
|
|
|
- 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` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
|
|
with:
|
|
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
|
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-yarn-
|
|
|
|
- run: yarn install --frozen-lockfile
|
|
|
|
- run: |
|
|
wrangler init
|
|
echo 'webpack_config = "src/backend-worker/webpack.config.js"' | tee -a wrangler.toml
|
|
wrangler build
|
|
|
|
- id: upload-file
|
|
uses: google-github-actions/upload-cloud-storage@main
|
|
with:
|
|
path: worker/script.js
|
|
destination: roleypoly-artifacts/backend-worker/${{ github.sha }}
|
|
credentials: ${{ secrets.GCS_TF_KEY }}
|
|
|
|
docker_build:
|
|
name: Docker Build & Publish
|
|
runs-on: ubuntu-latest
|
|
needs:
|
|
- go_test
|
|
- node_test
|
|
strategy:
|
|
matrix:
|
|
dockerfile:
|
|
- ui
|
|
- bot
|
|
steps:
|
|
- uses: actions/checkout@master
|
|
|
|
- uses: actions/cache@v2
|
|
with:
|
|
path: /tmp/.buildx-cache
|
|
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
|
restore-keys: |
|
|
${{ runner.os }}-buildx-
|
|
|
|
- name: Docker meta
|
|
id: docker_meta
|
|
uses: crazy-max/ghaction-docker-meta@v1
|
|
with:
|
|
images: |
|
|
ghcr.io/roleypoly/${{matrix.dockerfile}}
|
|
tag-sha: true
|
|
|
|
- name: Set up Docker Buildx
|
|
id: buildx
|
|
uses: docker/setup-buildx-action@v1
|
|
with:
|
|
install: true
|
|
|
|
- name: Login to GHCR
|
|
uses: docker/login-action@v1
|
|
with:
|
|
registry: ghcr.io
|
|
username: roleypoly
|
|
password: ${{ secrets.GHCR_PAT }}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v2
|
|
id: docker
|
|
with:
|
|
context: .
|
|
file: ./hack/dockerfiles/${{matrix.dockerfile}}.Dockerfile
|
|
push: true
|
|
cache-from: type=local,src=/tmp/.buildx-cache
|
|
cache-to: type=local,dest=/tmp/.buildx-cache
|
|
tags: ${{ steps.docker_meta.outputs.tags }}
|
|
labels: ${{ steps.docker_meta.outputs.labels }}
|
|
|
|
- name: Pre-deploy - Save digest.txt
|
|
run: |
|
|
echo "${{ steps.docker.outputs.digest }}" > digest.txt
|
|
|
|
- name: Pre-deploy - Make digest artifact
|
|
uses: actions/upload-artifact@v1
|
|
with:
|
|
name: ${{ matrix.dockerfile }}-digest
|
|
path: digest.txt
|
|
|
|
trigger_deploy:
|
|
name: Deploy to Stage
|
|
needs:
|
|
- docker_build
|
|
- worker_build
|
|
if: github.ref == refs/heads/main
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Get UI digest
|
|
uses: actions/download-artifact@v2
|
|
with:
|
|
name: ui-digest
|
|
path: .digests/ui
|
|
|
|
- name: Get Bot digest
|
|
uses: actions/download-artifact@v2
|
|
with:
|
|
name: bot-digest
|
|
path: .digests/bot
|
|
|
|
- name: Set digests as addressable
|
|
id: digests
|
|
env:
|
|
IMAGES: ui bot
|
|
run: |
|
|
set_digest_output() {
|
|
echo ::set-output name=$1::@$(cat .digests/$1/dig)
|
|
}
|
|
|
|
for image in $IMAGES; do
|
|
set_digest_output $image
|
|
done
|
|
|
|
- name: Invoke Deploy workflow
|
|
uses: benc-uk/workflow-dispatch@v1
|
|
with:
|
|
workflow: Deploy
|
|
token: ${{ secrets.GITOPS_TOKEN }}
|
|
inputs: |-
|
|
{
|
|
"environment": "stage",
|
|
"worker_tag": "${{ github.sha }}",
|
|
"ui_tag": "${{ steps.digests.output.ui }}",
|
|
"bot_tag": "${{ steps.digests.output.bot }}"
|
|
}
|