permitting push event to trigger workflow run on this branch #602
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, synchronize-downstream-test-then-deploy] #<<< remove before merge | |
# 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: synchronize-downstream-test-then-deploy | |
PERMISSION_WORKFLOW_BRANCH: synchronize-downstream-test-then-deploy | |
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 | |
echo "webapp_workflow_branch=${WEBAPP_WORKFLOW_BRANCH:-main}" >> $GITHUB_OUTPUT | |
echo "permissionapi_workflow_branch=${PERMISSION_WORKFLOW_BRANCH:-main}" >> $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: | |
name: Run tests in ${{matrix.repo}} | |
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/synchronize-downstream-test-then-deploy' # <<< change before merge | |
name: Bump Core pkg in ${{ matrix.repo }} | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
needs: [push-package, integration-test, run-downstream-test-workflows] | |
strategy: | |
max-parallel: 2 | |
fail-fast: true | |
matrix: | |
include: | |
- repo: "app.charmverse.io" | |
workflow_file: "update_core_pkg.yml" | |
workflow_payload: | | |
{ "core_pkg_version": "${{ needs.push-package.outputs.pkg_version }}" } | |
- repo: "permissions.charmverse.io" | |
workflow_file: "update_core_pkg.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: synchronize-downstream-test-then-deploy # <<< change before merge | |
client_payload: ${{ matrix.workflow_payload }} | |
wait_interval: 10 | |
propagate_failure: true | |
trigger_workflow: true | |
wait_workflow: true | |