Merge pull request #588 from medusajs/feat/github-actions
Feat: GitHub actions
This commit is contained in:
33
.github/actions/cache-bootstrap/action.yml
vendored
Normal file
33
.github/actions/cache-bootstrap/action.yml
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
name: cache-bootstrap
|
||||
description: Creates a cache with the given extension for lerna packages
|
||||
inputs:
|
||||
extension:
|
||||
description: Extension for cache name
|
||||
partial:
|
||||
description: Boolean flag to describe whether or not to run a partial bootstrap when finding cache
|
||||
default: false
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
# for always overriding cache, use: pat-s/always-upload-cache@v2.1.5
|
||||
- uses: actions/cache@v2
|
||||
id: cache
|
||||
with:
|
||||
path: |
|
||||
node_modules
|
||||
*/*/node_modules
|
||||
key: ${{ runner.os }}-yarn-${{inputs.extension}}-v8-${{ hashFiles('**/yarn.lock') }}
|
||||
# We want to only bootstrap and install if no cache is found.
|
||||
# Futhermore, we might want to do a partial, hoisted, bootstrap towards
|
||||
# the base branch if it exists, otherwise we choose develop for this.
|
||||
|
||||
# yarn install --frozen-lockfile
|
||||
- run: |
|
||||
if [[ "${{steps.cache.outputs.cache-hit}}" != "true" || "${{inputs.partial}}" != "true" ]]; then
|
||||
yarn install --frozen-lockfile
|
||||
yarn bootstrap --concurrency=2
|
||||
elif [[ "${{inputs.partial}}" = "true" ]]; then
|
||||
[[ ! -z "${GITHUB_BASE_REF}" ]] && ref="${GITHUB_BASE_REF#refs/heads/}" || ref="develop"
|
||||
yarn bootstrap --npm-client=npm --hoist --since "origin/${ref}...HEAD" --concurrency=2
|
||||
fi
|
||||
shell: bash
|
||||
82
.github/workflows/action.yml
vendored
Normal file
82
.github/workflows/action.yml
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
name: Medusa Pipeline
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
unit-tests:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2.3.5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup Node.js environment
|
||||
uses: actions/setup-node@v2.4.1
|
||||
with:
|
||||
node-version: '14'
|
||||
cache: 'yarn'
|
||||
|
||||
- name: Assert changed
|
||||
run: ./scripts/assert-changed-files-actions.sh "packages"
|
||||
|
||||
- name: Bootstrap packages
|
||||
uses: ./.github/actions/cache-bootstrap
|
||||
with:
|
||||
extension: unit-tests
|
||||
|
||||
- name: Run unit tests
|
||||
run: node --max-old-space-size=2048 ./node_modules/.bin/jest -w 1
|
||||
|
||||
integration-tests:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres
|
||||
env:
|
||||
POSTGRES_PASSWORD: postgres
|
||||
POSTGRES_USER: postgres
|
||||
options: >-
|
||||
--health-cmd pg_isready
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
ports:
|
||||
- 5432:5432
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2.3.5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup Node.js environment
|
||||
uses: actions/setup-node@v2.4.1
|
||||
with:
|
||||
node-version: '14'
|
||||
cache: 'yarn'
|
||||
|
||||
- name: Bootstrap packages
|
||||
uses: ./.github/actions/cache-bootstrap
|
||||
with:
|
||||
extension: integration-tests
|
||||
|
||||
- name: Install dev cli
|
||||
run: sudo npm i -g medusa-dev-cli
|
||||
|
||||
- name: Set path to medusa repo
|
||||
run: medusa-dev --set-path-to-repo `pwd`
|
||||
|
||||
- name: Force install
|
||||
run: medusa-dev --force-install
|
||||
working-directory: integration-tests/api
|
||||
|
||||
- name: Build integration tests
|
||||
run: yarn build
|
||||
working-directory: integration-tests/api
|
||||
|
||||
- name: Run integration tests
|
||||
run: yarn test
|
||||
working-directory: integration-tests/api
|
||||
env:
|
||||
DB_PASSWORD: postgres
|
||||
@@ -1,4 +1,3 @@
|
||||
import { IdMap } from "../../../../../../../medusa-test-utils/dist"
|
||||
import { request } from "../../../../../helpers/test-request"
|
||||
import { ProductVariantServiceMock } from "../../../../../services/__mocks__/product-variant"
|
||||
|
||||
|
||||
40
scripts/assert-changed-files-actions.sh
Executable file
40
scripts/assert-changed-files-actions.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
IS_CI="${CI:-false}"
|
||||
GREP_PATTERN=$1
|
||||
|
||||
if [ "$IS_CI" = true ]; then
|
||||
git config --local url."https://github.com/".insteadOf git@github.com:
|
||||
git config --local user.name "Medusajs Bot"
|
||||
git config --local user.email "core@medusa-commerce.com"
|
||||
|
||||
git fetch origin
|
||||
git merge --no-edit origin/master
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Branch has conflicts with master, rolling back test."
|
||||
git merge --abort
|
||||
fi
|
||||
|
||||
git config --local --unset user.name
|
||||
git config --local --unset user.email
|
||||
git config --local --unset url."https://github.com/".insteadOf
|
||||
fi
|
||||
|
||||
# Make sure that we are diffing towards the right branch, in github actions this is different
|
||||
# depending on whether or not we are creating a pull request or not.
|
||||
[ ! -z ${GITHUB_BASE_REF} ] && HAS_BASE=true || HAS_BASE=false
|
||||
[ HAS_BASE = true ] && COMPARE="${GITHUB_BASE_REF#refs/heads/}" || COMPARE="develop"
|
||||
FILES_COUNT="$(git diff-tree --no-commit-id --name-only -r origin/"$COMPARE" | grep -E "$GREP_PATTERN" -c)"
|
||||
|
||||
if [ "$IS_CI" = true ]; then
|
||||
# reset to previous state
|
||||
git reset --hard $GITHUB_SHA
|
||||
fi
|
||||
|
||||
if [ "$FILES_COUNT" -eq 0 ]; then
|
||||
echo "0 files matching '$GREP_PATTERN'; exiting and marking successful."
|
||||
exit 0
|
||||
else
|
||||
echo "$FILES_COUNT file(s) matching '$GREP_PATTERN'; continuing."
|
||||
fi
|
||||
Reference in New Issue
Block a user