diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 031bc44..e5d7e73 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Tests +name: CI on: push: @@ -27,12 +27,12 @@ jobs: - name: Install deps run: yarn install - # Read existing version, reuse that, add a Git short hash - # - name: Set build version to Git commit - # run: node scripts/writeGitVersion.js $(git rev-parse --short HEAD) + # Read existing version, reuse that, add a Git short hash + - name: Set build version to Git commit + run: node scripts/writeGitVersion.js $(git rev-parse --short HEAD) - # - name: Check updated version - # run: jq .version package.json + - name: Check updated version + run: jq .version package.json - name: Run linter run: yarn lint @@ -40,9 +40,6 @@ jobs: - name: Run tests run: yarn test - - name: Compile - run: yarn build - - name: Pack run: yarn pack @@ -82,3 +79,65 @@ jobs: run: | yarn tsc --version yarn test:typescript + + test-published-artifact: + name: Test Published Artifact ${{ matrix.example }} + + needs: [build] + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node: ['16.x'] + example: [ + # 'cra4', + 'cra5', + # 'next', + 'vite' + # 'node-standard', + # 'node-esm', + # 'are-the-types-wrong', + ] + defaults: + run: + working-directory: ./examples/publish-ci/${{ matrix.example }} + steps: + - name: Checkout repo + uses: actions/checkout@v2 + + - name: Use node ${{ matrix.node }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node }} + cache: 'yarn' + + - name: Clone RTK repo + run: git clone https://github.com/reduxjs/redux-toolkit.git + + - name: Select example + run: cd redux-toolkit/examples/publish-ci/${{ matrix.example }} + + - name: Install deps + run: yarn install + + - uses: actions/download-artifact@v2 + with: + name: package + path: ./examples/publish-ci/${{ matrix.example }} + + - name: Check folder contents + run: ls -l . + + - name: Install Redux-Thunk build artifact + run: yarn add ./package.tgz + + - name: Show installed package versions + run: > + yarn info redux-thunk + yarn why redux-thunk + + - name: Build example + run: yarn build + + - name: Run test step + run: yarn test diff --git a/scripts/writeGitVersion.js b/scripts/writeGitVersion.js new file mode 100644 index 0000000..4a9efc9 --- /dev/null +++ b/scripts/writeGitVersion.js @@ -0,0 +1,14 @@ +import path from 'path' +import fs from 'fs' +import { fileURLToPath } from 'node:url' + +const __filename = fileURLToPath(import.meta.url) +const __dirname = path.dirname(__filename) + +const gitRev = process.argv[2] + +const packagePath = path.join(__dirname, '../package.json') +const pkg = JSON.parse(fs.readFileSync(packagePath)) + +pkg.version = `${pkg.version}-${gitRev}` +fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2))