Skip to content

Commit

Permalink
chore: Add minify step to release action
Browse files Browse the repository at this point in the history
  • Loading branch information
tshashkova committed Aug 3, 2024
1 parent f3f7ef7 commit ea2e677
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 45 deletions.
4 changes: 2 additions & 2 deletions .github/actions/build_package/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ runs:
using: "composite"
steps:
- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '18.x'
node-version: '20.x'
- name: Install dev dependencies
if: inputs.mode != 'prod'
shell: bash
Expand Down
72 changes: 72 additions & 0 deletions .github/actions/upload_minified_version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: minify

inputs:
package:
description: Selected package to minify
required: true
tag:
description: Tag to checkout
required: true

runs:
using: "composite"
steps:
- name: Create tmp folder
shell: bash
run: mkdir -p ./tmp

- name: Checkout source code
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag }}
fetch-tags: true
path: ./packages

- name: Copy packages
shell: bash
run: cp -r ./tmp/packages/* ./packages

- name: Run build
uses: ./.github/actions/build_package
with:
mode: 'prod'

- 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'
process_gcloudignore: false
57 changes: 15 additions & 42 deletions .github/workflows/minify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -28,51 +28,24 @@ jobs:
id-token: 'write'

steps:
- name: Set TAG
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
fetch-depth: 0

- name: Extract version
run: |
echo "VERSION=$(node -e "console.log(require('./packages/${{ env.PACKAGE }}/package.json').version)")" >> $GITHUB_ENV
id: extract-version

- name: Set OUTPUT
run: |
echo "OUTPUT=packages/${{ env.PACKAGE }}/dist/inworld-${{ env.PACKAGE }}-${{ env.VERSION }}.min.js" >> $GITHUB_ENV
- 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: Set TAG from inputs
run: echo "TAG=refs/tags/${{ inputs.package }}@${{ inputs.version }}" >> $GITHUB_ENV
if: inputs.version != ''

- name: Rename minified file
run: |
mv packages/${{ env.PACKAGE }}/dist/inworld-${{ env.PACKAGE }}.min.js ${{ env.OUTPUT }}
- name: Set TAG as the latest one
run: echo "TAG=refs/tags/`echo $(git describe --tags --match="${{ inputs.package }}*" --abbrev=0)`" >> $GITHUB_ENV
if: inputs.version == ''

- name: Upload to GCS
uses: 'google-github-actions/upload-cloud-storage@v2'
- name: Minify and upload
uses: ./.github/actions/upload_minified_version
with:
path: ${{ env.OUTPUT }}
destination: 'innequin-assets/packages'
package: ${{ inputs.package }}
tag: ${{ env.TAG }}
env:
AUTH_SERVICE_ACCOUNT: ${{ env.AUTH_SERVICE_ACCOUNT }}
AUTH_IDENTITY_PROVIDER: ${{ env.AUTH_IDENTITY_PROVIDER }}
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ on:
- '@inworld/web-core'
- '@inworld/web-threejs'

env:
AUTH_SERVICE_ACCOUNT: [email protected]
AUTH_IDENTITY_PROVIDER: projects/678423885598/locations/global/workloadIdentityPools/github-devops-pool/providers/github-prvdr

jobs:
github-release:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -55,6 +59,28 @@ 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@v4
with:
fetch-depth: 0
- name: Set TAG as the latest one
run: echo "TAG=refs/tags/`echo $(git describe --tags --match="${{ inputs.package }}*" --abbrev=0)`" >> $GITHUB_ENV
- name: Minify and upload
uses: ./.github/actions/upload_minified_version
with:
package: ${{ inputs.package }}
tag: ${{ env.TAG }}
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]
Expand Down
2 changes: 1 addition & 1 deletion packages/web-core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"outDir": "build",
"resolveJsonModule": true,
"skipLibCheck": true,
"target": "es2015",
"target": "es2017",
"types": [
"jest",
"node"
Expand Down

0 comments on commit ea2e677

Please sign in to comment.