Skip to content

Publish CI

Publish CI #309

Workflow file for this run

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
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
publish_vscode_extension:
needs: [publish_ui, publish_nodejs]
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'
- name: Install vsce
run: npm install -g vsce
- name: Check VS Code extension version
id: check_vscode
run: |
PACKAGE_VERSION=$(node -p "require('./packages/vscode-extension/package.json').version")
echo "Version: $PACKAGE_VERSION"
HTTP_STATUS=$(curl -X POST \
-H "Accept: */*;api-version=7.2-preview.1;excludeUrls=true" \
-H "Accept-Encoding: gzip, deflate, br, zstd" \
-H "Accept-Language: en-GB,en-US;q=0.9,en;q=0.8,sv;q=0.7" \
-H "Content-Length: 0" \
-o /dev/null \
-w "%{http_code}" \
--silent \
"https://marketplace.visualstudio.com/_apis/public/gallery/publishers/ajthinking/extensions/ds-ext/$PACKAGE_VERSION/stats?statType=pageview")
if [ "$HTTP_STATUS" -eq 200 ]; then
echo "Version $PACKAGE_VERSION already exists. Skipping build and publish."
echo "VERSION_EXISTS=true" >> $GITHUB_ENV
else
echo "Version does not exist. Proceeding to build and publish."
echo "VERSION_EXISTS=false" >> $GITHUB_ENV
fi
- name: Install dependencies
if: env.VERSION_EXISTS == 'false'
run: |
cd packages/vscode-extension
yarn install --frozen-lockfile
- name: Build VS Code Extension
if: env.VERSION_EXISTS == 'false'
run: |
cd packages/vscode-extension
yarn build
- name: Publish VS Code Extension
if: env.VERSION_EXISTS == 'false'
run: |
cd packages/vscode-extension
vsce publish --pat ${{ secrets.VSCE_TOKEN }} --yarn