Skip to content

Commit

Permalink
test matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
dany-pellerin committed Nov 12, 2024
1 parent 0475026 commit affc13d
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 8 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,39 @@ jobs:
build:
needs: [tests-prettier]
uses: ./.github/workflows/reusable-build.yml

define-gcs-versions-to-update:
runs-on: ubuntu-latest

outputs:
sdk-versions: ${{ steps.sdk-versions.outputs.versions }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install asdf CLI
uses: asdf-vm/actions/install@v3

- name: Define versions to update
id: sdk-versions
run: ./scripts/versions-to-update.sh @optable/web-sdk v0.20.2 >> "$GITHUB_OUTPUT"

# Print output
- name: Print versions
run: |
echo "SDK versions: ${{ steps.sdk-versions.outputs.versions }}"
deploy-sdk-to-gcs:
needs: [define-gcs-versions-to-update]
strategy:
matrix:
sdk-version: ${{ fromJSON(needs.define-gcs-versions-to-update.outputs.sdk-versions) }}
runs-on: ubuntu-latest
env:
gcp-project-id: 118585658141
service-account: gh-ci-optable-web-sdk
steps:
- name: Versions to update
run: |
echo "Versions to update: ${{ matrix.sdk-version }}"
57 changes: 53 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
needs: [tests-prettier]
uses: ./.github/workflows/reusable-build.yml

deploy-sdk:
deploy-sdk-to-npm:
needs: [build]
runs-on: ubuntu-latest
env:
gcp-project-id: 118585658141
service-account: gh-ci-optable-web-sdk
gcp-project-id: 118585658141
service-account: gh-ci-optable-web-sdk
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -73,8 +73,57 @@ jobs:
path: "browser/dist/sdk.js"
destination: "gs://optable-web-sdk/latest"

define-gcs-versions-to-update:
needs: [deploy-sdk-to-npm]
runs-on: ubuntu-latest

outputs:
sdk-versions: ${{ steps.sdk-versions.outputs.versions }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install asdf CLI
uses: asdf-vm/actions/install@v3

- name: Define versions to update
id: sdk-versions
run: ./scripts/versions-to-update.sh @optable-web-sdk ${{ github.ref_name }} >> "$GITHUB_OUTPUT"

- name: Show versions that will be updated
run: |
echo "SDK versions: ${{ steps.sdk-versions.outputs.versions }}"
deploy-sdk-to-gcs:
needs: [define-gcs-versions-to-update]
strategy:
matrix:
sdk-version: ${{ fromJSON(needs.define-gcs-versions-to-update.outputs.sdk-versions) }}
runs-on: ubuntu-latest
env:
gcp-project-id: 118585658141
service-account: gh-ci-optable-web-sdk
steps:
- name: Download web artifacts
uses: actions/download-artifact@v4
with:
name: dist-web
path: browser/dist

- uses: "google-github-actions/auth@v2"
with:
workload_identity_provider: "projects/${{ env.gcp-project-id }}/locations/global/workloadIdentityPools/optable-ci/providers/github-pool-provider"
service_account: "${{ env.service-account }}@optable-platform-ci.iam.gserviceaccount.com"

- name: Upload SDK to GCS bucket, upload new version
uses: "google-github-actions/upload-cloud-storage@v2"
with:
path: "browser/dist/sdk.js"
destination: "gs://optable-web-sdk/${{ matrix.sdk-version }}"

deploy-demo:
needs: [deploy-sdk]
needs: [deploy-sdk-to-npm]
permissions:
contents: "read"
id-token: "write"
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@ jobs:

build-vanilla-demo:
runs-on: ubuntu-latest
defaults:
run:
working-directory: demos
env:
SDK_URI: https://cdn.optable.co/web-sdk/${{ github.ref_name }}/sdk.js
# The ref_name (tag) is not relevant when it runs on something other than a tag so we use latest
SDK_URI: https://cdn.optable.co/web-sdk/${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || 'latest' }}/sdk.js
ADS_HOST: ads.optable.co
ADS_REGION: ca
ADS_SITE: 4fe7c1ce-7c7d-4718-a0b8-5195e489319f
Expand Down
58 changes: 58 additions & 0 deletions scripts/versions-to-update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash
set -eu

usage() {
cat << USAGE >&2
Usage:
$0 <package> <version>
USAGE
}

if [[ $# -lt 2 ]]; then
usage
exit 1
fi

get_versions() {
local package="$1"
local version="$2"
local major=$(semver get major "$version")
local minor=$(semver get minor "$version")
local prerel=$(semver get prerel "$version")
local latestVersion=$(npm view $package version)

# Prerelease we only update the current version
if [[ "$prerel" != "" ]]; then
echo "versions=['$version']"
return 0
fi

local versionCompare=$(semver compare "$version" "$latestVersion")

# If this update version is the latest, we update all versions
if [[ $versionCompare -eq 1 ]]; then
echo "versions=['$version','v$major.$minor','v$major','latest']"
return 0
fi

# Initialize versions to update with the current version and major.minor, we always update both at least
local versionsToUpdate=(
"$version"
"v$major.$minor"
)

# Get the latest minor version of the specified major version
local latestMinorOfSpecifiedMajor=$(npm view $package versions --json | jq -r '.[]' | grep -E "^$major\." | sort -V | tail -n 1)
local latestMinor=$(semver get minor "$latestMinorOfSpecifiedMajor")

# If the current version is the latest minor or greater version of the specified major version, we update the major version
if [[ "$minor" -ge "$latestMinor" ]]; then
versionsToUpdate+=("v$major")
fi

# format the output
echo "versions=['$(IFS=, ; echo "${versionsToUpdate[*]}" | sed "s/,/','/g")']"
return 0
}

get_versions "$1" "$2"

0 comments on commit affc13d

Please sign in to comment.