Skip to content

chore: Update package versions #50

chore: Update package versions

chore: Update package versions #50

Workflow file for this run

name: Develop CD
on:
pull_request:
types: [ closed ]
branches:
- develop
env:
REGISTRY: ghcr.io
IMAGE_NAME: usermaven-js-stage
DOCKERFILE_PATH: packages/javascript-sdk/docker/Dockerfile
jobs:
build:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
permissions:
contents: read
packages: write
outputs:
rc_version: ${{ steps.rc_version.outputs.RC_VERSION }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
always-auth: true
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install pnpm
run: npm install -g pnpm
- name: Install dependencies
run: pnpm install
- name: Install npm-cli-login
run: npm install -g npm-cli-login
- name: add pnpm typescript
run: pnpm add typescript@latest -w
- name: Build project
run: pnpm build
- name: Generate RC version
id: rc_version
run: |
LATEST_TAG=$(git describe --tags --abbrev=0 --match "[0-9]*.[0-9]*.[0-9]*" 2>/dev/null || echo "0.0.0")
IFS='.' read -r -a version_parts <<< "$LATEST_TAG"
MAJOR="${version_parts[0]}"
MINOR="${version_parts[1]}"
PATCH="${version_parts[2]}"
NEW_PATCH=$((PATCH + 1))
RC_VERSION="$MAJOR.$MINOR.$NEW_PATCH-rc.${{ github.run_number }}"
echo "RC_VERSION=${RC_VERSION}" >> $GITHUB_OUTPUT
- name: Update package versions and dependencies
run: |
RC_VERSION="${{ steps.rc_version.outputs.RC_VERSION }}"
# Update versions in all packages recursively
pnpm version $RC_VERSION --no-git-tag-version --recursive
# Replace "workspace:*" with the actual version in all package.json files
find packages -name 'package.json' -print0 | xargs -0 sed -i "s/\"workspace:\*\"/\"$RC_VERSION\"/g"
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: packages
path: packages/*
retention-days: 1
publish-sdk:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install pnpm
run: npm install -g pnpm
- name: Download build artifacts
uses: actions/download-artifact@v3
with:
name: packages
path: .
- name: Install dependencies
run: pnpm install --no-frozen-lockfile
- name: Publish SDK
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
NPM_CONFIG_PROVENANCE: false
run: |
cd packages/javascript-sdk
pnpm publish --no-git-checks --tag rc --access public
publish-nextjs:
needs: publish-sdk
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install pnpm
run: npm install -g pnpm
- name: Download build artifacts
uses: actions/download-artifact@v3
with:
name: packages
path: .
- name: Publish NextJS package
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
NPM_CONFIG_PROVENANCE: false
run: |
cd packages/nextjs
pnpm publish --no-git-checks --tag rc --access public
publish-react:
needs: publish-sdk
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install pnpm
run: npm install -g pnpm
- name: Download build artifacts
uses: actions/download-artifact@v3
with:
name: packages
path: .
- name: Publish React package
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
NPM_CONFIG_PROVENANCE: false
run: |
cd packages/react
pnpm publish --no-git-checks --tag rc --access public
deploy-cdn:
needs: publish-sdk
runs-on: ubuntu-latest
steps:
- name: Download build artifacts
uses: actions/download-artifact@v3
with:
name: packages
path: .
- name: Deploy to BunnyCDN
uses: ayeressian/[email protected]
with:
source: "packages/javascript-sdk/dist"
destination: ""
storageZoneName: "${{ secrets.BCDN_STAGE_STORAGE_NAME }}"
storagePassword: "${{ secrets.BCDN_STAGE_STORAGE_PASSWORD }}"
accessKey: "${{ secrets.BCDN_STAGE_ACCESS_KEY }}"
pullZoneId: "${{ secrets.BCDN_STAGE_ZONE_ID }}"
upload: "true"
remove: "true"
purgePullZone: "true"
dev-publish-docker:
needs: publish-sdk
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
attestations: write
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.PAT }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Download build artifacts
uses: actions/download-artifact@v3
with:
name: packages
path: .
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ${{ env.DOCKERFILE_PATH }}
push: true
tags: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
labels: ${{ steps.meta.outputs.labels }}
update-k8s-manifest:
needs: dev-publish-docker
runs-on: ubuntu-latest
steps:
- name: Checkout kubernetes manifests repository
uses: actions/checkout@v4
with:
repository: usermaven/kubernetes-manifests-staging
token: ${{ secrets.PAT }}
- name: Update Kubernetes deployment
run: |
sed -i 's|image: .*|image: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ github.sha }}|' usermaven-js/usermaven-js-deployment.yaml
- name: Commit and push changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add usermaven-js/usermaven-js-deployment.yaml
git commit -m "Update image to ${{ github.sha }}"
git push