Skip to content

Merge pull request #74 from gzp79/validate_captcha #217

Merge pull request #74 from gzp79/validate_captcha

Merge pull request #74 from gzp79/validate_captcha #217

Workflow file for this run

name: Master CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
# cancel outdated builds
concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Prepare tests
run: |
npm ci
npm run lint
npm run mkcert
working-directory: ./integration-test
- name: Setup Docker Buildx (1)
run: |
docker network create shine
- name: Setup Docker Buildx (2)
uses: docker/setup-buildx-action@v2
with:
driver: docker-container
driver-opts: network=shine
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: type=sha
- name: Prepare MockBox
id: mockbox
run: |
docker compose -f docker-compose.yml -p shine-identity up -d
echo "pg_host=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' shine-identity-postgres-1)" >> $GITHUB_OUTPUT
echo "redis_host=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' shine-identity-redis-1)" >> $GITHUB_OUTPUT
working-directory: ./service
- name: Docker build
uses: docker/build-push-action@v4
with:
context: service
target: test
push: false
load: true
add-hosts: |
postgres.mockbox.com:${{ steps.mockbox.outputs.pg_host }}
redis.mockbox.com:${{ steps.mockbox.outputs.redis_host }}
cache-from: type=gha,mode=max
cache-to: type=gha,mode=max
tags: ${{ env.IMAGE_NAME }}:test
- name: Add hosts to /etc/hosts
run: |
sudo echo "127.0.0.1 sandbox.com" | sudo tee -a /etc/hosts
sudo echo "127.0.0.1 web.sandbox.com" | sudo tee -a /etc/hosts
sudo echo "127.0.0.1 cloud.sandbox.com" | sudo tee -a /etc/hosts
sudo echo "127.0.0.1 mockbox.com" | sudo tee -a /etc/hosts
sudo echo "127.0.0.1 postgres.mockbox.com" | sudo tee -a /etc/hosts
sudo echo "127.0.0.1 redis.mockbox.com" | sudo tee -a /etc/hosts
- name: Integration test
run: |
echo "::group::Starting service in the test environment"
docker compose -f ../service/docker-compose.yml -p shine-identity --profile test up -d
echo "::endgroup::"
echo "::group::Running test"
npm run test
npm run test:report
echo "::endgroup::"
working-directory: ./integration-test
- name: Publish test results
if: github.ref == 'refs/heads/master' || failure()
uses: actions/upload-artifact@v4
with:
name: test-reports
path: |
./integration-test/reports/
- name: Log in to the Container registry
if: github.ref == 'refs/heads/master'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build production
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v4
with:
context: service
target: prod
push: true
# these setting are added to allow the reuse of the layer from the build step
# without host parameters it would trigger a new build
add-hosts: |
postgres.mockbox.com:${{ steps.mockbox.outputs.pg_host }}
redis.mockbox.com:${{ steps.mockbox.outputs.redis_host }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Create release artifacts
if: github.ref == 'refs/heads/master'
run: |
echo "[build]" >> fly.toml
echo " image = \"${{ steps.meta.outputs.tags }}\"" >> fly.toml
cp fly.toml release/
working-directory: ./service
- name: Publish release artifacts
if: github.ref == 'refs/heads/master'
uses: actions/upload-artifact@v4
with:
name: release-artifacts
path: |
./service/release/
deploy:
needs: build
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Init fly
uses: superfly/flyctl-actions/setup-flyctl@v1
- name: Download release artifacts
uses: actions/download-artifact@v4
with:
name: release-artifacts
- name: Deploy to fly
run: flyctl deploy
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}