wip: add chat #35
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
name: Build CLI command, run tests and release packages | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
paths-ignore: | |
- "cmds/proxy/**" | |
- "**.md" | |
- ".github/workflows/on_push_proxy.yaml" | |
concurrency: ${{ github.workflow }}-${{ github.ref }} | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
release: | |
name: Build CLI command, run tests and release packages | |
runs-on: ubuntu-latest | |
if: github.repository == 'empiricaly/empirica' && github.event.pull_request.draft == false | |
steps: | |
# | |
# Step 0. Setup and test if Empirica compiles successfully | |
# | |
- name: Checkout Repo | |
uses: actions/checkout@v3 | |
- name: Setup Node.js 16.x | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 16.x | |
- name: Get branch name | |
id: branch-name | |
uses: tj-actions/branch-names@v5.4 | |
- name: Quick build of Empirica CLI to ensure compilation is working | |
uses: docker/build-push-action@v2 | |
with: | |
push: false | |
tags: empirica-tmp | |
file: ./build/Dockerfile | |
build-args: | | |
BUILD_DATE=${{ env.BUILD_DATE }} | |
BUILD_ONLY_AMD64=true | |
# | |
# Step 1. Build the npm package and publish | |
# | |
- name: "Build core package: install dependencies" | |
if: github.ref == 'refs/heads/main' | |
run: npm ci | |
- name: "Build packages: Create Release Pull Request or Publish to npm" | |
if: github.ref == 'refs/heads/main' | |
id: changesets | |
uses: changesets/action@v1 | |
with: | |
publish: npm run release:core | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Get @empirica/core package version | |
id: core-version | |
working-directory: ./lib/@empirica/core | |
run: echo "EMPIRICA_CORE_VERSION=v$(node -e "console.log(require('./package.json').version)")" >> $GITHUB_ENV | |
# We will use the result to determine if we need to create a release or not | |
- name: "Build core package: Create release tag" | |
if: steps.changesets.outputs.published == 'true' | |
id: create_tag | |
uses: jaywcjlove/create-tag-action@v1.2.0 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
version: ${{ env.EMPIRICA_CORE_VERSION }} | |
# | |
# Step 1. Build the Empirica cmd and run smoke test | |
# | |
- name: Set GITHUB_ENV | |
run: | | |
echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV | |
echo "BUILD_SHA=$(git rev-list -1 HEAD)" >> $GITHUB_ENV | |
echo "BUILD_SHA_SHORT=$(git rev-parse --short=7 ${{ github.sha }})" >> $GITHUB_ENV | |
# If tag has been created, we assume we need to release a version | |
- name: Check if tag has been created | |
if: steps.create_tag.outputs.successful | |
run: | | |
echo "BUILD_BRANCH=`echo "main" | sed -r 's,/,-,g'`" >> $GITHUB_ENV | |
echo "BUILD_TAG=${{ env.EMPIRICA_CORE_VERSION }}" >> $GITHUB_ENV | |
# If tag hasn't been created, create a CalVer version | |
- name: Use actual branch name. | |
if: steps.create_tag.outputs.successful != 'true' | |
working-directory: ./build | |
run: | | |
echo "BUILD_TAG=$(sh generate_calver.sh)" >> $GITHUB_ENV | |
# Otherwise use the actual branch name | |
- name: Use actual branch name. | |
if: steps.create_tag.outputs.successful != 'true' | |
run: | | |
echo "BUILD_BRANCH=`echo "${{ steps.branch-name.outputs.current_branch }}" | sed -r 's,/,-,g'`" >> $GITHUB_ENV | |
- name: Log build variables | |
run: | | |
echo BUILD_DATE=${{ env.BUILD_DATE }} | |
echo BUILD_SHA=${{ env.BUILD_SHA_SHORT }} | |
echo BUILD_BRANCH=${{ env.BUILD_BRANCH }} | |
echo BUILD_TAG=${{ env.BUILD_TAG }} | |
echo EMPIRICA_CORE_VERSION=${{ env.EMPIRICA_CORE_VERSION }} | |
- name: Build Empirica server | |
uses: docker/build-push-action@v2 | |
with: | |
push: false | |
tags: empirica-tmp | |
file: ./build/Dockerfile | |
build-args: | | |
BUILD_DATE=${{ env.BUILD_DATE }} | |
BUILD_SHA=${{ env.BUILD_SHA_SHORT }} | |
BUILD_BRANCH=${{ env.BUILD_BRANCH }} | |
BUILD_TAG=${{ env.BUILD_TAG }} | |
- name: Copy binaries from image | |
run: | | |
mkdir -p out | |
docker run --rm empirica-tmp tar -cC /out . | tar -xC $(pwd)/out | |
- name: Smoke test | |
run: ./out/empirica-linux-amd64 --help | |
# | |
# Step 2. Run e2e tests | |
# | |
- name: "E2E tests: install empirica" | |
working-directory: ./e2e-tests | |
run: curl https://get.empirica.dev | sh | |
- name: "E2E tests: install dependencies" | |
working-directory: ./e2e-tests | |
run: npm ci --workspaces=false | |
- name: "E2E tests: install @empirica core dependencies" | |
working-directory: ./lib/@empirica/core | |
run: npm ci | |
- name: "E2E tests: Get installed Playwright version" | |
id: playwright-version | |
run: echo "PLAYWRIGHT_VERSION=$(node -e "console.log(require('./package-lock.json').packages['node_modules/@playwright/test'].version)")" >> $GITHUB_ENV | |
- name: "E2E tests: Cache playwright binaries" | |
uses: actions/cache@v3 | |
id: playwright-cache | |
with: | |
path: | | |
~/.cache/ms-playwright | |
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }} | |
- name: "E2E tests: install playwright browsers" | |
run: npm run install_browsers -w ./e2e-tests | |
if: steps.playwright-cache.outputs.cache-hit != 'true' | |
- name: "E2E tests: Run" | |
run: npm run test:e2e -w ./e2e-tests | |
- name: "E2E tests: upload tests results to artifacts" | |
uses: actions/upload-artifact@v2 | |
if: always() | |
with: | |
name: playwright-test-results | |
path: ./e2e-tests/test-results/ | |
# | |
# Step 4. Test and upload the CLI to S3 and build the Docker image | |
# | |
- name: Step 3. Upload binaries to S3 | |
uses: ./.github/actions/upload-empirica-cli | |
with: | |
bucket: empirica | |
root: empirica | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
awsEndpoint: https://f120117e0fd797d29319953881b7634c.r2.cloudflarestorage.com | |
awsSignatureVersion: v4 | |
- name: Log in to the Container registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build Docker image | |
uses: docker/build-push-action@v3 | |
with: | |
push: true | |
file: ./build/Dockerfile.empirica | |
context: . | |
tags: | | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:sha-${{ env.BUILD_SHA_SHORT }} | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:build-${{ env.BUILD_TAG }} | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:branch-${{ env.BUILD_BRANCH }} | |