diff --git a/.github/actions/build-and-test/action.yml b/.github/actions/build-and-test/action.yml new file mode 100644 index 000000000..baa4253f3 --- /dev/null +++ b/.github/actions/build-and-test/action.yml @@ -0,0 +1,48 @@ +author: airtasker +name: build-and-test +description: Build and test. + +inputs: + node_version: + required: true + description: The version of Node.js to use. + shard: + required: true + description: Which shard we're on. + +runs: + using: composite + steps: + - uses: ./.github/actions/prepare-repository + + - name: Compile the repository on this version of Node. + run: yarn build + shell: bash + + - name: Create test reports directory + run: mkdir -p ./test-reports/jest + shell: bash + + - name: Find and run test files + run: | + TESTFILES=$(find lib -name '*.spec.ts') + for file in $TESTFILES; do + filename=$(basename "$file" .spec.ts) + JEST_JUNIT_OUTPUT_NAME="${{ github.sha }}_${{ github.run_id }}_node${{ inputs.node_version }}_${{ inputs.shard }}_${filename}_results.xml" \ + yarn test $file --ci --reporters=default --reporters=jest-junit --shard=${{ inputs.shard }} + done + env: + JEST_JUNIT_OUTPUT_DIR: ./test-reports/jest + JEST_JUNIT_CLASSNAME: "{filepath}" + JEST_JUNIT_UNIQUE_OUTPUT_NAME: "true" + shell: bash + + - name: Build the documentation. + run: |- + set -uex + if [ ${{ inputs.node_version }} -gt 16 ]; then + # Without this, we get `Error: error:0308010C:digital envelope routines::unsupported` on Node >= 17. + export NODE_OPTIONS="--openssl-legacy-provider" + fi + yarn build-docs + shell: bash \ No newline at end of file diff --git a/.github/actions/prepare-repository/action.yml b/.github/actions/prepare-repository/action.yml new file mode 100644 index 000000000..2b2dcedc5 --- /dev/null +++ b/.github/actions/prepare-repository/action.yml @@ -0,0 +1,47 @@ +author: airtasker +name: prepare-repository +description: Prepare the repository for building and testing. + +runs: + using: composite + + steps: + - uses: actions/checkout@v4 + - name: restore_cache + uses: actions/cache@v3 + with: + key: v3-dependencies-{{ checksum "yarn.lock" }} + path: node_modules + restore-keys: |- + v3-dependencies-{{ checksum "yarn.lock" }} + v3-dependencies + + - name: Install main dependencies + run: yarn install --frozen-lockfile + shell: bash + + - name: save_cache + uses: actions/cache@v3 + with: + path: node_modules + key: v3-dependencies-{{ checksum "yarn.lock" }} + + - name: restore_cache + uses: actions/cache@v3 + with: + key: v3-docs-dependencies-{{ checksum "docs/yarn.lock" }} + path: docs/node_modules + restore-keys: |- + v3-docs-dependencies-{{ checksum "docs/yarn.lock" }} + v3-docs-dependencies + + - name: Install docs dependencies + run: yarn install --frozen-lockfile + working-directory: docs/ + shell: bash + + - name: save_cache + uses: actions/cache@v3 + with: + path: docs/node_modules + key: v3-docs-dependencies-{{ checksum "docs/yarn.lock" }} \ No newline at end of file diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b79fbd99f..cded74cee 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,19 +1,40 @@ version: 2 updates: -- package-ecosystem: npm - directory: "/" - schedule: - interval: weekly - day: monday - time: "05:00" - timezone: Australia/Sydney - open-pull-requests-limit: 99 -- package-ecosystem: npm - directory: "/docs" - schedule: - interval: weekly - day: monday - time: "05:00" - timezone: Australia/Sydney - open-pull-requests-limit: 99 + - package-ecosystem: npm + directory: "/" + schedule: + interval: weekly + day: monday + time: "05:00" + timezone: Australia/Sydney + open-pull-requests-limit: 99 + - package-ecosystem: npm + directory: "/docs" + schedule: + interval: weekly + day: monday + time: "05:00" + timezone: Australia/Sydney + open-pull-requests-limit: 99 + - package-ecosystem: github-actions + directory: "/" + schedule: + interval: daily + time: "09:00" + timezone: Australia/Sydney + open-pull-requests-limit: 10 + - package-ecosystem: github-actions + directory: "/.github/actions/build-and-test" + schedule: + interval: daily + time: "09:00" + timezone: Australia/Sydney + open-pull-requests-limit: 10 + - package-ecosystem: github-actions + directory: "/.github/actions/prepare-repository" + schedule: + interval: daily + time: "09:00" + timezone: Australia/Sydney + open-pull-requests-limit: 10 diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 000000000..2be382793 --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,83 @@ +name: airtasker/spot/build-and-test + +on: + pull_request: + branches: + - master + push: + branches: + - master + release: + types: [published] + +env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + +jobs: + test: + name: test-node-${{ matrix.node-version }} + runs-on: runs-on,runner=4cpu-linux-x64 + strategy: + fail-fast: true # if one job fails, stop the rest + matrix: + node-version: [14, 16, 18, 20] + shard: + [ + "1", + "2", + "3", + "4", + ] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup NodeJS ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Run tests + uses: "./.github/actions/build-and-test" + with: + node_version: ${{ matrix.node-version }} + shard: ${{ matrix.shard }} + + - name: Upload test results + uses: actions/upload-artifact@v4 + with: + name: test-results-node-${{ matrix.node-version }}-${{ matrix.shard }} + path: ./test-reports + + - name: Test summary + uses: test-summary/action@v2 + with: + paths: ./test-reports/**/*.xml + + lint-check: + runs-on: runs-on,runner=4cpu-linux-x64 + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare-repository + + - name: Run lint checker + run: yarn lint:check + + publish: + runs-on: runs-on,runner=4cpu-linux-x64 + if: github.event_name == 'release' + needs: + - test + - lint-check + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/prepare-repository + + - name: Authenticate with NPM registry + run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc + + - name: Publish + run: npm publish --access=public