Proposal blocks schema #550
Workflow file for this run
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
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | |
name: CI | |
on: | |
push: | |
branches: [main] | |
# paths: | |
# - '!.github/**' | |
pull_request: | |
branches: ['**'] | |
workflow_dispatch: | |
inputs: | |
webapp_branch: | |
description: 'Webapp branch to test against.' | |
required: true | |
permissionapi_branch: | |
description: 'Permissions api branch to test against' | |
required: true | |
# Change the below to get your PR CI to run tests against a specific branch | |
# Overrides the input, as inputs always have a default value | |
env: | |
WEBAPP_WORKFLOW_BRANCH: | |
PERMISSION_WORKFLOW_BRANCH: | |
jobs: | |
build-test-env: | |
name: Build test env | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install dependencies | |
uses: ./.github/actions/install | |
- name: Run build | |
uses: ./.github/actions/build | |
typecheck: | |
name: Type Check | |
runs-on: ubuntu-latest | |
needs: build-test-env | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Restore dependencies from cache | |
uses: ./.github/actions/install | |
- name: Run type check | |
run: | | |
npm run typecheck | |
push-package: | |
name: Push Release candidate package to allow devs to use to test | |
runs-on: ubuntu-latest | |
needs: typecheck | |
permissions: | |
contents: write | |
pull-requests: write | |
outputs: | |
pkg_version: ${{ steps.publish_pkg.outputs.pkg_version }} | |
webapp_workflow_branch: ${{ steps.set_downstream_repo_branch.outputs.webapp_workflow_branch }} | |
permissionapi_workflow_branch: ${{ steps.set_downstream_repo_branch.outputs.permissionapi_workflow_branch }} | |
steps: | |
- name: Determine downstream repo branch to run tests against first | |
id: set_downstream_repo_branch | |
run: | | |
# values of this step's output is used in step run-downstream-test-workflows | |
# strategy/matrix doesn't permit access to env context. very lame... | |
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then | |
echo "webapp_workflow_branch='main'" >> $GITHUB_OUTPUT | |
echo "permissionapi_workflow_branch='main'" >> $GITHUB_OUTPUT | |
elif [[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then | |
echo "webapp_workflow_branch=${{inputs.webapp_branch}}" >> $GITHUB_OUTPUT | |
echo "permissionapi_workflow_branch=${{inputs.permissionapi_branch}}" >> $GITHUB_OUTPUT | |
else | |
if [[ -z $WEBAPP_WORKFLOW_BRANCH || -z $PERMISSION_WORKFLOW_BRANCH ]]; then | |
echo "::notice title=Test branch target::Setting downstream repo test to test against branch main." | |
WEBAPP_WORKFLOW_BRANCH='main' | |
PERMISSION_WORKFLOW_BRANCH='main' | |
else | |
if [[ $WEBAPP_WORKFLOW_BRANCH != "${{ github.head_ref }}" || $PERMISSION_WORKFLOW_BRANCH != "${{ github.head_ref }}" ]]; then | |
echo "::warning title=Mismatch in test branch target::Workflow branch env vars is not this current branch. Are you sure they are set correctly??" | |
echo "Setting downstream repo branch to what is set in env." | |
echo "PR head branch: $GITHUB_HEAD_REF_SLUG" | |
echo "env WEBAPP_WORKFLOW_BRANCH: $WEBAPP_WORKFLOW_BRANCH" | |
echo "env PERMISSION_WORKFLOW_BRANCH: $PERMISSION_WORKFLOW_BRANCH" | |
fi | |
fi | |
echo "webapp_workflow_branch=$WEBAPP_WORKFLOW_BRANCH" >> $GITHUB_OUTPUT | |
echo "permissionapi_workflow_branch=$PERMISSION_WORKFLOW_BRANCH" >> $GITHUB_OUTPUT | |
fi | |
- name: Checkout ref of the event that triggered this workflow. (first time run) | |
uses: actions/checkout@v3 | |
- name: Checkout head of merge on re-run | |
uses: actions/checkout@v3 | |
if: github.event_name != 'push' && github.run_attempt > 1 | |
with: | |
ref: refs/pull/${{ github.event.number }}/merge | |
- run: | | |
cat package.json | |
echo "run attempt ${{github.run_attempt}}" | |
- name: Restore build cache | |
uses: ./.github/actions/build | |
- name: Package and publish release candidate pkg | |
id: publish_pkg | |
uses: ./.github/actions/package_n_publish | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }} | |
- name: Posting pkg version in comment | |
uses: marocchino/sticky-pull-request-comment@v2 | |
with: | |
header: Pkg version | |
message: | | |
Code ${{ github.sha }} labeled version ${{ steps.publish_pkg.outputs.pkg_version }} | |
run-downstream-test-workflows: | |
if: github.event_name != 'push' && github.ref != 'refs/heads/main' | |
name: Trigger ${{matrix.repo}} testing workflow | |
runs-on: ubuntu-latest | |
needs: push-package | |
permissions: | |
pull-requests: write | |
strategy: | |
max-parallel: 2 | |
fail-fast: false | |
matrix: | |
include: | |
- repo: "app.charmverse.io" | |
branch: "${{ needs.push-package.outputs.webapp_workflow_branch }}" | |
workflow_file: "test_new_core_pkg.yml" | |
workflow_payload: | | |
{ "core_pkg_version": "${{ needs.push-package.outputs.pkg_version }}" } | |
- repo: "permissions.charmverse.io" | |
branch: "${{ needs.push-package.outputs.permissionapi_workflow_branch }}" | |
workflow_file: "test_core_pkg.yml" | |
workflow_payload: | | |
{ "core_pkg_version": "${{ needs.push-package.outputs.pkg_version }}" } | |
steps: | |
- name: Trigger tests on repo ${{ matrix.repo }} | |
uses: convictional/[email protected] | |
with: | |
owner: charmverse | |
repo: ${{ matrix.repo }} | |
github_token: ${{ secrets.WORKFLOW_TRIGGER_PAT }} | |
github_user: charmed-bot | |
workflow_file_name: ${{ matrix.workflow_file }} | |
ref: ${{ matrix.branch }} | |
client_payload: ${{ matrix.workflow_payload }} | |
wait_interval: 10 | |
propagate_failure: true | |
trigger_workflow: true | |
wait_workflow: true | |
comment_downstream_url: ${{ github.event.pull_request.comments_url }} | |
integration-test: | |
name: Run Integration Tests | |
runs-on: ubuntu-latest | |
needs: build-test-env | |
# Postgres setup copied from https://gist.github.com/2color/537f8ef13ecec80059abb007839a6878 | |
services: | |
postgres: | |
image: postgres | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
ports: | |
# Maps tcp port 5432 on service container to the host | |
- 5432:5432 | |
strategy: | |
max-parallel: 5 | |
fail-fast: false | |
matrix: | |
include: | |
- test_name: "Basic tests #1" | |
test_command: "npm run test:ci -- --shard 1/2" | |
- test_name: "Basic tests #2" | |
test_command: "npm run test:ci -- --shard 2/2" | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Restore dependencies from cache | |
uses: ./.github/actions/install | |
- name: Setup test database | |
run: npx dotenv -e .env.test.local -- npm run prisma:reset | |
- name: Run ${{matrix.test_name}} | |
run: ${{matrix.test_command}} | |
trigger-pkg-upgrade: | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
name: Trigger Core pkg Upgrade on ${{ matrix.repo }} | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
needs: [push-package, integration-test] | |
strategy: | |
max-parallel: 2 | |
fail-fast: false | |
matrix: | |
include: | |
- repo: "app.charmverse.io" | |
workflow_file: "test_and_deploy.yml" | |
workflow_payload: | | |
{ "core_pkg_version": "${{ needs.push-package.outputs.pkg_version }}" } | |
- repo: "permissions.charmverse.io" | |
workflow_file: "test_and_deploy.yml" | |
workflow_payload: | | |
{ "core_pkg_version": "${{ needs.push-package.outputs.pkg_version }}" } | |
steps: | |
- name: Trigger Core pkg update and deploy on repo ${{ matrix.repo }} | |
uses: convictional/[email protected] | |
with: | |
owner: charmverse | |
repo: ${{ matrix.repo }} | |
github_token: ${{ secrets.WORKFLOW_TRIGGER_PAT }} | |
github_user: charmed-bot | |
workflow_file_name: ${{ matrix.workflow_file }} | |
ref: "main" | |
client_payload: ${{ matrix.workflow_payload }} | |
wait_interval: 10 | |
propagate_failure: true | |
trigger_workflow: true | |
wait_workflow: true | |