|
| 1 | +name: SATP Hermes Gateway SDK - GHCR Publish |
| 2 | + |
| 3 | +# ============================================================================= |
| 4 | +# GHCR PUBLISHING WORKFLOW |
| 5 | +# ============================================================================= |
| 6 | +# |
| 7 | +# This workflow publishes the SATP Hermes Gateway SDK to GitHub Container Registry (GHCR) |
| 8 | +# with support for both development and production releases. |
| 9 | +# |
| 10 | +# PACKAGE CONFIGURATION: |
| 11 | +# Organization: @hyperledger |
| 12 | +# Package: @hyperledger/cactus-plugin-satp-hermes |
| 13 | +# Registry: https://ghcr.io/ |
| 14 | +# |
| 15 | +# VERSION STRATEGY: |
| 16 | +# Version Source: package.json customMetadata.satp-package-version (0.0.3-beta) |
| 17 | +# Note: package.json "version" field remains at 2.1.0 for monorepo compatibility. |
| 18 | +# The workflow dynamically updates version from customMetadata before publishing. |
| 19 | +# |
| 20 | +# Development Builds: |
| 21 | +# Format: {base-version}-dev.{timestamp} |
| 22 | +# Example: 0.0.3-beta-dev.20250106120000 |
| 23 | +# GHCR Tag: dev |
| 24 | +# Trigger: Push to main, satp-dev, or satp-stg branches |
| 25 | +# |
| 26 | +# Release Builds: |
| 27 | +# Format: {base-version} or custom version |
| 28 | +# Example: 0.0.3-beta |
| 29 | +# GHCR Tags: latest (primary) + version tag (0.0.3-beta) |
| 30 | +# Trigger: Manual workflow dispatch with is_release=true |
| 31 | +# Note: Production releases are tagged with both 'latest' and the specific version |
| 32 | +# |
| 33 | +# REQUIRED SECRETS: |
| 34 | +# GITHUB_TOKEN: Auto-provided by GitHub Actions for GHCR publishing |
| 35 | +# |
| 36 | +# USAGE: |
| 37 | +# Development Release (Automatic): |
| 38 | +# git push origin main |
| 39 | +# |
| 40 | +# Production Release (Manual): |
| 41 | +# 1. Go to Actions tab |
| 42 | +# 2. Select "SATP Hermes Gateway SDK - GHCR Publish" |
| 43 | +# 3. Click "Run workflow" |
| 44 | +# 4. Set is_release=true |
| 45 | +# 5. Optionally set custom_version |
| 46 | +# |
| 47 | +# VERIFICATION: |
| 48 | +# ghcr.io/hyperledger-cacti/cacti-satp-hermes-gateway |
| 49 | +# |
| 50 | +# ============================================================================= |
| 51 | + |
| 52 | +on: |
| 53 | + workflow_call: |
| 54 | + inputs: |
| 55 | + skip_tests: |
| 56 | + description: 'Skip test execution (for emergency releases only)' |
| 57 | + required: false |
| 58 | + default: false |
| 59 | + type: boolean |
| 60 | + is_release: |
| 61 | + description: 'Create release version using package.json version' |
| 62 | + required: false |
| 63 | + default: false |
| 64 | + type: boolean |
| 65 | + custom_version: |
| 66 | + description: 'Custom version tag (leave empty to use package.json version)' |
| 67 | + required: false |
| 68 | + type: string |
| 69 | + outputs: |
| 70 | + package_version: |
| 71 | + description: "Package version from package.json" |
| 72 | + value: ${{ jobs.set-ghcr-tags.outputs.package_version }} |
| 73 | + tag_suffix: |
| 74 | + description: "Tag suffix (dev or release)" |
| 75 | + value: ${{ jobs.set-ghcr-tags.outputs.tag_suffix }} |
| 76 | + tag_version: |
| 77 | + description: "Full tag version" |
| 78 | + value: ${{ jobs.set-ghcr-tags.outputs.tag_version }} |
| 79 | + ghcr_image: |
| 80 | + description: "GHCR image name" |
| 81 | + value: ${{ jobs.set-ghcr-tags.outputs.ghcr_image }} |
| 82 | + is_release: |
| 83 | + description: "Whether this is a release build" |
| 84 | + value: ${{ jobs.set-ghcr-tags.outputs.is_release }} |
| 85 | + |
| 86 | +permissions: |
| 87 | + contents: read |
| 88 | + packages: write |
| 89 | + id-token: write |
| 90 | + |
| 91 | +jobs: |
| 92 | + # Set GHCR tags based on branch and commit information |
| 93 | + set-ghcr-tags: |
| 94 | + if: | |
| 95 | + always() && ( |
| 96 | + (inputs.skip_tests == true && inputs.is_release == true) || |
| 97 | + (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/satp-dev' || github.ref == 'refs/heads/satp-stg')) || |
| 98 | + (github.event_name == 'pull_request' && (github.base_ref == 'main' || github.base_ref == 'satp-dev' || github.base_ref == 'satp-stg')) || |
| 99 | + github.event_name == 'workflow_dispatch' |
| 100 | + ) |
| 101 | + runs-on: ubuntu-latest-16-cores |
| 102 | + outputs: |
| 103 | + package_version: ${{ steps.set_tags.outputs.package_version }} |
| 104 | + tag_suffix: ${{ steps.set_tags.outputs.tag_suffix }} |
| 105 | + tag_version: ${{ steps.set_tags.outputs.tag_version }} |
| 106 | + ghcr_image: ${{ steps.set_tags.outputs.ghcr_image }} |
| 107 | + is_release: ${{ steps.set_tags.outputs.is_release }} |
| 108 | + steps: |
| 109 | + |
| 110 | + - name: Set image tags |
| 111 | + id: set_tags |
| 112 | + run: | |
| 113 | + PACKAGE_VERSION=$(node -e "console.log(require('./packages/cactus-plugin-satp-hermes/package.json').customMetadata['satp-package-version'])") |
| 114 | + IS_RELEASE="${{ inputs.is_release }}" |
| 115 | + if [ "$IS_RELEASE" = "true" ]; then |
| 116 | + if [ -n "${{ inputs.custom_version }}" ]; then |
| 117 | + TAG_VERSION="${{ inputs.custom_version }}" |
| 118 | + echo "Building release version with custom version: ${{ inputs.custom_version }}" |
| 119 | + else |
| 120 | + TAG_VERSION="${PACKAGE_VERSION}" |
| 121 | + echo "Building release version with satp-package-version: ${PACKAGE_VERSION}" |
| 122 | + fi |
| 123 | + TAG_SUFFIX="release" |
| 124 | + else |
| 125 | + TAG_SUFFIX="dev" |
| 126 | + TAG_VERSION="$(date -u +"%Y-%m-%d")-${TAG_SUFFIX}-$(git rev-parse --short HEAD)" |
| 127 | + echo "Building development version: ${TAG_VERSION}" |
| 128 | + fi |
| 129 | + GHCR_IMAGE="hyperledger-cacti/cacti-satp-hermes-gateway" |
| 130 | + { |
| 131 | + echo "package_version=${PACKAGE_VERSION}" |
| 132 | + echo "tag_suffix=${TAG_SUFFIX}" |
| 133 | + echo "tag_version=${TAG_VERSION}" |
| 134 | + echo "ghcr_image=${GHCR_IMAGE}" |
| 135 | + echo "is_release=${IS_RELEASE:-false}" |
| 136 | + } >> "$GITHUB_OUTPUT" |
| 137 | + - name: Debug Build Info |
| 138 | + run: | |
| 139 | + PACKAGE_VERSION=$(node -e "console.log(require('./packages/cactus-plugin-satp-hermes/package.json').customMetadata['satp-package-version'])") |
| 140 | + { |
| 141 | + echo "Debug: Current ref = ${{ github.ref }}" |
| 142 | + echo "Debug: Event name = ${{ github.event_name }}" |
| 143 | + echo "Debug: GitHub workspace = ${{ github.workspace }}" |
| 144 | + echo "Debug: Repository = ${{ github.repository }}" |
| 145 | + echo "Debug: Building for tag version = ${{ steps.set_tags.outputs.tag_version }}" |
| 146 | + echo "Debug: Building for ghcr image = ${{ steps.set_tags.outputs.ghcr_image }}" |
| 147 | + echo "Debug: Node.js version = v22.18.0" |
| 148 | + echo "Debug: SATP package version = ${PACKAGE_VERSION}" |
| 149 | + echo "Debug: Commit hash = $(git rev-parse --short HEAD)" |
| 150 | + } |
| 151 | +
|
| 152 | + # Build Docker image for GHCR |
| 153 | + build-satp-hermes-ghcr-image: |
| 154 | + needs: [set-ghcr-tags] |
| 155 | + if: (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/satp-dev' || github.ref == 'refs/heads/satp-stg')) || (github.event_name == 'pull_request' && (github.base_ref == 'main' || github.base_ref == 'satp-dev' || github.base_ref == 'satp-stg')) || github.event_name == 'workflow_dispatch' |
| 156 | + runs-on: ubuntu-latest-16-cores |
| 157 | + steps: |
| 158 | + |
| 159 | + - name: Setup Node.js |
| 160 | + uses: actions/setup-node@v4 |
| 161 | + with: |
| 162 | + node-version: '22' |
| 163 | + cache: 'yarn' |
| 164 | + cache-dependency-path: yarn.lock |
| 165 | + - id: yarn-cache |
| 166 | + name: Initialize Yarn Cache |
| 167 | + uses: actions/cache@v4 |
| 168 | + with: |
| 169 | + key: ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }} |
| 170 | + path: ./.yarn/ |
| 171 | + restore-keys: | |
| 172 | + ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }} |
| 173 | + - name: Set working directory |
| 174 | + run: cd packages/cactus-plugin-satp-hermes |
| 175 | + - name: Install Foundry |
| 176 | + uses: foundry-rs/foundry-toolchain@v1 |
| 177 | + with: |
| 178 | + version: stable |
| 179 | + - name: Install dependencies |
| 180 | + run: yarn install --frozen-lockfile |
| 181 | + - name: Configure |
| 182 | + run: yarn configure |
| 183 | + - name: Build bundle |
| 184 | + id: build |
| 185 | + run: | |
| 186 | + yarn lerna run build:bundle --scope=@hyperledger/cactus-plugin-satp-hermes |
| 187 | + echo "success=true" >> "$GITHUB_OUTPUT" |
| 188 | + - name: Set up Docker Buildx |
| 189 | + uses: docker/setup-buildx-action@v3 |
| 190 | + - name: Build Docker image (no push) |
| 191 | + uses: docker/build-push-action@v5 |
| 192 | + with: |
| 193 | + context: ./packages/cactus-plugin-satp-hermes |
| 194 | + file: ./packages/cactus-plugin-satp-hermes/satp-hermes-gateway.Dockerfile |
| 195 | + push: false |
| 196 | + tags: | |
| 197 | + ghcr.io/${{ needs.set-ghcr-tags.outputs.ghcr_image }}:${{ needs.set-ghcr-tags.outputs.tag_version }} |
| 198 | + cache-from: type=gha |
| 199 | + cache-to: type=gha,mode=max |
| 200 | + |
| 201 | + # Publish Docker image to GHCR |
| 202 | + publish-satp-hermes-ghcr-image: |
| 203 | + needs: [build-satp-hermes-ghcr-image, set-ghcr-tags] |
| 204 | + if: (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/satp-dev' || github.ref == 'refs/heads/satp-stg')) || github.event_name == 'workflow_dispatch' |
| 205 | + runs-on: ubuntu-latest-16-cores |
| 206 | + steps: |
| 207 | + |
| 208 | + - name: Setup Node.js |
| 209 | + uses: actions/setup-node@v4 |
| 210 | + with: |
| 211 | + node-version: '22' |
| 212 | + cache: 'yarn' |
| 213 | + cache-dependency-path: yarn.lock |
| 214 | + - name: Install dependencies |
| 215 | + run: yarn install --frozen-lockfile |
| 216 | + - name: Configure |
| 217 | + run: yarn configure |
| 218 | + - name: Build bundle |
| 219 | + id: build |
| 220 | + run: | |
| 221 | + yarn lerna run build:bundle --scope=@hyperledger/cactus-plugin-satp-hermes |
| 222 | + echo "success=true" >> "$GITHUB_OUTPUT" |
| 223 | + - name: Set up Docker Buildx |
| 224 | + uses: docker/setup-buildx-action@v3 |
| 225 | + - name: Login to GitHub Container Registry |
| 226 | + uses: docker/login-action@v3 |
| 227 | + with: |
| 228 | + registry: ghcr.io |
| 229 | + username: ${{ github.actor }} |
| 230 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 231 | + - name: Build and push to GHCR (Release) |
| 232 | + if: needs.set-ghcr-tags.outputs.is_release == 'true' |
| 233 | + uses: docker/build-push-action@v5 |
| 234 | + with: |
| 235 | + context: ./packages/cactus-plugin-satp-hermes |
| 236 | + file: ./packages/cactus-plugin-satp-hermes/satp-hermes-gateway.Dockerfile |
| 237 | + push: true |
| 238 | + tags: | |
| 239 | + ghcr.io/${{ needs.set-ghcr-tags.outputs.ghcr_image }}:${{ needs.set-ghcr-tags.outputs.tag_version }} |
| 240 | + ghcr.io/${{ needs.set-ghcr-tags.outputs.ghcr_image }}:latest |
| 241 | + cache-from: type=gha |
| 242 | + cache-to: type=gha,mode=max |
| 243 | + - name: Build and push to GHCR (Development) |
| 244 | + if: needs.set-ghcr-tags.outputs.is_release != 'true' |
| 245 | + uses: docker/build-push-action@v5 |
| 246 | + with: |
| 247 | + context: ./packages/cactus-plugin-satp-hermes |
| 248 | + file: ./packages/cactus-plugin-satp-hermes/satp-hermes-gateway.Dockerfile |
| 249 | + push: true |
| 250 | + tags: | |
| 251 | + ghcr.io/${{ needs.set-ghcr-tags.outputs.ghcr_image }}:${{ needs.set-ghcr-tags.outputs.tag_version }} |
| 252 | + cache-from: type=gha |
| 253 | + cache-to: type=gha,mode=max |
0 commit comments