diff --git a/.github/workflows/_build.yml b/.github/workflows/_build.yml new file mode 100644 index 000000000000..12e3f9030383 --- /dev/null +++ b/.github/workflows/_build.yml @@ -0,0 +1,104 @@ +name: Build website + +on: + workflow_call: + inputs: + node_version: + description: Define the version of Node.JS to use. + required: false + type: string + default: '24' + environment_name: + type: string + required: true + docusaurus_base_url: + required: true + type: string + docusaurus_no_index: + required: true + type: number + default: 0 + docusaurus_pr_number: + required: false + type: number + docusaurus_pr_url: + required: false + type: string + artifact_path: + description: Define the artifact path. + required: false + type: string + default: './build/' + artifact_name: + description: Define the artifact name. + required: false + type: string + default: 'dist.zip' + artifact_retention_day: + description: Define retention period in days. + required: false + type: number + default: 1 + outputs: + artifact_name: + description: 'Return the name of the built artifact.' + value: ${{ inputs.artifact_name }} + +concurrency: + group: build-${{ github.ref }} + cancel-in-progress: true + +# Permissions needed to interact with GitHub's OIDC Token endpoint +permissions: + id-token: write + contents: read + +jobs: + build: + runs-on: ubuntu-latest + environment: + name: ${{ inputs.environment_name }} + # Use environment's secrets without creating a deployment object. + # https://docs.github.com/en/actions/how-tos/deploy/configure-and-manage-deployments/control-deployments#using-environments-without-deployments + deployment: false + steps: + - name: Checkout ๐Ÿ›Ž๏ธ + uses: actions/checkout@v7 + with: + fetch-depth: 1 + submodules: true + + - name: Setup Node.JS ๐Ÿ”ง + uses: actions/setup-node@v7 + with: + node-version: ${{ inputs.node_version }} + cache: 'npm' + cache-dependency-path: ./package-lock.json + + - name: Print NPM version ๐ŸŒŽ + shell: bash + run: | + npm --version + + - name: Install dependencies ๐Ÿ”ง + shell: bash + run: | + git config --global --add safe.directory ${GITHUB_WORKSPACE} + npm ci + + - name: Build ๐Ÿ”ง + run: | + npm run build + env: + THEOPLAYER_LICENSE: ${{ vars.THEOPLAYER_LICENSE }} + DOCUSAURUS_BASE_URL: ${{ inputs.docusaurus_base_url }} + DOCUSAURUS_NO_INDEX: ${{ inputs.docusaurus_no_index }} + DOCUSAURUS_PR_NUMBER: ${{ inputs.docusaurus_pr_number }} + DOCUSAURUS_PR_URL: ${{ inputs.docusaurus_pr_url }} + + - name: Upload Build โ˜๏ธ + uses: actions/upload-artifact@v7 + with: + name: ${{ inputs.artifact_name }} + path: ${{ inputs.artifact_path }} + retention-days: ${{ inputs.artifact_retention_day }} diff --git a/.github/workflows/_deploy.yml b/.github/workflows/_deploy.yml new file mode 100644 index 000000000000..a77eda0f46c3 --- /dev/null +++ b/.github/workflows/_deploy.yml @@ -0,0 +1,67 @@ +name: Deploy website + +on: + workflow_call: + inputs: + environment_name: + type: string + required: true + environment_url: + description: | + The URL where the website will be deployed. + This will be shown on the deployment page and on the triggering pull request. + type: string + required: false + default: '' + artifact_name: + description: Name of the built artifact for deployment. + required: true + type: string + s3_prefix: + description: AWS S3 prefix where to store the build. + required: true + type: string + +concurrency: deploy-${{ github.ref }} + +jobs: + deploy-to-cloudfront: + runs-on: ubuntu-latest + environment: + name: ${{ inputs.environment_name }} + deployment: true + url: ${{ inputs.environment_url }} + permissions: + id-token: write + steps: + - name: Download build artifact ๐Ÿ—ƒ๏ธ + uses: actions/download-artifact@v8 + with: + name: ${{ inputs.artifact_name }} + path: ${{ github.workspace }}/${{ inputs.artifact_name }} + + - name: Configure AWS credentials โ˜๏ธ + uses: aws-actions/configure-aws-credentials@v6 + with: + aws-region: ${{ vars.AWS_REGION }} + role-to-assume: ${{ vars.AWS_ROLE }} + + - name: 'Sync to ${{ inputs.s3_prefix }} on S3 ๐Ÿ’พ' + run: | + echo "Copying artifact: ${ARTIFACT_PATH} to S3 bucket: ${S3_BUCKET}/${S3_PREFIX}" + aws s3 sync ${ARTIFACT_PATH}/ s3://${S3_BUCKET}/${S3_PREFIX}/ \ + --only-show-errors \ + --delete + env: + S3_BUCKET: ${{ vars.S3_BUCKET_NAME }} + S3_PREFIX: ${{ inputs.s3_prefix }} + ARTIFACT_PATH: ${{ github.workspace }}/${{ inputs.artifact_name }} + + - name: Invalidate Amazon CloudFront ๐Ÿงน + run: | + aws cloudfront create-invalidation \ + --distribution-id ${CF_DISTRIBUTION_ID} \ + --paths ${PATH_TO_INVALIDATE} + env: + CF_DISTRIBUTION_ID: ${{ vars.CF_DISTRIBUTION_ID }} + PATH_TO_INVALIDATE: '/${{ inputs.s3_prefix }}*' diff --git a/.github/workflows/_lint.yml b/.github/workflows/_lint.yml new file mode 100644 index 000000000000..c5fe6fa10cbf --- /dev/null +++ b/.github/workflows/_lint.yml @@ -0,0 +1,47 @@ +name: Lint + +on: + workflow_call: + inputs: + node_version: + description: Define the version of Node.JS to use. + required: false + type: string + default: '24' + +concurrency: + group: lint-${{ github.ref }} + cancel-in-progress: true + +jobs: + pr-lint: + runs-on: ubuntu-latest + steps: + - name: Checkout ๐Ÿ›Ž๏ธ + uses: actions/checkout@v7 + with: + fetch-depth: 1 + submodules: true + + - name: Setup Node.JS ๐Ÿ”ง + uses: actions/setup-node@v7 + with: + node-version: ${{ inputs.node_version }} + cache: 'npm' + cache-dependency-path: ./package-lock.json + + - name: Print NPM version ๐ŸŒŽ + shell: bash + run: | + npm --version + + - name: Install dependencies ๐Ÿ”ง + shell: bash + run: | + git config --global --add safe.directory ${GITHUB_WORKSPACE} + npm ci + + - run: npm run gen-api-docs + - run: npm run check-format + - run: npm run lint + - run: npm run typecheck diff --git a/.github/workflows/_undeploy.yml b/.github/workflows/_undeploy.yml new file mode 100644 index 000000000000..9a376f67dd29 --- /dev/null +++ b/.github/workflows/_undeploy.yml @@ -0,0 +1,48 @@ +name: Undeploy a pull request preview + +on: + workflow_call: + inputs: + environment_name: + type: string + required: true + s3_prefix: + description: AWS S3 prefix where the build is located. + required: true + type: string + +concurrency: deploy-${{ github.ref }} + +jobs: + deploy-to-cloudfront: + runs-on: ubuntu-latest + environment: + name: ${{ inputs.environment_name }} + deployment: false + permissions: + id-token: write + steps: + - name: Configure AWS credentials โ˜๏ธ + uses: aws-actions/configure-aws-credentials@v6 + with: + aws-region: ${{ vars.AWS_REGION }} + role-to-assume: ${{ vars.AWS_ROLE }} + + - name: 'Delete ${{ inputs.s3_prefix }} from S3 ๐Ÿ’พ' + run: | + echo "Delete the files from S3 bucket: ${S3_BUCKET}/${S3_PREFIX}" + aws s3 rm s3://${S3_BUCKET}/${S3_PREFIX} \ + --recursive \ + --only-show-errors + env: + S3_BUCKET: ${{ vars.S3_BUCKET_NAME }} + S3_PREFIX: ${{ inputs.s3_prefix }} + + - name: Invalidate Amazon CloudFront ๐Ÿงน + run: | + aws cloudfront create-invalidation \ + --distribution-id ${CF_DISTRIBUTION_ID} \ + --paths '/${S3_PREFIX}/*' + env: + CF_DISTRIBUTION_ID: ${{ vars.CF_DISTRIBUTION_ID }} + S3_PREFIX: ${{ inputs.s3_prefix }} diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml deleted file mode 100644 index d6a32472d3c2..000000000000 --- a/.github/workflows/deploy-staging.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Deploy to staging -on: - workflow_dispatch: -concurrency: - group: staging - cancel-in-progress: true -jobs: - deploy: - runs-on: ubuntu-latest - environment: staging - # Permissions needed to interact with GitHub's OIDC Token endpoint - permissions: - id-token: write - contents: read - steps: - - name: Checkout - uses: actions/checkout@v7 - with: - fetch-depth: 1 - submodules: true - # Build the website - - name: Use Node.js 22 - uses: actions/setup-node@v6 - with: - node-version: 22 - cache: 'npm' - - run: npm ci - - run: npm run build - env: - THEOPLAYER_LICENSE: ${{ vars.THEOPLAYER_LICENSE }} - DOCUSAURUS_BASE_URL: /docs/ - # Deploy to S3 - # See https://github.com/aws-actions/configure-aws-credentials - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v6 - with: - role-to-assume: arn:aws:iam::823129359776:role/optiview-docs-github - aws-region: us-west-2 - - name: Deploy to S3 - run: | - aws s3 sync --delete ./build s3://docs-staging-optiview-dolby-com-0-20250610142618642800000001/docs/ - - name: Invalidate CloudFront - run: | - aws cloudfront create-invalidation --distribution-id E15SU691K20UEP --paths '/*' diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 0a321c366a93..000000000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: Deploy to production -on: - push: - branches: - - main - workflow_dispatch: -concurrency: - group: production - cancel-in-progress: true -jobs: - deploy: - runs-on: ubuntu-latest - environment: production - # Permissions needed to interact with GitHub's OIDC Token endpoint - permissions: - id-token: write - contents: read - steps: - - name: Checkout - uses: actions/checkout@v7 - with: - fetch-depth: 1 - submodules: true - # Build the website - - name: Use Node.js 22 - uses: actions/setup-node@v6 - with: - node-version: 22 - cache: 'npm' - - run: npm ci - - run: npm run build - env: - THEOPLAYER_LICENSE: ${{ vars.THEOPLAYER_LICENSE }} - DOCUSAURUS_BASE_URL: /docs/ - # Deploy to S3 - # See https://github.com/aws-actions/configure-aws-credentials - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v6 - with: - role-to-assume: arn:aws:iam::548863597864:role/optiview-docs-github - aws-region: us-west-2 - - name: Deploy to S3 - run: | - aws s3 sync --delete ./build s3://docs-optiview-dolby-com-0-20250401191057436800000003/docs/ - - name: Invalidate CloudFront - run: | - aws cloudfront create-invalidation --distribution-id EKPRWRE0B1EQ4 --paths '/*' diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index fd7a7c28e886..000000000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Lint -on: - pull_request: - types: - - opened - - reopened - - synchronize -jobs: - pr-lint: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v7 - with: - fetch-depth: 1 - submodules: true - - name: Use Node.js 22 - uses: actions/setup-node@v6 - with: - node-version: 22 - cache: 'npm' - - run: npm ci - - run: npm run gen-api-docs - - run: npm run check-format - - run: npm run lint - - run: npm run typecheck diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000000..363bca042dfb --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,29 @@ +name: 'On Push to Main branch' + +on: + push: + branches: + - main + workflow_dispatch: + +concurrency: + group: production + cancel-in-progress: true + +jobs: + build: + name: build + uses: ./.github/workflows/_build.yml + with: + environment_name: production + docusaurus_base_url: '/docs/' + docusaurus_no_index: 0 + + deploy: + name: deploy + needs: [build] + uses: ./.github/workflows/_deploy.yml + with: + environment_name: production + artifact_name: ${{ needs.build.outputs.artifact_name }} + s3_prefix: 'docs' diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml deleted file mode 100644 index af2bd1ec87ad..000000000000 --- a/.github/workflows/pr-build.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Build pull request -on: - pull_request: - types: - - opened - - reopened - - synchronize -concurrency: build-${{ github.ref }} -jobs: - build: - runs-on: ubuntu-latest - # Run only on PRs from forks, or from Dependabot. - if: ${{ github.event.pull_request.head.repo.fork || github.triggering_actor == 'dependabot[bot]' }} - steps: - - name: Checkout - uses: actions/checkout@v7 - with: - fetch-depth: 1 - submodules: true - # Build the website - - name: Use Node.js 22 - uses: actions/setup-node@v6 - with: - node-version: 22 - cache: 'npm' - - name: Build - run: | - npm ci - npm run build diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml deleted file mode 100644 index 35b1c992daf5..000000000000 --- a/.github/workflows/pr-preview.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: Deploy pull request preview -on: - pull_request: - types: - - opened - - reopened - - synchronize - - closed -concurrency: preview-${{ github.ref }} -jobs: - pr-preview: - runs-on: ubuntu-latest - # Do not run on PRs from forks or from Dependabot, since they don't have the permissions to deploy to our GitHub pages branch. - if: ${{ !github.event.pull_request.head.repo.fork && github.triggering_actor != 'dependabot[bot]' }} - steps: - - name: Create app token - uses: actions/create-github-app-token@v3 - id: app-token - with: - client-id: ${{ vars.THEOPLAYER_BOT_CLIENT_ID }} - private-key: ${{ secrets.THEOPLAYER_BOT_PRIVATE_KEY }} - - name: Checkout - uses: actions/checkout@v7 - with: - token: ${{ steps.app-token.outputs.token }} - fetch-depth: 1 - submodules: true - # Build the website - - name: Use Node.js 22 - if: github.event.action != 'closed' - uses: actions/setup-node@v6 - with: - node-version: 22 - cache: 'npm' - - name: Build - if: github.event.action != 'closed' - run: | - npm ci - npm run build - env: - THEOPLAYER_LICENSE: ${{ vars.THEOPLAYER_LICENSE }} - # Preview URLs look like this: https://[owner].github.io/[repo]/pr-preview/pr-[number]/ - # https://github.com/marketplace/actions/deploy-pr-preview - DOCUSAURUS_BASE_URL: /${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.number }}/ - # Prevent PR previews from being indexed by search engines - DOCUSAURUS_NO_INDEX: 1 - # Add an announcement at the top to indicate that this is a preview - DOCUSAURUS_PR_NUMBER: ${{ github.event.number }} - DOCUSAURUS_PR_URL: ${{ github.event.pull_request.html_url }} - # Deploy preview - - name: Deploy preview - uses: rossjrw/pr-preview-action@v1 - with: - token: ${{ steps.app-token.outputs.token }} - source-dir: ./build/ - preview-branch: gh-pages - umbrella-dir: pr-preview diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 000000000000..7a9b84e15ea4 --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,51 @@ +name: 'On Pull Requests' + +on: + pull_request: + types: + - opened + - reopened + - synchronize + - ready_for_review + - closed + +jobs: + lint: + name: lint + if: ${{ github.event.action != 'closed' }} + uses: ./.github/workflows/_lint.yml + secrets: inherit + + build: + name: build + if: ${{ github.event.action != 'closed' }} + uses: ./.github/workflows/_build.yml + with: + environment_name: preview + # Preview URLs look like this: https://[storage-url]/pr-[number]/ + docusaurus_base_url: '/pr-${{ github.event.number }}/' + # Prevent PR previews from being indexed by search engines + docusaurus_no_index: 1 + # Add an announcement at the top to indicate if this is a preview + docusaurus_pr_number: ${{ github.event.number }} + docusaurus_pr_url: ${{ github.event.pull_request.html_url }} + + deploy: + name: deploy + needs: [build] + # Do not run on PRs from Dependabot, since they should not need it. + if: ${{ github.event.action != 'closed' && github.triggering_actor != 'dependabot[bot]' }} + uses: ./.github/workflows/_deploy.yml + with: + environment_name: preview + environment_url: '${{ vars.PREVIEW_CLOUDFRONT_URL }}/pr-${{ github.event.number }}/' + artifact_name: ${{ needs.build.outputs.artifact_name }} + s3_prefix: 'pr-${{ github.event.number }}' + + undeploy: + name: undeploy + if: ${{ github.event.action == 'closed' && github.triggering_actor != 'dependabot[bot]' }} + uses: ./.github/workflows/_undeploy.yml + with: + environment_name: preview + s3_prefix: 'pr-${{ github.event.number }}' diff --git a/.github/workflows/update-submodules.yml b/.github/workflows/update-submodules.yml deleted file mode 100644 index 56524d434a4c..000000000000 --- a/.github/workflows/update-submodules.yml +++ /dev/null @@ -1,90 +0,0 @@ -name: Update submodules -on: - # Runs every day at midnight UTC - schedule: - - cron: '0 0 * * *' - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: -jobs: - update: - runs-on: ubuntu-latest - permissions: - contents: write - pull-requests: write - env: - # The branch that will receive the submodule updates (will be created if it doesn't exist) - # Will automatically open a new PR (if no PR exists yet) - UPDATE_BRANCH: update-submodules - steps: - - name: Create app token - uses: actions/create-github-app-token@v3 - id: app-token - with: - client-id: ${{ vars.THEOPLAYER_BOT_CLIENT_ID }} - private-key: ${{ secrets.THEOPLAYER_BOT_PRIVATE_KEY }} - - name: Checkout - uses: actions/checkout@v7 - with: - token: ${{ steps.app-token.outputs.token }} - fetch-depth: 1 - - name: Configure Git user - run: | - git config user.name 'theoplayer-bot[bot]' - git config user.email '873105+theoplayer-bot[bot]@users.noreply.github.com' - - name: Create branch - run: git checkout -b $UPDATE_BRANCH - - name: Update submodules with upstream - # `git submodule update --remote` doesn't seem to work very well with non-main branches... - # Fetch and checkout the latest revision of each submodule manually. - run: | - git submodule update --init --single-branch - git submodule foreach 'git fetch --depth=1 origin $(git config -f $toplevel/.gitmodules submodule.$name.branch) && git checkout --quiet FETCH_HEAD' - - name: Commit changes - run: git commit --allow-empty -a -m 'Update submodules' - - name: Check for relevant doc changes - id: check_doc_changes - shell: bash - # https://stackoverflow.com/q/67724347/7976758 - # We only care about changes to CHANGELOG.md or inside /doc/ or /docs/ - run: | - compare () { - if [ -z "$3" ]; - then git diff --name-only --ignore-submodules=all --diff-filter=ACMR "$1" "$2" - else git diff --name-only --ignore-submodules=all --diff-filter=ACMR "$1" "$2" | awk -v r=$3 '{print "" r "/" $0}' - fi - for submodule in `git submodule | awk '{print $2}'` - do - old=$(git ls-tree $1 $submodule | awk '{print $3}') - new=$(git ls-tree $2 $submodule | awk '{print $3}') - (cd $submodule && compare $old $new $submodule) - done - } - change_count=$(compare "HEAD~1" "HEAD" | (grep -c -E 'README|CHANGELOG|/docs?/' ||:)) - if ((change_count > 0)); then - echo "changed=true" >> "$GITHUB_OUTPUT" - fi - - name: Push to branch - if: ${{ steps.check_doc_changes.outputs.changed }} - run: git push --force origin HEAD:$UPDATE_BRANCH - - name: Check if pull request already exists - if: ${{ steps.check_doc_changes.outputs.changed }} - id: check_pr_exists - shell: bash - run: | - pr_count=$(gh pr list --base main --head "$UPDATE_BRANCH" --state open --limit 1 --json number --jq length) - if ((pr_count > 0)); then - echo "exists=true" >> "$GITHUB_OUTPUT" - fi - env: - GH_TOKEN: ${{ steps.app-token.outputs.token }} - - name: Create pull request - if: ${{ steps.check_doc_changes.outputs.changed && !steps.check_pr_exists.outputs.exists }} - shell: bash - run: | - gh pr create \ - --base main \ - --head "$UPDATE_BRANCH" \ - --title "Update documentation from submodules" \ - --body "This PR pulls in the latest documentation changes from the external submodules." - env: - GH_TOKEN: ${{ steps.app-token.outputs.token }}