Skip to content

Upload package as artifact #65

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

Merged
merged 1 commit into from
Jun 16, 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
48 changes: 41 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
17 changes: 17 additions & 0 deletions .github/workflows/prepare_package_upload.js
Original file line number Diff line number Diff line change
@@ -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}`
);