Skip to content

Artifacts Build

Artifacts Build #2076

Workflow file for this run

# This file is part of ICU4X. For terms of use, please see the file
# called LICENSE at the top level of the ICU4X source tree
# (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
##### README #####
#
# The CI action in this file is used to build the artifacts on pushes to a repository containing
# the ICU4X service account key. All steps are skipped unless the key is present.
#
# If you are a frequent contributor, you can add the key to your fork. The key is shared with
# icu4x collaborators and can be viewed here:
#
# https://drive.google.com/file/d/17-oMqRfuHOHL9hYp64NYOh8vcJ03DQHm/view
#
# To add the key, follow these steps:
#
# 1. Go to the secrets on your fork:
# - https://github.com/{USER}/icu4x/settings/secrets/actions
# 2. Click "New repository secret" and enter the following information:
# - Name: ICU4X_GCP_SA_KEY
# - Value: The contents of the file linked above
# 3. Click "Add secret"
# 4. Re-run the latest "Artifacts Build" action on your fork to make sure it works:
# - https://github.com/{USER}/icu4x/actions/workflows/artifacts-build.yml
name: Artifacts Build
on:
push
jobs:
credentials:
name: "Check Credentials"
runs-on: "ubuntu-latest"
env:
ICU4X_GCP_SA_KEY: "${{ secrets.ICU4X_GCP_SA_KEY }}"
steps:
- name: "Check for credentials"
run: |
if [ -z "$ICU4X_GCP_SA_KEY" ]
then
echo "GCP key not found. Docs previews will not be uploaded. If you are a frequent contributor, you may add the key to your fork; for instructions, see 'artifacts-build.yml'"
exit 1;
fi
docs:
name: "Docs Preview"
needs: credentials
runs-on: "ubuntu-latest"
env:
GCP_PROJECT_ID: "dev-infra-273822"
GCP_BUCKET_ID: "icu4x-pr-artifacts"
steps:
- uses: actions/checkout@v3
- name: Load the default Rust toolchain via the rust-toolchain file.
run: rustup show
- name: Authenticate to Google Cloud
uses: google-github-actions/setup-gcloud@v0.2
with:
project_id: ${{ env.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.ICU4X_GCP_SA_KEY }}
export_default_credentials: true
- name: Build docs
uses: actions-rs/cargo@v1
with:
command: doc
args: --workspace --release --all-features --no-deps
- name: Upload docs to Google Cloud Storage
run: |
gsutil -m cp -r target/doc gs://${{ env.GCP_BUCKET_ID }}/gha/${{ github.sha }}/docs
- name: "⭐⭐⭐ Links to Uploaded Artifacts ⭐⭐⭐"
run: |
echo "::group::📖 Docs Preview"
echo "http://${{ env.GCP_BUCKET_ID }}.storage.googleapis.com/gha/${{ github.sha }}/docs/icu/index.html"
echo "::endgroup::"
ffi-docs:
name: "FFI Preview"
needs: credentials
runs-on: "ubuntu-latest"
env:
GCP_PROJECT_ID: "dev-infra-273822"
GCP_BUCKET_ID: "icu4x-pr-artifacts"
steps:
- uses: actions/checkout@v3
- name: Authenticate to Google Cloud
uses: google-github-actions/setup-gcloud@v0.2
with:
project_id: ${{ env.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.ICU4X_GCP_SA_KEY }}
export_default_credentials: true
- name: Install Python
uses: actions/setup-python@v1
- name: Install Sphinx
uses: BSFishy/pip-action@v1
with:
packages: |
sphinx
sphinx-rtd-theme
- name: Build CPP docs
run: |
cd ffi/diplomat/cpp/docs
make html
cd ../../../..
- name: Build JS docs
run: |
cd ffi/diplomat/js/docs
make html
cd ../../../..
- name: Upload docs to Google Cloud Storage
run: |
gsutil -m cp -r ffi/diplomat/cpp/docs/build/html gs://${{ env.GCP_BUCKET_ID }}/gha/${{ github.sha }}/ffi/cpp
gsutil -m cp -r ffi/diplomat/js/docs/build/html gs://${{ env.GCP_BUCKET_ID }}/gha/${{ github.sha }}/ffi/js
- name: "⭐⭐⭐ Links to Uploaded Artifacts ⭐⭐⭐"
run: |
echo "::group::📖 CPP Docs Preview"
echo "http://${{ env.GCP_BUCKET_ID }}.storage.googleapis.com/gha/${{ github.sha }}/ffi/cpp/index.html"
echo "::endgroup::"
echo "::group::📖 JS Docs Preview"
echo "http://${{ env.GCP_BUCKET_ID }}.storage.googleapis.com/gha/${{ github.sha }}/ffi/js/index.html"
echo "::endgroup::"
webpack:
name: WASM Demo
needs: credentials
runs-on: "ubuntu-latest"
env:
GCP_PROJECT_ID: "dev-infra-273822"
GCP_BUCKET_ID: "icu4x-pr-artifacts"
steps:
- uses: actions/checkout@v3
- name: Authenticate to Google Cloud
uses: google-github-actions/setup-gcloud@v0.2
with:
project_id: ${{ env.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.ICU4X_GCP_SA_KEY }}
export_default_credentials: true
- name: Install Node.js v16.18.0
uses: actions/setup-node@v3
with:
node-version: 16.18.0
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- name: Install Rust nightly
run: |
rustup toolchain install nightly-2022-04-05
rustup +nightly-2022-04-05 component add rust-src
- name: Init node package
run: |
cd ffi/diplomat/js/examples/node
make lib
make icu_capi.wasm
# Manually running datagen with the required keys
cargo run -p icu_datagen -- --key-file ../wasm-demo/required-keys.txt --locales full --format blob --out data.postcard
cd ../wasm-demo
npm ci
- name: Run Webpack
run: |
cd ffi/diplomat/js/examples/wasm-demo
npm run build
- name: Put index.html in dist for temp URL
run: |
cp ffi/diplomat/js/examples/wasm-demo/index.html ffi/diplomat/js/examples/wasm-demo/dist/index.html
printf "const gcs=document.createElement('script');gcs.setAttribute('src','./bundle.js');document.body.appendChild(gcs);" > ffi/diplomat/js/examples/wasm-demo/dist/index.js
- name: Upload Webpack bundle to Google Cloud Storage
run: |
# gsutil cors set ffi/diplomat/js/examples/wasm-demo/cors-config-file.json gs://${{ env.GCP_BUCKET_ID }}
gsutil -m cp -r ffi/diplomat/js/examples/wasm-demo/dist/ gs://${{ env.GCP_BUCKET_ID }}/gha/${{ github.sha }}/wasm-demo
- name: "⭐⭐⭐ Links to Uploaded Artifacts ⭐⭐⭐"
run: |
echo "::group::Wasm Demo Preview"
echo "https://storage.googleapis.com/icu4x-pr-artifacts/gha/${{ github.sha }}/wasm-demo/index.html"
echo "::endgroup::"
# TODO(qnnokabayashi): This was my attempt to get it to copy the HTML to
# the `gh-pages` branch. As of 8/1/2022, idea is that
# `index.html` contains the structure for
# the demo. It needs to call into the Webpacked JavaScript. When testing
# locally, this content is in `dist/`, but
# when deployed, it lives in Google Cloud Storage. But we don't want to
# be editing this arbitrarily complex HTML file in CI. The solution was
# to have it call a very simple `index.js` file which modifies the HTML
# and tells it where to get the script from. Locally, this lives next to
# `index.html` at `index.js`, and contains
# the following:
# ```js
# const gcs = document.createElement('script');
# gcs.setAttribute('src', './dist/bundle.js');
# document.body.appendChild(gcs);
# ```
# The plan was to rewrite this file in CI to point into GCS instead of
# `./dist/bundle.js`, and then commit and push the original `index.html`
# and this new `index.js` to the `gh-pages` branch. That way, when a
# browser visited the Github page, `index.html` would read `index.js`,
# which would then point the browser to get `bundle.js` from GCS.
#
# This was my attempt to make that work, but I couldn't quite figure out
# how to push to `gh-pages`.
#
# - name: Store index.html
# run: |
# cp index.html /tmp/wasm-demo-index.html
# - name: Checkout gh-pages
# uses: actions/checkout@v3
# with:
# ref: gh-pages
# - name: Retrieve index.html
# run: |
# rm -rf wasm-demo-app
# mkdir wasm-demo-app
# printf "const gcs=document.createElement('script');gcs.setAttribute('src','https://storage.googleapis.com/icu4x-pr-artifacts/gha/%s/wasm-demo/bundle.js');document.body.appendChild(gcs);" ${{ github.sha }} > wasm-demo-app/index.js
# cp /tmp/wasm-demo-index.html wasm-demo-app/index.html
# git diff-index --quiet HEAD || git commit -m "add wasm demo for ${{ github.sha }}"
# git push