Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added gpr publish workflow to release.yml
  • Loading branch information
FarhanAnjum-opti committed Mar 10, 2025
commit c17fe5071f18755ba1dd48ec0cc467448f3fb085
141 changes: 141 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
name: Publish SDK to NPM and GPR

on:
release:
types: [published, edited]
workflow_dispatch: {}

jobs:
publish_to_npm:
name: Publish to NPM
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' || !github.event.release.draft }}
steps:
- name: Checkout branch
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: "https://registry.npmjs.org/"
always-auth: "true"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

- name: Install dependencies
run: npm install

- id: latest-release
name: Export latest release git tag
run: |
echo "latest-release-tag=$(curl -qsSL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases/latest" \
| jq -r .tag_name)" >> $GITHUB_OUTPUT

- id: npm-tag
name: Determine NPM tag
env:
GITHUB_RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
VERSION=$(jq -r '.version' package.json)
LATEST_RELEASE_TAG="${{ steps.latest-release.outputs['latest-release-tag']}}"

if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
RELEASE_TAG=${GITHUB_REF#refs/tags/}
else
RELEASE_TAG=$GITHUB_RELEASE_TAG
fi

if [[ $RELEASE_TAG == $LATEST_RELEASE_TAG ]]; then
echo "npm-tag=latest" >> "$GITHUB_OUTPUT"
elif [[ "$VERSION" == *"-beta"* ]]; then
echo "npm-tag=beta" >> "$GITHUB_OUTPUT"
elif [[ "$VERSION" == *"-alpha"* ]]; then
echo "npm-tag=alpha" >> "$GITHUB_OUTPUT"
elif [[ "$VERSION" == *"-rc"* ]]; then
echo "npm-tag=rc" >> "$GITHUB_OUTPUT"
else
echo "npm-tag=v$(echo $VERSION | awk -F. '{print $1}')-latest" >> "$GITHUB_OUTPUT"
fi

- id: release
name: Test, build and publish to npm
env:
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
run: |
if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
DRY_RUN="--dry-run"
fi
npm publish --tag=${{ steps.npm-tag.outputs['npm-tag'] }} $DRY_RUN

publish_to_gpr:
name: Publish to GitHub Package Registry
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' || !github.event.release.draft }}
steps:
- name: Checkout branch
uses: actions/checkout@v4

- name: Setup Node.js for GPR
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: 'https://npm.pkg.github.com/'
always-auth: true
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
run: npm install

- id: latest-release
name: Export latest release git tag
run: |
echo "latest-release-tag=$(curl -qsSL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases/latest" \
| jq -r .tag_name)" >> $GITHUB_OUTPUT

- id: npm-tag
name: Determine NPM tag
env:
GITHUB_RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
VERSION=$(jq -r '.version' package.json)
LATEST_RELEASE_TAG="${{ steps.latest-release.outputs['latest-release-tag']}}"

if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
RELEASE_TAG=${GITHUB_REF#refs/tags/}
else
RELEASE_TAG=$GITHUB_RELEASE_TAG
fi

if [[ $RELEASE_TAG == $LATEST_RELEASE_TAG ]]; then
echo "npm-tag=latest" >> "$GITHUB_OUTPUT"
elif [[ "$VERSION" == *"-beta"* ]]; then
echo "npm-tag=beta" >> "$GITHUB_OUTPUT"
elif [[ "$VERSION" == *"-alpha"* ]]; then
echo "npm-tag=alpha" >> "$GITHUB_OUTPUT"
elif [[ "$VERSION" == *"-rc"* ]]; then
echo "npm-tag=rc" >> "$GITHUB_OUTPUT"
else
echo "npm-tag=v$(echo $VERSION | awk -F. '{print $1}')-latest" >> "$GITHUB_OUTPUT"
fi

- id: release
name: Test, build and publish to gpr
env:
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
DRY_RUN="--dry-run"
fi
npm publish --tag=${{ steps.npm-tag.outputs['npm-tag'] }} --registry=https://npm.pkg.github.com/ $DRY_RUN
74 changes: 0 additions & 74 deletions .github/workflows/release_gpr.yml

This file was deleted.

81 changes: 0 additions & 81 deletions .github/workflows/release_npm.yml

This file was deleted.

Loading