mirror of
https://github.com/videojs/video.js.git
synced 2026-11-20 06:29:27 +01:00
229 lines
9.7 KiB
YAML
229 lines
9.7 KiB
YAML
name: Deployment
|
|
|
|
concurrency: production
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
# An empty version re-runs release-please after a missing tag is restored.
|
|
# A version resumes an existing release whose publication failed partway.
|
|
workflow_dispatch:
|
|
inputs:
|
|
recover_version:
|
|
description: 'Existing release version to finish publishing (for example, 10.0.1); leave empty to run release-please'
|
|
required: false
|
|
type: string
|
|
|
|
jobs:
|
|
release:
|
|
# npm trusted publishing requires a GitHub-hosted runner.
|
|
# https://docs.npmjs.com/trusted-publishers/
|
|
runs-on: ubuntu-latest
|
|
environment: production
|
|
permissions:
|
|
contents: write
|
|
pull-requests: write
|
|
id-token: write
|
|
|
|
steps:
|
|
# release-please needs a token other than GITHUB_TOKEN so the release
|
|
# branch push, the release PR, and the published releases still trigger
|
|
# release-pr.yml, CI, and changelog-prose.yml
|
|
# (see https://github.com/peter-evans/create-pull-request/issues/48).
|
|
# A GitHub App installation token attributes the release PRs and tags to
|
|
# the app's bot user rather than a maintainer.
|
|
- uses: actions/create-github-app-token@v2
|
|
id: app-token
|
|
if: ${{ inputs.recover_version == '' }}
|
|
with:
|
|
app-id: ${{ vars.RELEASE_APP_ID }}
|
|
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
|
|
|
|
- uses: googleapis/release-please-action@v4
|
|
id: release
|
|
if: ${{ inputs.recover_version == '' }}
|
|
with:
|
|
token: ${{ steps.app-token.outputs.token }}
|
|
config-file: .github/release-please/release-please-config.json
|
|
manifest-file: .github/release-please/.release-please-manifest.json
|
|
|
|
- name: Select release to publish
|
|
id: target
|
|
env:
|
|
RECOVER_VERSION: ${{ inputs.recover_version }}
|
|
RELEASE_CREATED: ${{ steps.release.outputs.releases_created }}
|
|
RELEASE_SHA: ${{ steps.release.outputs['packages/cdn--sha'] }}
|
|
RELEASE_VERSION: ${{ steps.release.outputs['packages/cdn--version'] }}
|
|
RELEASE_TAG: ${{ steps.release.outputs['packages/cdn--tag_name'] }}
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
if [ -n "$RECOVER_VERSION" ]; then
|
|
if [[ ! "$RECOVER_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
|
|
echo "::error::Invalid release version: $RECOVER_VERSION"
|
|
exit 1
|
|
fi
|
|
|
|
# Publishing moves an npm dist-tag and later force-pushes site/v10, so only
|
|
# the current release on main is safe to resume.
|
|
if [ "$GITHUB_REF" != 'refs/heads/main' ]; then
|
|
echo '::error::Release recovery must be dispatched from main'
|
|
exit 1
|
|
fi
|
|
|
|
current_version=$(gh api "repos/${GITHUB_REPOSITORY}/contents/packages/cdn/package.json?ref=main" --jq '.content | @base64d | fromjson | .version')
|
|
if [ "$RECOVER_VERSION" != "$current_version" ]; then
|
|
echo "::error::Release recovery must use the current CDN version ($current_version)"
|
|
exit 1
|
|
fi
|
|
|
|
tag="@videojs/cdn@$RECOVER_VERSION"
|
|
gh release view "$tag" --repo "$GITHUB_REPOSITORY" --json tagName --jq .tagName > /dev/null
|
|
echo "ref=refs/tags/$tag" >> "$GITHUB_OUTPUT"
|
|
echo "version=$RECOVER_VERSION" >> "$GITHUB_OUTPUT"
|
|
echo "tag=$tag" >> "$GITHUB_OUTPUT"
|
|
elif [ "$RELEASE_CREATED" = 'true' ]; then
|
|
if [ -z "$RELEASE_SHA" ] || [ -z "$RELEASE_VERSION" ] || [ -z "$RELEASE_TAG" ]; then
|
|
echo '::error::Release Please did not provide the CDN release ref, version, and tag'
|
|
exit 1
|
|
fi
|
|
|
|
echo "ref=$RELEASE_SHA" >> "$GITHUB_OUTPUT"
|
|
echo "version=$RELEASE_VERSION" >> "$GITHUB_OUTPUT"
|
|
echo "tag=$RELEASE_TAG" >> "$GITHUB_OUTPUT"
|
|
else
|
|
exit 0
|
|
fi
|
|
|
|
echo 'released=true' >> "$GITHUB_OUTPUT"
|
|
|
|
- uses: actions/checkout@v5
|
|
if: ${{ steps.target.outputs.released == 'true' }}
|
|
with:
|
|
fetch-depth: 0 # Fetch all history for all tags and branches
|
|
# release-please creates the tags while this job is running, so the
|
|
# triggering SHA is still the commit before the release PR. Recovery
|
|
# also checks out the exact commit tagged for @videojs/cdn.
|
|
ref: ${{ steps.target.outputs.ref }}
|
|
|
|
- name: Setup pnpm
|
|
if: ${{ steps.target.outputs.released == 'true' }}
|
|
uses: pnpm/action-setup@v6.1.0
|
|
|
|
- uses: actions/setup-node@v5
|
|
if: ${{ steps.target.outputs.released == 'true' }}
|
|
with:
|
|
node-version-file: '.nvmrc'
|
|
registry-url: 'https://registry.npmjs.org'
|
|
|
|
- name: Install
|
|
if: ${{ steps.target.outputs.released == 'true' }}
|
|
run: pnpm i --frozen-lockfile
|
|
|
|
- name: Verify release checkout
|
|
if: ${{ steps.target.outputs.released == 'true' }}
|
|
run: |
|
|
node -e "process.exit(require('./packages/cdn/package.json').version === process.env.VERSION ? 0 : 1)"
|
|
|
|
if [ -n "$RECOVER_VERSION" ]; then
|
|
git fetch origin main site/v10 --quiet
|
|
if ! git merge-base --is-ancestor HEAD origin/main; then
|
|
echo '::error::The recovery tag is not on main'
|
|
exit 1
|
|
fi
|
|
|
|
# Main may have moved on: packages publish from this checkout, but the
|
|
# final step resets site/v10 to it, so every pick on site/v10 must
|
|
# already be in this release.
|
|
missing=$(git log --format=%B origin/main..origin/site/v10 \
|
|
| sed -n 's/^(cherry picked from commit \([0-9a-f]*\))$/\1/p' \
|
|
| while read -r commit; do
|
|
git merge-base --is-ancestor "$commit" HEAD 2>/dev/null || echo "$commit"
|
|
done)
|
|
if [ -n "$missing" ]; then
|
|
echo "::error::site/v10 has picks newer than this release: $(echo $missing)"
|
|
exit 1
|
|
fi
|
|
fi
|
|
env:
|
|
VERSION: ${{ steps.target.outputs.version }}
|
|
RECOVER_VERSION: ${{ inputs.recover_version }}
|
|
|
|
- name: Restore Vite Task cache
|
|
if: ${{ steps.target.outputs.released == 'true' }}
|
|
uses: actions/cache/restore@v6
|
|
with:
|
|
path: node_modules/.vite/task-cache
|
|
key: vite-task-${{ runner.os }}-${{ runner.arch }}-restore-only-${{ github.run_id }}-${{ github.run_attempt }}-${{ github.job }}
|
|
restore-keys: |
|
|
vite-task-${{ runner.os }}-${{ runner.arch }}-packages-
|
|
|
|
- name: Clean
|
|
if: ${{ steps.target.outputs.released == 'true' }}
|
|
run: .github/scripts/run-logged.sh clean pnpm clean
|
|
|
|
- name: Build
|
|
if: ${{ steps.target.outputs.released == 'true' }}
|
|
run: .github/scripts/run-logged.sh build-packages pnpm build:packages
|
|
|
|
- name: Build CDN bundles
|
|
if: ${{ steps.target.outputs.released == 'true' }}
|
|
run: .github/scripts/run-logged.sh build-cdn pnpm build:cdn
|
|
|
|
# Fail before publishing rather than ship bundles that reach out to a public
|
|
# CDN at runtime, which would break self-hosted and archive installs.
|
|
- name: Check CDN bundles are self-contained
|
|
if: ${{ steps.target.outputs.released == 'true' }}
|
|
run: pnpm -F @videojs/cdn check:cdn
|
|
|
|
- name: Build distribution archive
|
|
if: ${{ steps.target.outputs.released == 'true' }}
|
|
run: pnpm -F @videojs/cdn build:archive
|
|
|
|
# The site build emits per-framework markdown to site/dist/docs/framework/{html,react}/.
|
|
# The @videojs/html and @videojs/react packages' prepack scripts (fired by `pnpm publish`
|
|
# below) copy that subtree into each package's docs/ directory so it ships in the tarball.
|
|
# The task graph lets Vite Task reuse the package builds here.
|
|
- name: Build site (required by html/react prepack)
|
|
if: ${{ steps.target.outputs.released == 'true' }}
|
|
run: .github/scripts/run-logged.sh build-site pnpm build:site
|
|
|
|
- name: Publish
|
|
if: ${{ steps.target.outputs.released == 'true' }}
|
|
# Stable versions go to `latest`; prereleases go to `next` so they never
|
|
# become the default install. npm authenticates through trusted
|
|
# publishing (OIDC), so no token is needed.
|
|
run: |
|
|
tag=latest
|
|
if [[ "$VERSION" == *-* ]]; then
|
|
tag=next
|
|
fi
|
|
pnpm --fail-if-no-match -r publish --filter "./packages/**" --access public --provenance --no-git-checks --tag "$tag"
|
|
env:
|
|
VERSION: ${{ steps.target.outputs.version }}
|
|
|
|
# Attach the archive to the @videojs/cdn release so installers outside npm
|
|
# (Composer, Drupal) have a stable, versioned download. Use the tag and
|
|
# version selected above, matching the checkout for this run.
|
|
- name: Upload distribution archive to the release
|
|
if: ${{ steps.target.outputs.released == 'true' }}
|
|
run: |
|
|
gh release upload "$RELEASE_TAG" \
|
|
"packages/cdn/archive/videojs-cdn-${VERSION}.zip" \
|
|
"packages/cdn/archive/videojs-cdn-${VERSION}.tar.gz" \
|
|
packages/cdn/archive/SHA256SUMS \
|
|
--clobber
|
|
|
|
ASSETS=$(gh release view "$RELEASE_TAG" --json assets --jq '.assets[].name')
|
|
grep -Fx "videojs-cdn-${VERSION}.zip" <<< "$ASSETS"
|
|
grep -Fx "videojs-cdn-${VERSION}.tar.gz" <<< "$ASSETS"
|
|
grep -Fx "SHA256SUMS" <<< "$ASSETS"
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
RELEASE_TAG: ${{ steps.target.outputs.tag }}
|
|
VERSION: ${{ steps.target.outputs.version }}
|
|
|
|
- name: Update site/v10 branch
|
|
if: ${{ steps.target.outputs.released == 'true' }}
|
|
run: git push origin HEAD:refs/heads/site/v10 --force
|