|
| 1 | +name: Deploy example app to Capgo |
| 2 | + |
| 3 | +concurrency: |
| 4 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 5 | + cancel-in-progress: true |
| 6 | + |
| 7 | +on: |
| 8 | + release: |
| 9 | + types: [published] |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + channel: |
| 13 | + description: 'Capgo channel' |
| 14 | + required: false |
| 15 | + default: 'production' |
| 16 | + comment: |
| 17 | + description: 'Optional release comment' |
| 18 | + required: false |
| 19 | +permissions: |
| 20 | + contents: read |
| 21 | + |
| 22 | +jobs: |
| 23 | + deploy: |
| 24 | + if: ${{ github.event_name != 'release' || !github.event.release.prerelease }} |
| 25 | + name: Deploy example app to Capgo |
| 26 | + runs-on: ubuntu-latest |
| 27 | + timeout-minutes: 10 |
| 28 | + steps: |
| 29 | + - name: Checkout |
| 30 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd |
| 31 | + with: |
| 32 | + ref: ${{ github.event.release.tag_name || github.ref }} |
| 33 | + fetch-depth: 1 |
| 34 | + filter: blob:none |
| 35 | + persist-credentials: false |
| 36 | + |
| 37 | + - name: Setup bun |
| 38 | + uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 |
| 39 | + with: |
| 40 | + bun-version: 1.3.11 |
| 41 | + no-cache: true |
| 42 | + |
| 43 | + - name: Install plugin dependencies |
| 44 | + run: bun install --frozen-lockfile |
| 45 | + |
| 46 | + - name: Build plugin |
| 47 | + run: bun run build |
| 48 | + |
| 49 | + - name: Install example dependencies |
| 50 | + working-directory: example-app |
| 51 | + run: bun install --frozen-lockfile |
| 52 | + |
| 53 | + - name: Build example app |
| 54 | + working-directory: example-app |
| 55 | + run: bun run build |
| 56 | + |
| 57 | + - name: Resolve Capgo upload metadata |
| 58 | + id: upload |
| 59 | + shell: bash |
| 60 | + env: |
| 61 | + INPUT_CHANNEL: ${{ github.event.inputs.channel }} |
| 62 | + INPUT_COMMENT: ${{ github.event.inputs.comment }} |
| 63 | + RELEASE_TAG: ${{ github.event.release.tag_name }} |
| 64 | + run: | |
| 65 | + set -euo pipefail |
| 66 | +
|
| 67 | + channel="${INPUT_CHANNEL:-}" |
| 68 | + comment="${INPUT_COMMENT:-}" |
| 69 | + release_tag="${RELEASE_TAG:-}" |
| 70 | + repo_name="${GITHUB_REPOSITORY##*/}" |
| 71 | + base_bundle="$(bun -e "const fs = require('fs'); const root = JSON.parse(fs.readFileSync('package.json', 'utf8')); const example = JSON.parse(fs.readFileSync('example-app/package.json', 'utf8')); const version = [example.version, root.version].find((value) => value && value !== '0.0.0'); console.log(version || '');")" |
| 72 | +
|
| 73 | + next_bundle_version() { |
| 74 | + bun -e 'const base = process.argv[1]; const run = Number(process.argv[2] || 0); const match = base.match(/^(\d+)\.(\d+)\.(\d+)/); if (!match) { console.log(base); process.exit(0); } const [, major, minor, patch] = match; console.log(`${major}.${minor}.${Number(patch) + Math.max(run, 1)}`);' "$1" "${GITHUB_RUN_NUMBER:-0}" |
| 75 | + } |
| 76 | + if [[ -n "$base_bundle" ]]; then |
| 77 | + bundle="$(next_bundle_version "$base_bundle")" |
| 78 | + elif [[ -n "$release_tag" ]]; then |
| 79 | + bundle="${release_tag#v}" |
| 80 | + else |
| 81 | + bundle="${repo_name}-${GITHUB_RUN_NUMBER:-manual}" |
| 82 | + fi |
| 83 | +
|
| 84 | + if [[ -z "$channel" ]]; then |
| 85 | + channel="production" |
| 86 | + fi |
| 87 | +
|
| 88 | + if [[ -z "$comment" ]]; then |
| 89 | + if [[ -n "$release_tag" ]]; then |
| 90 | + comment="${repo_name} example ${release_tag}" |
| 91 | + else |
| 92 | + comment="${repo_name} example ${GITHUB_RUN_NUMBER:-manual}" |
| 93 | + fi |
| 94 | + fi |
| 95 | +
|
| 96 | + { |
| 97 | + echo "channel=$channel" |
| 98 | + echo "bundle=$bundle" |
| 99 | + echo "comment<<__CAPGO_COMMENT__" |
| 100 | + echo "$comment" |
| 101 | + echo "__CAPGO_COMMENT__" |
| 102 | + } >> "$GITHUB_OUTPUT" |
| 103 | +
|
| 104 | + - name: Validate Capgo token |
| 105 | + env: |
| 106 | + CAPGO_TOKEN: ${{ secrets.CAPGO_TOKEN }} |
| 107 | + run: | |
| 108 | + if [ -z "$CAPGO_TOKEN" ]; then |
| 109 | + echo "::error::CAPGO_TOKEN org secret is not available to this workflow" |
| 110 | + exit 1 |
| 111 | + fi |
| 112 | +
|
| 113 | + - name: Deploy to Capgo |
| 114 | + run: bun scripts/deploy-example-capgo.mjs |
| 115 | + env: |
| 116 | + CAPGO_TOKEN: ${{ secrets.CAPGO_TOKEN }} |
| 117 | + CAPGO_CHANNEL: ${{ steps.upload.outputs.channel }} |
| 118 | + CAPGO_BUNDLE: ${{ steps.upload.outputs.bundle }} |
| 119 | + CAPGO_COMMENT: ${{ steps.upload.outputs.comment }} |
0 commit comments