Publish CI #431
This file contains hidden or 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: | |
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: '21.x' | |
registry-url: 'https://registry.npmjs.org' | |
- 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: Download dist artifacts from Test CI | |
uses: actions/download-artifact@v4 | |
with: | |
name: dist-artifacts | |
path: packages | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
repository: ${{ github.repository }} | |
run-id: ${{ github.event.workflow_run.id }} | |
- 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: '21.x' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Download dist artifacts from Test CI | |
uses: actions/download-artifact@v4 | |
with: | |
name: dist-artifacts | |
path: packages | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
repository: ${{ github.repository }} | |
run-id: ${{ github.event.workflow_run.id }} | |
- 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: '21.x' | |
registry-url: 'https://registry.npmjs.org' | |
- 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: '21.x' | |
- name: Install vsce | |
run: npm install -g @vscode/[email protected] | |
- name: Check VS Code extension version | |
id: check_vscode | |
run: | | |
# get local version | |
LOCAL_VERSION=$(node -p "require('./packages/ds-ext/package.json').version") | |
echo "Local Version: $LOCAL_VERSION" | |
# query online latest version | |
RESPONSE=$(curl -s -X POST \ | |
-H "Content-Type: application/json" \ | |
-H "Accept: application/json;api-version=3.0-preview" \ | |
-d '{"filters":[{"criteria":[{"filterType":7,"value":"ajthinking.ds-ext"}]}],"flags":914}' \ | |
"https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery") | |
# parse online version | |
ONLINE_VERSION=$(echo $RESPONSE | jq -r '.results[0].extensions[0].versions[0].version') | |
echo "Online Version: $ONLINE_VERSION" | |
# version comparison logic | |
if [ "$LOCAL_VERSION" = "$ONLINE_VERSION" ]; then | |
echo "::warning::Version $LOCAL_VERSION already exists. Skipping build and publish." | |
echo "VERSION_EXISTS=true" >> $GITHUB_ENV | |
else | |
echo "::notice::New version detected. Proceeding to build and publish." | |
echo "VERSION_EXISTS=false" >> $GITHUB_ENV | |
fi | |
# add error handling (continue publishing when API is unavailable) | |
continue-on-error: true | |
- name: Install dependencies | |
if: env.VERSION_EXISTS == 'false' | |
run: | | |
# cd packages/ds-ext | |
yarn install --frozen-lockfile | |
- name: Build VS Code Extension | |
if: env.VERSION_EXISTS == 'false' | |
run: | | |
# cd packages/ds-ext | |
yarn build | |
- name: Publish VS Code Extension | |
if: env.VERSION_EXISTS == 'false' | |
run: | | |
cd packages/ds-ext | |
vsce package --no-yarn --skip-license | |
vsce publish --pat ${{ secrets.AZURE_ACCESS_TOKEN }} --no-yarn |