Skip to content

fix(ci): strip dev- #69

fix(ci): strip dev-

fix(ci): strip dev- #69

name: Sync and Publish
on:
repository_dispatch:
types:
- sync_trigger
push:
branches:
- main
- '**' # Match any branch
jobs:
sync-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Set environment variables
run: echo "Setting environment variables based on branch"
env:
BRANCH_NAME: ${{ github.ref_name }}
DEV_BRANCH: ${{ steps.set-env.outputs.DEV_BRANCH }}
shell: bash
# Production
- name: Set environment variable for main branch
if: github.ref == 'refs/heads/main'
run: echo "DEV_BRANCH=production_value" >> $GITHUB_ENV
# Development - All other branches start with `dev-` prefixes
- name: Set environment variable for dev branches
if: startsWith(github.ref, 'refs/heads/dev-')
run: |
BRANCH_NAME=${GITHUB_REF#refs/heads/}
BRANCH_NAME=${BRANCH_NAME#dev-}
DEV_BRANCH_NAME=${BRANCH_NAME#dev-}
echo "DEV_BRANCH=$DEV_BRANCH_NAME" >> $GITHUB_ENV
- name: Display environment variable
run: echo "DEV_BRANCH is $DEV_BRANCH"
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "16"
- name: Install bun
run: curl -fsSL https://bun.sh/install | bash
- name: Add bun to path
run: echo 'export BUN_INSTALL="$HOME/.bun"' >> $GITHUB_ENV
shell: bash
- name: Install dependencies
run: $HOME/.bun/bin/bun install
# prod (stable) - gets data from /networks
- name: Run (prod) fetch-contracts.ts
env:
LIT_ABI_SOURCE: prod
GH_LIT_ASSETS_READ_ONLY_API: ${{ secrets.GH_LIT_ASSETS_READ_ONLY_API }}
run: $HOME/.bun/bin/bun run fetch-contracts.ts
# dev (always updating) - gets data from /lit-assets
- name: Run (dev) fetch-contracts.ts
env:
LIT_ABI_SOURCE: dev
GH_LIT_ASSETS_READ_ONLY_API: ${{ secrets.GH_LIT_ASSETS_READ_ONLY_API }}
run: $HOME/.bun/bin/bun run fetch-contracts.ts
- name: Run general-exports.ts
run: $HOME/.bun/bin/bun run generate-exports.mjs
- name: Commit and push changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "feat: Update contracts data" || echo "No changes to commit"
git push origin ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Bump version
run: npm version patch
- name: Commit and push version bump
run: |
git add package.json
git commit -m "chore: bump version" || echo "No version bump to commit"
git push origin ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Publish npm package
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
BRANCH_NAME=${GITHUB_REF##*/}
echo "Branch name: $BRANCH_NAME"
if [[ "$BRANCH_NAME" == "main" ]]; then
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
npm publish --access public --tag latest
else
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
npm publish --access public --tag $BRANCH_NAME
fi