diff --git a/.DS_Store b/.DS_Store index ff3f707..c723b8f 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..f91e0d0 --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,217 @@ +name: NPM Publish + +on: + push: + branches: + - main + - master + paths: + - 'djed-sdk/package.json' + - 'stablepay-sdk/package.json' + +jobs: + publish-djed-sdk: + runs-on: ubuntu-latest + timeout-minutes: 15 + defaults: + run: + working-directory: ./djed-sdk + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: '18' + registry-url: 'https://registry.npmjs.org' + + - name: Check version change + id: check + run: | + PACKAGE_NAME=$(node -p "require('./package.json').name") + LOCAL_VERSION=$(node -p "require('./package.json').version") + + echo "Checking registry for $PACKAGE_NAME..." + + # Retry loop for npm view to handle network flakes + PUBLISHED_VERSION="" + for i in {1..3}; do + if OUTPUT=$(npm view "$PACKAGE_NAME" version 2>/dev/null); then + PUBLISHED_VERSION=$OUTPUT + break + else + # Check if it's a 404 (package doesn't exist) + if npm view "$PACKAGE_NAME" version 2>&1 | grep -q "E404"; then + echo "Package not found on registry. Assuming new package." + PUBLISHED_VERSION="0.0.0" + break + fi + + if [ $i -lt 3 ]; then + echo "Attempt $i failed. Retrying in 5 seconds..." + sleep 5 + fi + fi + done + + if [ -z "$PUBLISHED_VERSION" ]; then + echo "Failed to retrieve published version after 3 attempts. Assuming 0.0.0 to err on side of attempting publish." + PUBLISHED_VERSION="0.0.0" + fi + + echo "Local version: $LOCAL_VERSION" + echo "Published version: $PUBLISHED_VERSION" + + if [ "$LOCAL_VERSION" != "$PUBLISHED_VERSION" ]; then + echo "Version changed." + echo "changed=true" >> "$GITHUB_OUTPUT" + else + echo "Version unchanged." + echo "changed=false" >> "$GITHUB_OUTPUT" + fi + + - name: Install dependencies + if: steps.check.outputs.changed == 'true' + run: | + SUCCESS=false + for i in {1..3}; do + if npm ci; then + SUCCESS=true + break + else + echo "Install failed, retrying in 10 seconds..." + sleep 10 + fi + done + if [ "$SUCCESS" != "true" ]; then + echo "Failed to install dependencies after 3 attempts" + exit 1 + fi + + - name: Build + if: steps.check.outputs.changed == 'true' + run: npm run build + + - name: Publish to NPM + if: steps.check.outputs.changed == 'true' + run: | + SUCCESS=false + for i in {1..3}; do + if npm publish; then + SUCCESS=true + break + else + echo "Publish failed, retrying in 10 seconds..." + sleep 10 + fi + done + if [ "$SUCCESS" != "true" ]; then + echo "Failed to publish after 3 attempts" + exit 1 + fi + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + publish-stablepay-sdk: + runs-on: ubuntu-latest + timeout-minutes: 15 + defaults: + run: + working-directory: ./stablepay-sdk + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: '18' + registry-url: 'https://registry.npmjs.org' + + - name: Check version change + id: check + run: | + PACKAGE_NAME=$(node -p "require('./package.json').name") + LOCAL_VERSION=$(node -p "require('./package.json').version") + + echo "Checking registry for $PACKAGE_NAME..." + + PUBLISHED_VERSION="" + for i in {1..3}; do + if OUTPUT=$(npm view "$PACKAGE_NAME" version 2>/dev/null); then + PUBLISHED_VERSION=$OUTPUT + break + else + if npm view "$PACKAGE_NAME" version 2>&1 | grep -q "E404"; then + echo "Package not found on registry. Assuming new package." + PUBLISHED_VERSION="0.0.0" + break + fi + + if [ $i -lt 3 ]; then + echo "Attempt $i failed. Retrying in 5 seconds..." + sleep 5 + fi + fi + done + + if [ -z "$PUBLISHED_VERSION" ]; then + echo "Failed to retrieve published version after 3 attempts. Assuming 0.0.0 to err on side of attempting publish." + PUBLISHED_VERSION="0.0.0" + fi + + echo "Local version: $LOCAL_VERSION" + echo "Published version: $PUBLISHED_VERSION" + + if [ "$LOCAL_VERSION" != "$PUBLISHED_VERSION" ]; then + echo "Version changed." + echo "changed=true" >> "$GITHUB_OUTPUT" + else + echo "Version unchanged." + echo "changed=false" >> "$GITHUB_OUTPUT" + fi + + - name: Install dependencies + if: steps.check.outputs.changed == 'true' + run: | + SUCCESS=false + for i in {1..3}; do + if npm ci; then + SUCCESS=true + break + else + echo "Install failed, retrying in 10 seconds..." + sleep 10 + fi + done + if [ "$SUCCESS" != "true" ]; then + echo "Failed to install dependencies after 3 attempts" + exit 1 + fi + + - name: Build + if: steps.check.outputs.changed == 'true' + run: npm run build + + - name: Publish to NPM + if: steps.check.outputs.changed == 'true' + run: | + SUCCESS=false + for i in {1..3}; do + if npm publish; then + SUCCESS=true + break + else + echo "Publish failed, retrying in 10 seconds..." + sleep 10 + fi + done + if [ "$SUCCESS" != "true" ]; then + echo "Failed to publish after 3 attempts" + exit 1 + fi + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/djed-sdk/package.json b/djed-sdk/package.json index e6bcdfa..c22dcd0 100644 --- a/djed-sdk/package.json +++ b/djed-sdk/package.json @@ -5,6 +5,7 @@ "main": "dist/umd/index.js", "module": "dist/esm/index.js", "scripts": { + "build": "rollup -c", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [],