Merge pull request #19 from TextureHQ/victor/add-cachedMetadata #52
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 to npm | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
test-and-publish: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '20' | |
- name: Install dependencies | |
run: yarn install | |
- name: Install jq | |
run: sudo apt-get install -y jq | |
- name: Run tests | |
run: yarn test | |
- name: Build it | |
run: yarn build | |
- name: Get current version | |
id: get_version | |
run: echo "version=$(jq -r .version package.json)" >> $GITHUB_ENV | |
- name: Check if version is published | |
id: version_check | |
run: | | |
PUBLISHED_VERSIONS=$(yarn info . versions --json | jq -r '.data') | |
CURRENT_VERSION=$(jq -r .version package.json) | |
if echo "$PUBLISHED_VERSIONS" | jq -e ". | index(\"$CURRENT_VERSION\")" > /dev/null; then | |
echo "Version $CURRENT_VERSION is already published." | |
exit 0 | |
else | |
echo "Version $CURRENT_VERSION is new and will be published." | |
echo "new_version=true" >> $GITHUB_ENV | |
fi | |
- name: Configure npm for authentication | |
if: env.new_version == 'true' | |
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
- name: Publish to npm | |
if: env.new_version == 'true' | |
run: yarn publish |