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

feat: Create and distribute Gatling JS bundle, close RNG-53 #105

Merged
merged 18 commits into from
Dec 10, 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
49 changes: 49 additions & 0 deletions .github/actions/build-and-upload-bundle/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: "Build and upload bundle"
description: "Build bundle (GraalVM + JVM dependencies) and upload it to a GitHub release"
inputs:
version:
description: "Gatling JS version"
required: true
upload-url:
description: "GitHub release upload URL"
required: true
os-type:
description: "Linux|Darwin|Windows_NT"
required: true
os-arch:
description: "x64|arm64"
required: true
github-token:
description: "Token used to upload file to the GitHub release"
required: true

runs:
using: "composite"
steps:
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Build bundle
shell: bash
working-directory: ./js
run: |
echo "architecture: $(arch)"
rm -rf node_modules bundle/node_modules
npm ci
npm run generate --workspace=bundle
upload_url=$(echo "${{ inputs.upload-url }}" | sed 's/{[^}]*}//')
echo "upload_url=$upload_url"
curl --location \
--silent \
--show-error \
--connect-timeout 10 \
--max-time 300 \
--request POST \
--header "Accept: application/vnd.github+json" \
--header "Authorization: Bearer ${{ inputs.github-token }}" \
--header "Content-Type: application/octet-stream" \
--header "X-GitHub-Api-Version: 2022-11-28" \
"${upload_url}?name=gatling-js-bundle-${{ inputs.version }}-${{ inputs.os-type }}-${{ inputs.os-arch }}.zip" \
--data-binary "@bundle/tmp/gatling-js-bundle-${{ inputs.version }}-${{ inputs.os-type }}-${{ inputs.os-arch }}.zip"
257 changes: 243 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

permissions:
id-token: write
contents: read
contents: write

defaults:
run:
Expand All @@ -21,6 +21,8 @@ jobs:
env:
JAVA_OPTS: "-Xmx4G"
SBT_OPTS: "-Dsbt.ci=true"
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -48,49 +50,276 @@ jobs:
run: |
sbt "project gatling-jvm-to-js-adapter" "release with-defaults"

- name: Setup version
id: version
run: |
version="$(cat jvm/adapter/target/release-info)"
echo "version=$version"
echo "version=$version" >> $GITHUB_OUTPUT

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: gatling-js-workdir
path: .
retention-days: 1
name: release-jvm-workdir
include-hidden-files: true
path: |
.
!.git/
retention-days: 7

release-js:
name: Release JS
needs: release-jvm
runs-on: ubuntu-latest
timeout-minutes: 10
environment:
name: npm
url: https://www.npmjs.com/org/gatling.io
timeout-minutes: 10
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: gatling-js-workdir
name: release-jvm-workdir

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Setup version
id: version
run: |
version="$(cat jvm/adapter/target/release-info)"
echo "version=$version"
echo "version=$version" >> $GITHUB_OUTPUT

- name: Deploy JS packages
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
working-directory: ./js
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
npm ci
npm version "${{ steps.version.outputs.version }}"
npm version "${{ needs.release-jvm.outputs.version }}"
npm run build --workspaces
for pkg in "cli" "jvm-types" "core" "http"; do
cp ../LICENSE "./$pkg/LICENSE"
npm publish --access public "[email protected]/$pkg"
done

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: release-js-workdir
include-hidden-files: true
path: |
.
!.git/
retention-days: 7

create-github-release:
name: Create GitHub release (draft)
needs:
- release-jvm
- release-js
runs-on: ubuntu-latest
timeout-minutes: 2
environment:
name: GitHub release (draft)
url: ${{ steps.release.outputs.html_url }}
outputs:
prerelease: ${{ steps.release.outputs.prerelease }}
url: ${{ steps.release.outputs.url }}
upload_url: ${{ steps.release.outputs.upload_url }}
steps:
- name: Create GitHub release (draft)
id: release
run: |
version="${{ needs.release-jvm.outputs.version }}"
if [[ "$version" =~ -M[0-9]+$ ]]; then
prerelease=true
else
prerelease=false
fi
echo "prerelease=$prerelease"
echo "prerelease=$prerelease" >> $GITHUB_OUTPUT
releases_url=$(echo "${{ github.event.repository.releases_url }}" | sed 's/{\/id}//')
response=$(curl \
--fail-with-body \
--location \
--show-error \
--silent \
--request POST \
--header "Accept: application/vnd.github+json" \
--header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
--header "X-GitHub-Api-Version: 2022-11-28" \
"$releases_url" \
--data @- <<EOF
{
"name": "Gatling JS $version",
"tag_name": "${{ github.ref_name }}",
"body": "To get started with Gatling JS, please check [the tutorial](https://docs.gatling.io/tutorials/scripting-intro-js/).\n\nThe bundle files in this release are normally automatically downloaded by the Gatling JS CLI. If you need to perform a manual install, please refer to [the documentation](https://docs.gatling.io/reference/integrations/build-tools/js-cli/).",
"draft": true,
"prerelease": $prerelease
}
EOF
)
echo "response=$response"
url=$(echo "$response" | jq --raw-output ".url")
echo "url=$url"
echo "url=$url" >> $GITHUB_OUTPUT
html_url=$(echo "$response" | jq --raw-output ".html_url")
echo "html_url=$html_url"
echo "html_url=$html_url" >> $GITHUB_OUTPUT
upload_url=$(echo "$response" | jq --raw-output ".upload_url")
echo "upload_url=$upload_url"
echo "upload_url=$upload_url" >> $GITHUB_OUTPUT

build-linux-x64:
name: Build bundle for Linux x64
needs:
- release-jvm
- create-github-release
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: release-js-workdir

- name: Build and upload bundle
uses: ./.github/actions/build-and-upload-bundle
with:
version: ${{ needs.release-jvm.outputs.version }}
upload-url: ${{ needs.create-github-release.outputs.upload_url }}
os-type: Linux
os-arch: x64
github-token: ${{ secrets.GITHUB_TOKEN }}

build-linux-arm64:
name: Build bundle for Linux ARM64
needs:
- release-jvm
- create-github-release
runs-on: ubuntu-24-arm-2-cores
timeout-minutes: 5
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: release-js-workdir

- name: Build and upload bundle
uses: ./.github/actions/build-and-upload-bundle
with:
version: ${{ needs.release-jvm.outputs.version }}
upload-url: ${{ needs.create-github-release.outputs.upload_url }}
os-type: Linux
os-arch: arm64
github-token: ${{ secrets.GITHUB_TOKEN }}

build-macos-x64:
name: Build bundle for macOS x64
needs:
- release-jvm
- create-github-release
runs-on: macos-13
timeout-minutes: 5
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: release-js-workdir

- name: Build and upload bundle
uses: ./.github/actions/build-and-upload-bundle
with:
version: ${{ needs.release-jvm.outputs.version }}
upload-url: ${{ needs.create-github-release.outputs.upload_url }}
os-type: Darwin
os-arch: x64
github-token: ${{ secrets.GITHUB_TOKEN }}

build-macos-arm64:
name: Build bundle for macOS ARM64
needs:
- release-jvm
- create-github-release
runs-on: macos-14
timeout-minutes: 5
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: release-js-workdir

- name: Build and upload bundle
uses: ./.github/actions/build-and-upload-bundle
with:
version: ${{ needs.release-jvm.outputs.version }}
upload-url: ${{ needs.create-github-release.outputs.upload_url }}
os-type: Darwin
os-arch: arm64
github-token: ${{ secrets.GITHUB_TOKEN }}

build-windows-x64:
name: Build bundle for Windows x64
needs:
- release-jvm
- create-github-release
runs-on: windows-latest
timeout-minutes: 5
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: release-js-workdir

- name: Build and upload bundle
uses: ./.github/actions/build-and-upload-bundle
with:
version: ${{ needs.release-jvm.outputs.version }}
upload-url: ${{ needs.create-github-release.outputs.upload_url }}
os-type: Windows_NT
os-arch: x64
github-token: ${{ secrets.GITHUB_TOKEN }}

publish-github-release:
name: Publish GitHub release
needs:
- create-github-release
- build-linux-x64
- build-linux-arm64
- build-macos-x64
- build-macos-arm64
- build-windows-x64
runs-on: ubuntu-latest
timeout-minutes: 2
environment:
name: GitHub release
url: ${{ steps.release.outputs.html_url }}
steps:
- name: Publish GitHub release
id: release
run: |
prerelease="${{ needs.create-github-release.outputs.prerelease }}"
if [[ "$prerelease" = "true" ]]; then
make_latest=false
else
make_latest=true
fi
response=$(curl \
--fail-with-body \
--location \
--show-error \
--silent \
--request PATCH \
--header "Accept: application/vnd.github+json" \
--header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
--header "X-GitHub-Api-Version: 2022-11-28" \
"${{ needs.create-github-release.outputs.url }}" \
--data @- <<EOF
{
"draft": false,
"make_latest": $make_latest
}
EOF
)
echo "response=$response"
html_url=$(echo "$response" | jq --raw-output ".html_url")
echo "html_url=$html_url"
echo "html_url=$html_url" >> $GITHUB_OUTPUT
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ node_modules/

# build targets
target/
/tmp/
tmp/
/js/bundle/src/versions.ts
/js/cli/src/dependencies/versions.ts
/js/jvm-types/index.js
/js/jvm-types/index.d.ts
Expand Down
15 changes: 15 additions & 0 deletions build-bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -e

root_dir="$(dirname "$(realpath -- "$0")")"

# Build bundle
cd "$root_dir/js"
npm run generate --workspace=bundle

# Install bundle (manually)
bundle_file="../js/bundle/tmp/gatling-js-bundle-0.0.0-SNAPSHOT-Darwin-arm64.zip"
install_dir="$HOME/.gatling/gatling-js-bundle/0.0.0-SNAPSHOT/"
rm -rf "$install_dir"
"${root_dir}/js/cli/target/index.js" install "$bundle_file"
Loading
Loading