From 18f3be14bb498011acdc293b0b5a33430df97cb3 Mon Sep 17 00:00:00 2001 From: Tatyana Shashkova Date: Fri, 2 Aug 2024 20:23:40 -0700 Subject: [PATCH] chore: Add minify step to release action --- .../upload_minified_version/action.yml | 47 +++++++++++++ .github/workflows/minify.yml | 69 ++++++++----------- .github/workflows/release.yml | 27 ++++++++ 3 files changed, 102 insertions(+), 41 deletions(-) create mode 100644 .github/actions/upload_minified_version/action.yml diff --git a/.github/actions/upload_minified_version/action.yml b/.github/actions/upload_minified_version/action.yml new file mode 100644 index 00000000..7dde150b --- /dev/null +++ b/.github/actions/upload_minified_version/action.yml @@ -0,0 +1,47 @@ +name: minify + +inputs: + package: + description: Selected package to minify + +runs: + using: "composite" + steps: + - name: Set PACKAGE + shell: bash + run: | + echo "PACKAGE=$(echo ${{ inputs.package }} | sed 's/@inworld\///g')" >> $GITHUB_ENV + + - name: Extract version + shell: bash + run: | + echo "VERSION=$(node -e "console.log(require('./packages/${{ env.PACKAGE }}/package.json').version)")" >> $GITHUB_ENV + id: extract-version + + - name: Set OUTPUT + shell: bash + run: | + echo "OUTPUT=packages/${{ env.PACKAGE }}/dist/inworld-${{ env.PACKAGE }}-${{ env.VERSION }}.min.js" >> $GITHUB_ENV + + - name: Minify + shell: bash + run: | + npx yarn workspace ${{ inputs.package }} minify + + - name: Authenticate to Google Cloud + uses: google-github-actions/auth@v2 + with: + workload_identity_provider: ${{ env.AUTH_IDENTITY_PROVIDER }} + service_account: ${{ env.AUTH_SERVICE_ACCOUNT }} + create_credentials_file: true + + - name: Rename minified file + shell: bash + run: | + mv packages/${{ env.PACKAGE }}/dist/inworld-${{ env.PACKAGE }}.min.js ${{ env.OUTPUT }} + + - name: Upload to GCS + uses: 'google-github-actions/upload-cloud-storage@v2' + with: + path: ${{ env.OUTPUT }} + destination: 'innequin-assets/packages' diff --git a/.github/workflows/minify.yml b/.github/workflows/minify.yml index 1d4d3d96..026c5b32 100644 --- a/.github/workflows/minify.yml +++ b/.github/workflows/minify.yml @@ -11,7 +11,7 @@ on: - '@inworld/web-threejs' version: type: string - description: "The version of package to minify. The version should be the same as version in package.json. For example, 1.0.0" + description: "The version of package to minify. The version should be the same as version in package.json. For example, 1.0.0. Otherwise, the latest version will be used." required: false env: @@ -28,51 +28,38 @@ jobs: id-token: 'write' steps: - - name: Set TAG + # - name: Checkout source code + # uses: actions/checkout@v4 + # with: + # fetch-depth: 0 + + - name: Set TAG from inputs run: echo "TAG=refs/tags/${{ inputs.package }}@${{ inputs.version }}" >> $GITHUB_ENV if: inputs.version != '' - - name: Checkout source code - uses: actions/checkout@v4 - with: - ref: ${{ env.TAG }} - fetch-tags: true - - - name: Run build - uses: ./.github/actions/build_package - with: - package: ${{ inputs.package }} - - - name: Set PACKAGE - run: | - echo "PACKAGE=$(echo ${{ inputs.package }} | sed 's/@inworld\///g')" >> $GITHUB_ENV - - - name: Extract version - run: | - echo "VERSION=$(node -e "console.log(require('./packages/${{ env.PACKAGE }}/package.json').version)")" >> $GITHUB_ENV - id: extract-version + - name: Set env from GITHUB_REF + run: echo "TAG=refs/tags/`echo $(git describe --tags --abbrev=0)`" >> $GITHUB_ENV + if: inputs.version == '' - - name: Set OUTPUT + - name: Test run: | - echo "OUTPUT=packages/${{ env.PACKAGE }}/dist/inworld-${{ env.PACKAGE }}-${{ env.VERSION }}.min.js" >> $GITHUB_ENV + echo $TAG - - name: Minify - run: | - npx yarn workspace ${{ inputs.package }} minify - - - name: Authenticate to Google Cloud - uses: google-github-actions/auth@v2 - with: - workload_identity_provider: ${{ env.AUTH_IDENTITY_PROVIDER }} - service_account: ${{ env.AUTH_SERVICE_ACCOUNT }} - create_credentials_file: true + # - name: Checkout source code + # uses: actions/checkout@v4 + # with: + # ref: ${{ env.TAG }} + # fetch-tags: true - - name: Rename minified file - run: | - mv packages/${{ env.PACKAGE }}/dist/inworld-${{ env.PACKAGE }}.min.js ${{ env.OUTPUT }} + # - name: Run build + # uses: ./.github/actions/build_package + # with: + # package: ${{ inputs.package }} - - name: Upload to GCS - uses: 'google-github-actions/upload-cloud-storage@v2' - with: - path: ${{ env.OUTPUT }} - destination: 'innequin-assets/packages' + # - name: Minify and upload + # uses: ./.github/actions/minify + # with: + # package: ${{ inputs.package }} + # env: + # AUTH_SERVICE_ACCOUNT: ${{ env.AUTH_SERVICE_ACCOUNT }} + # AUTH_IDENTITY_PROVIDER: ${{ env.AUTH_IDENTITY_PROVIDER }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 645d1684..43cb4723 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,6 +18,10 @@ on: - '@inworld/web-core' - '@inworld/web-threejs' +env: + AUTH_SERVICE_ACCOUNT: inworld-web-sdk@inworld-ai-github.iam.gserviceaccount.com + AUTH_IDENTITY_PROVIDER: projects/678423885598/locations/global/workloadIdentityPools/github-devops-pool/providers/github-prvdr + jobs: github-release: runs-on: ubuntu-latest @@ -55,6 +59,29 @@ jobs: - name: Publish to npm run: npx yarn workspace ${{ inputs.package }} release:publish + minify-and-upload: + runs-on: [self-hosted, linux, x64, kubernetes, ephemeral] + needs: [npm-release] + permissions: + contents: 'read' + id-token: 'write' + steps: + - name: Checkout source code + uses: actions/checkout@v3 + with: + ref: main + - name: Run build + uses: ./.github/actions/build_package + with: + mode: 'prod' + - name: Minify and upload + uses: ./.github/actions/minify + with: + package: ${{ inputs.package }} + env: + AUTH_SERVICE_ACCOUNT: ${{ env.AUTH_SERVICE_ACCOUNT }} + AUTH_IDENTITY_PROVIDER: ${{ env.AUTH_IDENTITY_PROVIDER }} + release-notification: runs-on: [self-hosted, kubernetes, nodocker] needs: [github-release, npm-release]