Skip to content

Publish Swift Package #2

Publish Swift Package

Publish Swift Package #2

Workflow file for this run

name: Publish Swift Package
permissions:
contents: read
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: 'Existing release tag (e.g. v1.2.3)'
required: true
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Derive release version
run: |
if [ "${{ github.event_name }}" = "release" ]; then
TAG='${{ github.event.release.tag_name }}'
else
TAG='${{ inputs.tag }}'
fi
echo "RELEASE_TAG=$TAG" >> "$GITHUB_ENV"
echo "RELEASE_VERSION=${TAG#v}" >> "$GITHUB_ENV"
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
# DRY-RUN BRANCH ONLY: build a manual dispatch from the ref it was run on
# (so we can publish a version without a pre-existing monorepo tag).
ref: ${{ github.event_name == 'release' && github.event.release.tag_name || github.sha }}
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: '.nvmrc'
package-manager-cache: false
- uses: pnpm/action-setup@903f9c1a6ebcba6cf41d87230be49611ac97822e # v6.0.3
- run: pnpm install --prefer-offline --frozen-lockfile
- name: Build the JS bridge (stamps the version into the UMD)
run: pnpm --filter @contentful/optimization-js-bridge build
env:
RELEASE_VERSION: ${{ env.RELEASE_VERSION }}
- name: Assemble the package payload
run: |
SRC=packages/ios/ContentfulOptimization
DST="$RUNNER_TEMP/pkg"
mkdir -p "$DST"
# Swift sources, Package.swift, README, LICENSE — but not the UMD (built below).
# Polyfills are bundled into the UMD now, so there is no separate polyfills dir.
rsync -a --exclude='Resources/optimization-ios-bridge.umd.js' "$SRC"/ "$DST"/
cp packages/universal/optimization-js-bridge/dist/optimization-ios-bridge.umd.js \
"$DST/Sources/ContentfulOptimization/Resources/"
- name: Verify the payload is complete
run: |
test -f "$RUNNER_TEMP/pkg/Package.swift"
test -f "$RUNNER_TEMP/pkg/Sources/ContentfulOptimization/Resources/optimization-ios-bridge.umd.js"
- name: Set up the deploy key for SSH push
env:
MIRROR_DEPLOY_KEY: ${{ secrets.SPM_MIRROR_DEPLOY_KEY }}
run: |
mkdir -p ~/.ssh
printf '%s\n' "$MIRROR_DEPLOY_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan github.com >> ~/.ssh/known_hosts 2>/dev/null
- name: Commit, tag, and push to the distribution repo
run: |
git clone --depth 1 git@github.com:contentful/optimization.swift.git mirror
# --delete so files removed in the monorepo also disappear from the mirror
rsync -a --delete --exclude='.git' "$RUNNER_TEMP/pkg"/ mirror/
cd mirror
git add -A
if git diff --cached --quiet; then
echo "No content changes since the last release commit; moving the tag only."
else
git -c user.name='contentful-ci' -c user.email='ci@contentful.com' \
commit -m "Release $RELEASE_TAG (from contentful/optimization@${GITHUB_SHA:0:7})"
git push origin HEAD:main
fi
git tag --force "$RELEASE_TAG"
git push origin "refs/tags/$RELEASE_TAG" --force