0.13.3 #99
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
on: | |
release: | |
types: | |
- published | |
env: | |
CDN_URL: https://cdn.croct.io/js/v1/lib/plug.js | |
PLAYGROUND_ORIGIN: https://play.croct.com | |
PLAYGROUND_CONNECT_URL: https://play.croct.com/connect.html | |
PREVIEW_WIDGET_ORIGIN: https://cdn.croct.io | |
PREVIEW_WIDGET_PATH: js/v1/lib/plug/widget-${{ github.ref_name }}.html | |
PREVIEW_WIDGET_URL: https://cdn.croct.io/js/v1/lib/plug/widget-${{ github.ref_name }}.html | |
jobs: | |
deploy-library: | |
permissions: | |
id-token: write # This is required for requesting the JWT | |
contents: read # This is required for actions/checkout | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
- name: Cache dependencies | |
id: cache-dependencies | |
uses: actions/cache@v3 | |
with: | |
path: node_modules | |
key: node_modules-${{ hashFiles('package-lock.json') }} | |
- name: Install dependencies | |
if: steps.cache-dependencies.outputs.cache-hit != 'true' | |
run: |- | |
npm ci | |
rm -rf ~/.npmrc | |
- name: Build package | |
run: |- | |
npm run build | |
- name: Prepare release | |
run: |- | |
cp package.json LICENSE README.md build/ | |
cd build | |
find . -type f -path '*/*\.js.map' -exec sed -i -e "s~../src~src~" {} + | |
sed -i -e "s~\"version\": \"0.0.0-dev\"~\"version\": \"${GITHUB_REF##*/}\"~" package.json | |
sed -i -e "s~<@cdnUrl@>~${CDN_URL}~" constants.* | |
sed -i -e "s~<@playgroundOrigin@>~${PLAYGROUND_ORIGIN}~" constants.* | |
sed -i -e "s~<@playgroundConnectUrl@>~${PLAYGROUND_CONNECT_URL}~" constants.* | |
sed -i -e "s~<@previewWidgetOrigin@>~${PREVIEW_WIDGET_ORIGIN}~" constants.* | |
sed -i -e "s~<@previewWidgetUrl@>~${PREVIEW_WIDGET_URL}~" constants.* | |
cp -r ../src src | |
- name: Publish pre-release to NPM | |
if: ${{ github.event.release.prerelease }} | |
run: |- | |
cd build | |
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ~/.npmrc | |
npm publish --access public --tag next | |
env: | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Publish release to NPM | |
if: ${{ !github.event.release.prerelease }} | |
run: |- | |
cd build | |
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ~/.npmrc | |
npm publish --access public | |
env: | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Bundle package | |
if: ${{ !github.event.release.prerelease }} | |
run: |- | |
rm -rf build | |
npm run bundle -- --config-cdn-url=${CDN_URL} \ | |
--config-playground-origin=${PLAYGROUND_ORIGIN} \ | |
--config-playground-connect-url=${PLAYGROUND_CONNECT_URL} \ | |
--config-preview-widget-origin=${PREVIEW_WIDGET_ORIGIN} \ | |
--config-preview-widget-url=${PREVIEW_WIDGET_URL} | |
- id: 'auth' | |
name: 'Authenticate to Google Cloud' | |
if: ${{ !github.event.release.prerelease }} | |
uses: 'google-github-actions/auth@v1' | |
with: | |
workload_identity_provider: '${{ secrets.GCLOUD_WORKLOAD_IDENTITY }}' | |
service_account: '${{ secrets.GCLOUD_SERVICE_ACCOUNT }}' | |
- name: Set up Cloud SDK | |
uses: google-github-actions/setup-gcloud@v1 | |
- name: Deploy to GCS | |
if: ${{ !github.event.release.prerelease }} | |
env: | |
GCLOUD_BUCKET: ${{ secrets.GCLOUD_BUCKET }} | |
run: |- | |
gsutil -m cp build/plug.min.js "gs://${GCLOUD_BUCKET}/js/v1/lib/plug.js" | |
gsutil -m setmeta -h "Cache-Control: public, max-age=3600" "gs://${GCLOUD_BUCKET}/js/v1/lib/plug.js" | |
deploy-preview-widget: | |
permissions: | |
id-token: write # This is required for requesting the JWT | |
contents: read # This is required for actions/checkout | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: preview | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
- name: Cache dependencies | |
id: cache-dependencies | |
uses: actions/cache@v3 | |
with: | |
path: node_modules | |
key: node_modules-${{ hashFiles('package-lock.json') }} | |
- name: Install dependencies | |
if: steps.cache-dependencies.outputs.cache-hit != 'true' | |
run: |- | |
npm ci | |
- name: Build package | |
run: |- | |
npm run build | |
- id: auth | |
name: Authenticate to Google Cloud | |
uses: google-github-actions/auth@v1 | |
with: | |
workload_identity_provider: '${{ secrets.GCLOUD_WORKLOAD_IDENTITY }}' | |
service_account: '${{ secrets.GCLOUD_SERVICE_ACCOUNT }}' | |
- name: Set up Cloud SDK | |
uses: google-github-actions/setup-gcloud@v1 | |
- name: Deploy to GCS | |
env: | |
GCLOUD_BUCKET: ${{ secrets.GCLOUD_BUCKET }} | |
run: |- | |
gsutil -m cp dist/widget.html "gs://${GCLOUD_BUCKET}/${PREVIEW_WIDGET_PATH}" | |
gsutil -m setmeta -h "Cache-Control: public, max-age=3600" "gs://${GCLOUD_BUCKET}/${PREVIEW_WIDGET_PATH}" |