<commit_before># Plugin release automation
#
# Builds the plugin for release candidates and stable releases.
#
# Creates the release branch, the actual release on GitHub, and the correct tag.
#
# For new major releases, the action should be run from the `main` branch.
# For patch releases, the action should be run from the corresponding release branch (e.g. `release/1.2.0`)

name: Plugin Release

on:
  workflow_dispatch:
    inputs:
      version:
        description: 'Plugin version (e.g. 1.2.3 or 7.2.0-rc.1)'
        required: true

env:
  PLUGIN_VERSION: ${{ github.event.inputs.version }}
  TAG_NAME: 'v${{ github.event.inputs.version }}'
  IS_RC: ${{ contains(github.event.inputs.version, 'rc') }}
  IS_PATCH_RELEASE: ${{ startsWith(github.ref, 'refs/heads/release/') }}
  GIT_AUTHOR_EMAIL: <EMAIL>
  GIT_AUTHOR_NAME: googleforcreators-bot
  GIT_COMMITTER_EMAIL: <EMAIL>
  GIT_COMMITTER_NAME: googleforcreators-bot
  GITHUB_REPO_ID: 235435637

jobs:
  # Perform some sanity checks at the beginning to avoid surprises.
  checks:
    name: Checks
    runs-on: ubuntu-latest
    timeout-minutes: 5
    # This step requires additional review
    # See https://docs.github.com/en/actions/reference/environments
    environment: Production
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Verify semver compatibility
        run: |
          if [[ $PLUGIN_VERSION =~ $SEMVER_VERSION_REGEX ]]; then
            echo "Given plugin version string is a valid semver version"
          else
            echo "Given plugin version string is not a valid semver version"
            exit 1
          fi
        env:
          SEMVER_VERSION_REGEX: ^([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(\+[0-9A-Za-z-]+)?$

      - name: Verify release does not exist yet
        run: |
          if git describe --abbrev=0 --tags --match "$TAG_NAME" &>/dev/null; then
            echo "The planned plugin version already exists!"
            exit 1
          fi

      #      - name: Ensure RC exists for stable release
      #        if: ${{ ! contains(github.event.inputs.version, 'rc') }}
      #        run: |
      #          VERSION_WITHOUT_SUFFIX=${PLUGIN_VERSION/-rc.*/}
      #          BRANCH=release/$VERSION_WITHOUT_SUFFIX
      #
      #          if [[ -z $(git ls-remote origin $BRANCH) ]]; then
      #            echo "No release branch exists for this planned stable release"
      #            exit 1
      #          fi
      #
      #          git checkout --track origin/$BRANCH
      #
      #          if ! git describe --abbrev=0 --tags --match "$TAG_NAME-rc.*" &>/dev/null; then
      #            echo "No RC exists for this planned stable release"
      #            exit 1
      #          fi

      - name: Ensure readme.txt contains changelog
        run: |
          VERSION_WITHOUT_SUFFIX=${PLUGIN_VERSION/-rc.*/}
          CHANGELOG_REGEX="= $VERSION_WITHOUT_SUFFIX ="

          if ! grep -q -P "$CHANGELOG_REGEX" readme.txt; then
            echo "No changelog found in readme.txt"
            exit 1
          fi

  # Get the current CDN assets version.
  # If the static assets on the CDN have changed since the last release,
  # bump the assets version accordingly in the GoogleForCreators/wp.stories.google repo.
  assets-version:
    name: Prepare static assets
    runs-on: ubuntu-latest
    timeout-minutes: 10
    needs: [checks]
    steps:
      # TODO: Define behavior for patch releases.
      #
      # A patch release is done from a specific release branch instead of `main`
      #
      # Patch releases must not necessarily copy assets from `main`.
      # Given the following assets versions:
      # main  1  2  3  4 <- next major release
      #             ^
      #             |
      #       current branch
      #
      # The patch release should probably get version 3.1 or similar,
      # since version 4 is already used by the next major release.
      #
      # Right now, this is needs to be done manually for patch releases,
      # otherwise the assets version is left unchanged here.

      # Grab current assets version from `web-stories.php` and pass on to next steps.
      # - name: Checkout
      #   uses: actions/checkout@v3
      #   with:
      #     ref:

      # - name: Get current assets version
      #   id: base_assets_version
      #   run: |
      #     BASE_ASSETS_VERSION=main
      #     if  [[ $(cat web-stories.php) =~ $ASSETS_VERSION_REGEX ]]; then
      #       BASE_ASSETS_VERSION=${BASH_REMATCH[1]}
      #     fi
      #     echo "::set-output name=BASE_ASSETS_VERSION::$BASE_ASSETS_VERSION"
      #     env:
      #       ASSETS_VERSION_REGEX: "https://wp.stories.google/static/([^']+)"

      - name: Checkout wp.stories.google
        uses: actions/checkout@v3
        with:
          repository: GoogleForCreators/wp.stories.google
          lfs: true
          # Needed so the below commits will trigger a website deployment.
          token: ${{ secrets.GOOGLEFORCREATORS_BOT_TOKEN }}

      - name: Setup Cloud SDK
        uses: google-github-actions/setup-gcloud@v0.6.0
        with:
          project_id: ${{ secrets.GCP_PROJECT_ID }}
          service_account_key: ${{ secrets.GCP_SA_KEY }}

      # For release candidates of new major releases:
      #
      # 1. Get highest assets version
      # 2. Compare with `main`
      # 3. If they differ:
      # 3.1 Set new_version = version+1
      # 3.2 Copy `main` to new_version
      # 3.2 Push new directory
      # 4. Else, keep currently highest version
      - name: Prepare assets for RC
        if: ${{ contains(github.event.inputs.version, 'rc') && ! startsWith(github.ref, 'refs/heads/release/') }}
        run: |
          LATEST_ASSETS_VERSION=$(gsutil ls gs://web-stories-wp-cdn-assets/ | sed 's/gs:\/\/web-stories-wp-cdn-assets\///' | sed 's/\///' | sort -n | tail -1)
          NEW_ASSETS_VERSION=$LATEST_ASSETS_VERSION

          NUMBER_OF_NEW_ASSETS=$(ls main | wc -l)

          if [[ "0" -eq NUMBER_OF_NEW_ASSETS ]]; then
            echo "No new assets found. Not uploading anything."
          else
            echo "New assets found."
            NEW_ASSETS_VERSION=$((LATEST_ASSETS_VERSION+1))

            echo "Copying existing assets over to new version."

            gsutil -m rsync -r gs://web-stories-wp-cdn-assets/$LATEST_ASSETS_VERSION gs://web-stories-wp-cdn-assets/$NEW_ASSETS_VERSION

            echo "Uploading new assets to new version."
            gsutil -m rsync -r -x '(^|/)\.' main gs://web-stories-wp-cdn-assets/$NEW_ASSETS_VERSION

            rm -rf static/main/*

            echo "Updating LATEST_ASSETS_VERSION Firebase env variable."

            echo "LATEST_ASSETS_VERSION=$NEW_ASSETS_VERSION" > ../../functions/.env

            git add ../../functions/.env
            git add .
            git status
            git commit -m "Preparing assets for plugin release $PLUGIN_VERSION"
            git pull --rebase
            git push origin main
          fi

          echo "Assets version for this release: $NEW_ASSETS_VERSION"

          mkdir -p assets_version
          echo $NEW_ASSETS_VERSION > assets_version/assets_version.txt
        working-directory: public/static<commit_msg>Plugin release: fix file path in workflow<commit_after># Plugin release automation
#
# Builds the plugin for release candidates and stable releases.
#
# Creates the release branch, the actual release on GitHub, and the correct tag.
#
# For new major releases, the action should be run from the `main` branch.
# For patch releases, the action should be run from the corresponding release branch (e.g. `release/1.2.0`)

name: Plugin Release

on:
  workflow_dispatch:
    inputs:
      version:
        description: 'Plugin version (e.g. 1.2.3 or 7.2.0-rc.1)'
        required: true

env:
  PLUGIN_VERSION: ${{ github.event.inputs.version }}
  TAG_NAME: 'v${{ github.event.inputs.version }}'
  IS_RC: ${{ contains(github.event.inputs.version, 'rc') }}
  IS_PATCH_RELEASE: ${{ startsWith(github.ref, 'refs/heads/release/') }}
  GIT_AUTHOR_EMAIL: <EMAIL>
  GIT_AUTHOR_NAME: googleforcreators-bot
  GIT_COMMITTER_EMAIL: <EMAIL>
  GIT_COMMITTER_NAME: googleforcreators-bot
  GITHUB_REPO_ID: 235435637

jobs:
  # Perform some sanity checks at the beginning to avoid surprises.
  checks:
    name: Checks
    runs-on: ubuntu-latest
    timeout-minutes: 5
    # This step requires additional review
    # See https://docs.github.com/en/actions/reference/environments
    environment: Production
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Verify semver compatibility
        run: |
          if [[ $PLUGIN_VERSION =~ $SEMVER_VERSION_REGEX ]]; then
            echo "Given plugin version string is a valid semver version"
          else
            echo "Given plugin version string is not a valid semver version"
            exit 1
          fi
        env:
          SEMVER_VERSION_REGEX: ^([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(\+[0-9A-Za-z-]+)?$

      - name: Verify release does not exist yet
        run: |
          if git describe --abbrev=0 --tags --match "$TAG_NAME" &>/dev/null; then
            echo "The planned plugin version already exists!"
            exit 1
          fi

      #      - name: Ensure RC exists for stable release
      #        if: ${{ ! contains(github.event.inputs.version, 'rc') }}
      #        run: |
      #          VERSION_WITHOUT_SUFFIX=${PLUGIN_VERSION/-rc.*/}
      #          BRANCH=release/$VERSION_WITHOUT_SUFFIX
      #
      #          if [[ -z $(git ls-remote origin $BRANCH) ]]; then
      #            echo "No release branch exists for this planned stable release"
      #            exit 1
      #          fi
      #
      #          git checkout --track origin/$BRANCH
      #
      #          if ! git describe --abbrev=0 --tags --match "$TAG_NAME-rc.*" &>/dev/null; then
      #            echo "No RC exists for this planned stable release"
      #            exit 1
      #          fi

      - name: Ensure readme.txt contains changelog
        run: |
          VERSION_WITHOUT_SUFFIX=${PLUGIN_VERSION/-rc.*/}
          CHANGELOG_REGEX="= $VERSION_WITHOUT_SUFFIX ="

          if ! grep -q -P "$CHANGELOG_REGEX" readme.txt; then
            echo "No changelog found in readme.txt"
            exit 1
          fi

  # Get the current CDN assets version.
  # If the static assets on the CDN have changed since the last release,
  # bump the assets version accordingly in the GoogleForCreators/wp.stories.google repo.
  assets-version:
    name: Prepare static assets
    runs-on: ubuntu-latest
    timeout-minutes: 10
    needs: [checks]
    steps:
      # TODO: Define behavior for patch releases.
      #
      # A patch release is done from a specific release branch instead of `main`
      #
      # Patch releases must not necessarily copy assets from `main`.
      # Given the following assets versions:
      # main  1  2  3  4 <- next major release
      #             ^
      #             |
      #       current branch
      #
      # The patch release should probably get version 3.1 or similar,
      # since version 4 is already used by the next major release.
      #
      # Right now, this is needs to be done manually for patch releases,
      # otherwise the assets version is left unchanged here.

      # Grab current assets version from `web-stories.php` and pass on to next steps.
      # - name: Checkout
      #   uses: actions/checkout@v3
      #   with:
      #     ref:

      # - name: Get current assets version
      #   id: base_assets_version
      #   run: |
      #     BASE_ASSETS_VERSION=main
      #     if  [[ $(cat web-stories.php) =~ $ASSETS_VERSION_REGEX ]]; then
      #       BASE_ASSETS_VERSION=${BASH_REMATCH[1]}
      #     fi
      #     echo "::set-output name=BASE_ASSETS_VERSION::$BASE_ASSETS_VERSION"
      #     env:
      #       ASSETS_VERSION_REGEX: "https://wp.stories.google/static/([^']+)"

      - name: Checkout wp.stories.google
        uses: actions/checkout@v3
        with:
          repository: GoogleForCreators/wp.stories.google
          lfs: true
          # Needed so the below commits will trigger a website deployment.
          token: ${{ secrets.GOOGLEFORCREATORS_BOT_TOKEN }}

      - name: Setup Cloud SDK
        uses: google-github-actions/setup-gcloud@v0.6.0
        with:
          project_id: ${{ secrets.GCP_PROJECT_ID }}
          service_account_key: ${{ secrets.GCP_SA_KEY }}

      # For release candidates of new major releases:
      #
      # 1. Get highest assets version
      # 2. Compare with `main`
      # 3. If they differ:
      # 3.1 Set new_version = version+1
      # 3.2 Copy `main` to new_version
      # 3.2 Push new directory
      # 4. Else, keep currently highest version
      - name: Prepare assets for RC
        if: ${{ contains(github.event.inputs.version, 'rc') && ! startsWith(github.ref, 'refs/heads/release/') }}
        run: |
          LATEST_ASSETS_VERSION=$(gsutil ls gs://web-stories-wp-cdn-assets/ | sed 's/gs:\/\/web-stories-wp-cdn-assets\///' | sed 's/\///' | sort -n | tail -1)
          NEW_ASSETS_VERSION=$LATEST_ASSETS_VERSION

          NUMBER_OF_NEW_ASSETS=$(ls main | wc -l)

          if [[ "0" -eq NUMBER_OF_NEW_ASSETS ]]; then
            echo "No new assets found. Not uploading anything."
          else
            echo "New assets found."
            NEW_ASSETS_VERSION=$((LATEST_ASSETS_VERSION+1))

            echo "Copying existing assets over to new version."

            gsutil -m rsync -r gs://web-stories-wp-cdn-assets/$LATEST_ASSETS_VERSION gs://web-stories-wp-cdn-assets/$NEW_ASSETS_VERSION

            echo "Uploading new assets to new version."
            gsutil -m rsync -r -x '(^|/)\.' main gs://web-stories-wp-cdn-assets/$NEW_ASSETS_VERSION

            rm -rf static/main/*

            echo "Updating LATEST_ASSETS_VERSION Firebase env variable."

            echo "LATEST_ASSETS_VERSION=$NEW_ASSETS_VERSION" > packages/functions/.env

            git add packages/functions/.env
            git add .
            git status
            git commit -m "Preparing assets for plugin release $PLUGIN_VERSION"
            git pull --rebase
            git push origin main
          fi

          echo "Assets version for this release: $NEW_ASSETS_VERSION"

          mkdir -p assets_version
          echo $NEW_ASSETS_VERSION > assets_version/assets_version.txt
        working-directory: public/static
{'fraction_non_alphanumeric': 0.10370727673649394, 'fraction_numerical': 0.009509371554575523, 'mean_word_length': 2.0585879873551107, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1348574', 'n_tokens_mistral': 4603, 'n_tokens_neox': 4331, 'n_words': 1269}