build(deps): bump dependencies #44
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: Publish Package | |
on: | |
push: | |
branches: | |
- main | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | |
concurrency: | |
group: 'pages' | |
cancel-in-progress: false | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@nightly | |
with: | |
targets: wasm32-unknown-unknown | |
components: rust-src | |
# Add Rust caching | |
- uses: Swatinem/rust-cache@v2 | |
with: | |
shared-key: 'screeps-clockwork' | |
cache-directories: 'dist_lib/target/' | |
- name: Install wasm-pack | |
run: | | |
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh | |
rustup target add wasm32-unknown-unknown | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
registry-url: 'https://registry.npmjs.org' | |
# Add Node dependency caching | |
- name: Cache node modules | |
uses: actions/cache@v3 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Install dependencies | |
run: npm ci | |
# Cache wasm-pack output | |
- name: Cache wasm-pack output | |
uses: actions/cache@v3 | |
with: | |
path: wasm | |
key: ${{ runner.os }}-wasm-${{ hashFiles('lib/**') }} | |
- name: Build | |
run: npm run build | |
- name: Build docs | |
run: npm run build:docs | |
- name: Upload dist folder as artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: dist-artifact | |
path: dist | |
- name: Upload docs folder as artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: docs-artifact | |
path: dist_docs | |
publish-npm: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
registry-url: https://registry.npmjs.org/ | |
- uses: actions/download-artifact@v3 | |
with: | |
name: dist-artifact | |
path: dist | |
- name: Check if version exists | |
id: version-check | |
run: | | |
PACKAGE_VERSION=$(node -p "require('./package.json').version") | |
PACKAGE_NAME=$(node -p "require('./package.json').name") | |
if npm view $PACKAGE_NAME@$PACKAGE_VERSION version &>/dev/null; then | |
echo "Version $PACKAGE_VERSION already exists, skipping publish" | |
echo "exists=true" >> $GITHUB_OUTPUT | |
else | |
echo "Version $PACKAGE_VERSION does not exist, will publish" | |
echo "exists=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Publish to npm | |
if: steps.version-check.outputs.exists == 'false' | |
run: npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
publish-docs: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v3 | |
with: | |
name: docs-artifact | |
path: dist_docs | |
- name: Copy API docs | |
run: cp -r ./dist_docs ./docs/api | |
- name: Setup Pages | |
uses: actions/configure-pages@v5 | |
- name: Build with Jekyll | |
uses: actions/jekyll-build-pages@v1 | |
with: | |
source: ./docs | |
destination: ./_site | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v3 | |
deploy-docs: | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
needs: publish-docs | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 |