Publish CI #285
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 CI | |
on: | |
workflow_run: | |
workflows: [ "Test CI" ] | |
branches: [ main ] | |
types: [ completed ] | |
jobs: | |
build_and_upload_artifacts: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '18.x' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Install dependencies | |
run: yarn | |
- name: Build | |
run: yarn build | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dist-artifacts | |
path: | | |
packages/core/dist | |
packages/ui/dist | |
packages/nodejs/dist | |
packages/hjson/dist | |
publish_hjson: | |
needs: build_and_upload_artifacts | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '18.x' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: dist-artifacts | |
path: packages | |
- name: Check Test CI status | |
if: > | |
github.event.workflow_run.conclusion == 'failure' || | |
github.event.workflow_run.conclusion == 'cancelled' | |
run: | | |
echo "The 'Test CI' workflow is ${{ github.event.workflow_run.conclusion }}." | |
exit 1 # Exit with a failure | |
- name: Check version | |
id: check | |
run: | | |
PACKAGE_VERSION=$(node -p -e "require('./packages/hjson/package.json').version") | |
echo "Version: $PACKAGE_VERSION" | |
HTTP_STATUS=$(curl --silent --head --write-out "%{http_code}" --output /dev/null https://registry.npmjs.org/@data-story/hjson/$PACKAGE_VERSION) | |
if [ $HTTP_STATUS -eq 200 ]; then | |
echo "Version $PACKAGE_VERSION already exists. Exiting the action script." | |
echo "VERSION_EXISTS=true" >> $GITHUB_ENV | |
else | |
echo "Version does not exist." | |
echo "VERSION_EXISTS=false" >> $GITHUB_ENV | |
fi | |
- name: Publish | |
if: ${{ env.VERSION_EXISTS == 'false' }} | |
run: | | |
yarn config set -H npmScopes.data-story.npmPublishRegistry "https://registry.npmjs.org/" | |
yarn config set -H npmScopes.data-story.npmAuthToken "${{ secrets.NPM_DATA_STORY }}" | |
cd packages/hjson && yarn npm publish --access public | |
publish_core: | |
needs: build_and_upload_artifacts | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '18.x' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: dist-artifacts | |
path: packages | |
- name: Check Test CI status | |
if: > | |
github.event.workflow_run.conclusion == 'failure' || | |
github.event.workflow_run.conclusion == 'cancelled' | |
run: | | |
echo "The 'Test CI' workflow is ${{ github.event.workflow_run.conclusion }}." | |
exit 1 # Exit with a failure | |
- name: Check version | |
id: check | |
run: | | |
PACKAGE_VERSION=$(node -p -e "require('./packages/core/package.json').version") | |
echo "Version: $PACKAGE_VERSION" | |
HTTP_STATUS=$(curl --silent --head --write-out "%{http_code}" --output /dev/null https://registry.npmjs.org/@data-story/core/$PACKAGE_VERSION) | |
if [ $HTTP_STATUS -eq 200 ]; then | |
echo "Version $PACKAGE_VERSION already exists. Exiting the action script." | |
echo "VERSION_EXISTS=true" >> $GITHUB_ENV | |
else | |
echo "Version does not exist." | |
echo "VERSION_EXISTS=false" >> $GITHUB_ENV | |
fi | |
- name: Publish | |
if: ${{ env.VERSION_EXISTS == 'false' }} | |
run: | | |
yarn config set -H npmScopes.data-story.npmPublishRegistry "https://registry.npmjs.org/" | |
yarn config set -H npmScopes.data-story.npmAuthToken "${{ secrets.NPM_DATA_STORY }}" | |
cd packages/core && yarn npm publish --access public | |
publish_ui: | |
needs: publish_core | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '18.x' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: dist-artifacts | |
path: packages | |
- name: Check version | |
id: check | |
run: | | |
PACKAGE_VERSION=$(node -p -e "require('./packages/ui/package.json').version") | |
echo "Version: $PACKAGE_VERSION" | |
HTTP_STATUS=$(curl --silent --head --write-out "%{http_code}" --output /dev/null https://registry.npmjs.org/@data-story/ui/$PACKAGE_VERSION) | |
if [ $HTTP_STATUS -eq 200 ]; then | |
echo "Version $PACKAGE_VERSION already exists. Exiting the action script." | |
echo "VERSION_EXISTS=true" >> $GITHUB_ENV | |
else | |
echo "Version does not exist." | |
echo "VERSION_EXISTS=false" >> $GITHUB_ENV | |
fi | |
- name: Publish | |
if: ${{ env.VERSION_EXISTS == 'false' }} | |
run: | | |
yarn config set -H npmScopes.data-story.npmPublishRegistry "https://registry.npmjs.org/" | |
yarn config set -H npmScopes.data-story.npmAuthToken "${{ secrets.NPM_DATA_STORY }}" | |
cd packages/ui && yarn npm publish --access public | |
publish_nodejs: | |
needs: publish_core | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '18.x' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: dist-artifacts | |
path: packages | |
- name: Check version | |
id: check | |
run: | | |
PACKAGE_VERSION=$(node -p -e "require('./packages/nodejs/package.json').version") | |
echo "Version: $PACKAGE_VERSION" | |
HTTP_STATUS=$(curl --silent --head --write-out "%{http_code}" --output /dev/null https://registry.npmjs.org/@data-story/nodejs/$PACKAGE_VERSION) | |
if [ $HTTP_STATUS -eq 200 ]; then | |
echo "Version $PACKAGE_VERSION already exists. Exiting the action script." | |
echo "VERSION_EXISTS=true" >> $GITHUB_ENV | |
else | |
echo "Version does not exist." | |
echo "VERSION_EXISTS=false" >> $GITHUB_ENV | |
fi | |
- name: Publish | |
if: ${{ env.VERSION_EXISTS == 'false' }} | |
run: | | |
yarn config set -H npmScopes.data-story.npmPublishRegistry "https://registry.npmjs.org/" | |
yarn config set -H npmScopes.data-story.npmAuthToken "${{ secrets.NPM_DATA_STORY }}" | |
cd packages/nodejs && yarn npm publish --access public |