Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Run bin for pipeline tests #34

Merged
merged 4 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
Publish:
name: Publish
needs:
- CiBuild # For version variable
- CiBuild
- PipelineTests # Requires passing tests

uses: connorjs/github-workflows/.github/workflows/npm-publish~v1.yaml@main
Expand All @@ -30,10 +30,14 @@ jobs:

PipelineTests:
name: Test (${{ matrix.node }} | ${{ matrix.platform.os }})
needs:
- CiBuild

runs-on: ${{ matrix.platform.os }}-latest
defaults:
run:
shell: bash
runs-on: ${{ matrix.platform.os }}-latest

strategy:
matrix:
node:
Expand All @@ -49,17 +53,21 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
name: ${{ needs.CiBuild.outputs.npmPackFilename }}

- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v4
with:
cache: npm
node-version: ${{ matrix.node }}

- name: Install
run: npm install

- name: Build
run: npm run build
- name: Install css-typed
run: |
mkdir -p sandbox
cd sandbox
npm install ../${{ needs.CiBuild.outputs.npmPackFilename }}

- name: "Test 1: default case"
run: |
Expand All @@ -83,7 +91,7 @@ jobs:
- name: "Test 5: absolute outdir"
if: success() || failure()
run: |
scripts/test.sh foo "" "-o $GITHUB_WORKSPACE/generated *.css" "" "$GITHUB_WORKSPACE"/generated/
scripts/test.sh foo "" "-o $RUNNER_TEMP/generated *.css" "" "$RUNNER_TEMP"/generated/
# Note: This test uses double quotes, which expands differently.

- name: "Test 6: json file config"
Expand Down
27 changes: 16 additions & 11 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,28 @@ output=${4:-$1}
# $5 is the path prefix for output. Defaults to "".
prefix=${5:-}

# Run from $RUNNER_TEMP for auto-cleanup.
cp fixtures/${input}.css $RUNNER_TEMP/test.css
cp fixtures/${output}.d.css.ts $RUNNER_TEMP/expected.d.css.ts
# `sandbox` is where we installed css-typed.
# Create fresh tmp directory under it each time (under for npx usage).
TEST_DIR=sandbox/tmp
rm -rf $TEST_DIR
mkdir -p $TEST_DIR

cp fixtures/${input}.css $TEST_DIR/test.css
cp fixtures/${output}.d.css.ts $TEST_DIR/expected.d.css.ts

rm -rf "${RUNNER_TEMP:?}/.config"
if [ -f fixtures/config/${config} ]; then
mkdir -p $RUNNER_TEMP/.config
cp fixtures/config/${config} $RUNNER_TEMP/.config/${config}
mkdir -p $TEST_DIR/.config
cp fixtures/config/${config} $TEST_DIR/.config/${config}
fi

pushd $RUNNER_TEMP > /dev/null || exit
pushd $TEST_DIR > /dev/null || exit

set -x # Print the css-typed command exactly as executed

# `./dist/main.js` is executing local `css-typed` as if installed (same as `bin`).
# But it is `$GITHUB_WORKSPACE/dist/main.js` b/c we `cd $RUNNER_TEMP`.
echo "css-typed " "${options[@]}"
# shellcheck disable=SC2068
$GITHUB_WORKSPACE/dist/main.js ${options[@]}
npx css-typed ${options[@]}

{ set +x; } 2>/dev/null # Turn off command printing, and do not print set +X

# Use `diff` to compare the files.
# Use `-I '//.*'` to ignore the first line (comment) which has generated path and timestamp.
Expand Down