From 1ac8dae1a35b2ec617934175b3e1d6d9f109f3e4 Mon Sep 17 00:00:00 2001 From: Guillaume Galy Date: Wed, 4 Dec 2024 11:37:44 +0100 Subject: [PATCH] feat: Create and distribute Gatling JS bundle, close RNG-53 Co-authored-by: guilgaly --- .../build-and-upload-bundle/action.yml | 49 ++++ .github/workflows/release.yml | 242 +++++++++++++++++- 2 files changed, 278 insertions(+), 13 deletions(-) create mode 100644 .github/actions/build-and-upload-bundle/action.yml diff --git a/.github/actions/build-and-upload-bundle/action.yml b/.github/actions/build-and-upload-bundle/action.yml new file mode 100644 index 0000000..37e05a2 --- /dev/null +++ b/.github/actions/build-and-upload-bundle/action.yml @@ -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)" + npm ci + npm version "${{ inputs.version }}" + 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" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9ce609f..3abdcef 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,7 +7,7 @@ on: permissions: id-token: write - contents: read + contents: write defaults: run: @@ -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 @@ -48,39 +50,39 @@ 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 + name: release-jvm-workdir path: . - retention-days: 1 + 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 }} @@ -88,9 +90,223 @@ jobs: 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 "--workspace=@gatling.io/$pkg" done + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: release-js-workdir + path: . + retention-days: 7 + + create-github-release: + name: Create GitHub release (draft) + needs: 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 }} + 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 \ + --location \ + --silent \ + --show-error \ + --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 @- <> $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 x64 + 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 + releases_url=$(echo "${{ github.event.repository.releases_url }}" | sed 's/{\/id}//') + response=$(curl \ + --location \ + --silent \ + --show-error \ + --request PATCH \ + --header "Accept: application/vnd.github+json" \ + --header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + --header "X-GitHub-Api-Version: 2022-11-28" \ + "$releases_url" \ + --data @- <> $GITHUB_OUTPUT