Skip to content

Commit

Permalink
build: bump version to 1.5.2 and update CI/CD for dev/production rele…
Browse files Browse the repository at this point in the history
…ase (#46)

* build: bump version to 1.5.2 and update CI/CD for dev/production release

Signed-off-by: James Chien <james@numbersprotocol.io>

* fix(scripts/deploy-release.sh): avoid bumping version in deploy script
and reuse keys

Signed-off-by: James Chien <james@numbersprotocol.io>

---------

Signed-off-by: James Chien <james@numbersprotocol.io>
  • Loading branch information
shc261392 authored Dec 24, 2024
1 parent e6e0277 commit 904e68a
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 34 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/dev-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Dev Release

on:
push:
branches:
- release-*

jobs:
publish-s3:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Build the project
run: npm run build
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Deploy to S3
run: sh -c scripts/deploy-staging.sh

create-release:
needs: [publish-s3]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create Release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
generate_release_notes: true
name: Release ${{ github.ref_name }}
tag_name: ${{ github.ref_name }}
draft: false
prerelease: true
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
name: Node.js Package

name: Production Release
on:
push:
branches:
- main

jobs:
build:
version-check:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.check.outputs.version }}
changed: ${{ steps.check.outputs.changed }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run build
- name: Check version changes
id: check
uses: EndBug/version-check@v2

publish-github:
needs: build
if: needs.build.outputs.changed == 'true'
needs: version-check
if: needs.version-check.outputs.changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -36,15 +30,18 @@ jobs:
node-version: 20
registry-url: https://npm.pkg.github.com/
scope: '@numbersprotocol'
- run: npm ci
- run: npm run build
- run: npm publish
- name: Install dependencies
run: npm ci
- name: Build the project
run: npm run build
- name: Deploy to GitHub Packages
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish-npm:
needs: build
if: needs.build.outputs.changed == 'true'
needs: version-check
if: needs.version-check.outputs.changed == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -53,39 +50,59 @@ jobs:
node-version: 20
registry-url: 'https://registry.npmjs.org'
scope: '@numbersprotocol'
- run: npm ci
- run: npm run build
- run: npm publish
- name: Install dependencies
run: npm ci
- name: Build the project
run: npm run build
- name: Deploy to NPM registry
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

purge-cdn-cache:
needs: publish-npm
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Send GET request to purge jsdelivr cache
run: |
curl --fail-with-body -X GET "https://purge.jsdelivr.net/npm/@numbersprotocol/capture-eye@latest/dist/capture-eye.bundled.js"
publish-s3:
needs: version-check
if: needs.version-check.outputs.changed == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Build the project
run: npm run build
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Deploy to S3
run: sh -c scripts/deploy-release.sh

create-release:
needs: [build, publish-github, publish-npm]
needs: [version-check, publish-github, publish-npm, publish-s3]
runs-on: ubuntu-latest
if: needs.build.outputs.changed == 'true'
if: needs.version-check.outputs.changed == 'true'
steps:
- uses: actions/checkout@v4
- name: Get changelog
id: changelog
run: |
echo "::set-output name=changes::$(git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:'%h %s')"
- name: Create Release
uses: actions/create-release@v1
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.build.outputs.version }}
release_name: Release ${{ needs.build.outputs.version }}
body: |
Changes:
${{ steps.changelog.outputs.changes }}
name: Release ${{ needs.version-check.outputs.version }}
tag_name: ${{ needs.version-check.outputs.version }}
generate_release_notes: true
draft: false
prerelease: false
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ It includes customizable action buttons for donations, purchases, or licensing,

<p align="center"><img src="https://static-cdn.numbersprotocol.io/capture-eye/overview.webp" /></p>

For more info on Capture Eye, refer to the GitBook [Captue Eye](https://docs.captureapp.xyz/capture-eye) page.
For more info on Capture Eye, refer to the GitBook [Capture Eye](https://docs.captureapp.xyz/capture-eye) page.

## Integration

Please refer to the Capture Eye [Integration](https://docs.captureapp.xyz/capture-eye/installation-and-integration) GitBook page for detailed installation and usage guide.

## Release

For release process, please refer to [RELEASE.md](RELEASE.md).
Empty file added RELEASE.md
Empty file.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@numbersprotocol/capture-eye",
"version": "1.5.1",
"version": "1.5.2",
"description": "Capture Eye widget seamlessly integrates into your website, facilitating secure and transparent provenance display and purchases of digital content directly from the creator",
"main": "dist/capture-eye.js",
"module": "dist/capture-eye.js",
Expand Down
56 changes: 56 additions & 0 deletions scripts/deploy-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

# Variables
DISTRIBUTION_ID="E1GEDS049Y53CA"
FILE_PATH="dist/capture-eye.bundled.js"
S3_BUCKET="numbers-static"

# Define S3 keys for paths
LATEST_KEY="capture-eye/release/latest/capture-eye.bundled.js"
VERSION_KEY="capture-eye/release/$(npm pkg get version | tr -d \")/capture-eye.bundled.js"

# CloudFront invalidation paths
INVALIDATION_PATHS="/$LATEST_KEY /$VERSION_KEY"

echo "Invalidation paths: $INVALIDATION_PATHS"

# Upload to S3 (latest version)
aws s3 cp $FILE_PATH s3://$S3_BUCKET/$LATEST_KEY
if [ $? -ne 0 ]; then
echo "Failed to upload $FILE_PATH to s3://$S3_BUCKET/$LATEST_KEY"
exit 1
fi
echo "File uploaded to s3://$S3_BUCKET/$LATEST_KEY"

# Upload to S3 (version-specific path)
aws s3 cp $FILE_PATH s3://$S3_BUCKET/$VERSION_KEY
if [ $? -ne 0 ]; then
echo "Failed to upload $FILE_PATH to s3://$S3_BUCKET/$VERSION_KEY"
exit 1
fi
echo "File uploaded to s3://$S3_BUCKET/$VERSION_KEY"

# Create the invalidation
INVALIDATION_ID=$(aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths $INVALIDATION_PATHS --query 'Invalidation.Id' --output text)
if [ $? -ne 0 ]; then
echo "Failed to create invalidation"
exit 1
fi
echo "Invalidation created with ID: $INVALIDATION_ID"

# Function to check the status of the invalidation
check_invalidation_status() {
STATUS=$(aws cloudfront get-invalidation --distribution-id $DISTRIBUTION_ID --id $INVALIDATION_ID --query 'Invalidation.Status' --output text)
echo "Current status: $STATUS"
}

# Loop until the invalidation status is "Completed"
while true; do
check_invalidation_status
if [ "$STATUS" = "Completed" ]; then
echo "success/done"
break
fi
# Wait for 5 seconds before checking again
sleep 5
done

0 comments on commit 904e68a

Please sign in to comment.