diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f8f22c..6549850 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,42 @@ concurrency: jobs: build: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: 18 + + - name: NPM install + run: npm ci + + - name: Build + run: npx rescript + + - name: Pack + run: npm pack + + - name: Prepare package upload + # For pull requests, pass the correct commit SHA explicitly as GITHUB_SHA points to the wrong commit. + run: node .github/workflows/prepare_package_upload.js ${{ github.event.pull_request.head.sha }} + + - name: "Upload artifact: npm package" + uses: actions/upload-artifact@v4 + with: + name: ${{ env.artifact_filename }} + path: ${{ env.artifact_filename }} + + outputs: + artifact_filename: ${{ env.artifact_filename }} + + test: + needs: build + strategy: fail-fast: false matrix: @@ -40,17 +76,15 @@ jobs: with: node-version: 18 - - name: NPM install - run: npm ci - - - name: Build - run: npx rescript + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + name: ${{ needs.build.outputs.artifact_filename }} - name: Test env: CI: 1 shell: bash run: | - npm pack - npm i -g ./create-rescript-app-*.tgz + npm i -g ${{ needs.build.outputs.artifact_filename }} npx create-rescript-app diff --git a/.github/workflows/prepare_package_upload.js b/.github/workflows/prepare_package_upload.js new file mode 100644 index 0000000..b358792 --- /dev/null +++ b/.github/workflows/prepare_package_upload.js @@ -0,0 +1,17 @@ +const fs = require("fs"); +const os = require("os"); + +const packageSpec = JSON.parse(fs.readFileSync("./package.json", "utf8")); +const { version } = packageSpec; + +const commitHash = process.argv[2] || process.env.GITHUB_SHA; +const commitHashShort = commitHash.substring(0, 7); +const artifactFilename = `create-rescript-app-${version}-${commitHashShort}.tgz`; + +fs.renameSync(`create-rescript-app-${version}.tgz`, artifactFilename); + +// Pass information to subsequent GitHub actions +fs.appendFileSync( + process.env.GITHUB_ENV, + `artifact_filename=${artifactFilename}${os.EOL}` +);