From b6196a77e68c7d95568259da2d4768e31c1cab01 Mon Sep 17 00:00:00 2001 From: tec-bot Date: Thu, 30 Jan 2025 04:12:06 +0000 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=94=84=20created=20local=20'.github/w?= =?UTF-8?q?orkflows/release-process-changelog.yml'=20from=20remote=20'temp?= =?UTF-8?q?lates/workflows/release-process-changelog.yml'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../workflows/release-process-changelog.yml | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 .github/workflows/release-process-changelog.yml diff --git a/.github/workflows/release-process-changelog.yml b/.github/workflows/release-process-changelog.yml new file mode 100644 index 0000000000..847f6b2c60 --- /dev/null +++ b/.github/workflows/release-process-changelog.yml @@ -0,0 +1,142 @@ +name: "Release: Process Changelogs" + +# This action will run when it is triggered manually +on: + workflow_dispatch: + inputs: + release-version: + description: "The release version for which the action should process the changelog (e.g. 4.5.0) (default: will try to figure it out)" + default: 'figure-it-out' + required: true + type: string + release-date: + description: "The release date in human-readable format (default: 'today')." + required: false + default: "today" + type: string + action-type: + description: "Whether this is to amend or generate the changelog entries (default: 'generate')." + required: true + default: "generate" + type: choice + options: + - amend + - generate + - amend-version + +defaults: + run: + shell: bash + +jobs: + process-changelog: + name: "Process the changelog" + runs-on: ubuntu-latest + env: + CHANGELOG_ACTION: ${{ inputs.action-type }} + RELEASE_VERSION: ${{ inputs.release-version }} + RELEASE_DATE: ${{ inputs.release-date }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} + fetch-depth: 0 + + - name: Configure PHP environment + uses: shivammathur/setup-php@v2 + with: + php-version: 7.4 + + - name: Set up Composer + run: composer install --no-progress --ignore-platform-reqs + + - name: Set Variables + id: vars + run: / + echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT + + - name: Set up Git configuration + run: | + git config --global user.email "actions@github.com" + git config --global user.name "github-actions" + + - name: Check for .puprc file and paths.versions + id: check-puprc + run: | + if [ ! -f ".puprc" ]; then + echo "Error: .puprc file not found" >> $GITHUB_STEP_SUMMARY + exit 1 + fi + if ! jq -e '.paths.versions' .puprc > /dev/null; then + echo "Error: paths.versions not found in .puprc" >> $GITHUB_STEP_SUMMARY + exit 1 + fi + + - name: Figure out Version + id: figure_out_version + run: | + if [ "$RELEASE_VERSION" == "figure-it-out" ]; then + existing_version="" + while read -r version; do + echo "Processing version info: $version" + file=$(echo "$version" | jq -r '.file') + regex=$(echo "$version" | jq -r '.regex') + + existing_version=$(grep -Po "$regex" "$file" | grep -Po '(\d+\.\d+\.\d+(\.\d+)?)') + + if [ -n "$existing_version" ]; then + echo "Release version: $existing_version" + echo "RELEASE_VERSION=$existing_version" >> $GITHUB_OUTPUT + break + fi + done < <(jq -c '.paths.versions[]' .puprc) + else + echo "Release version: $RELEASE_VERSION" + echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_OUTPUT + fi + + - name: "Format the release date" + id: format_date + run: | + RELEASE_DATE=$( date "+%Y-%m-%d" -d "$RELEASE_DATE" ) # Release date formatted as YYYY-MM-DD + echo "Release date: $RELEASE_DATE" + echo "RELEASE_DATE=$RELEASE_DATE" >> $GITHUB_OUTPUT + + - name: Create new branch + id: versions + run: | + changeBranch="task/process-changelog/${{ steps.format_date.outputs.RELEASE_DATE }}/${{ steps.figure_out_version.outputs.RELEASE_VERSION }}/${{ steps.vars.outputs.sha_short }}" + git checkout -b "$changeBranch" + git push origin "$changeBranch" + + - name: "Process changelog" + id: process_changelog + - uses: the-events-calendar/actions/.github/actions/process-changelog@main + with: + release-version: ${{ steps.figure_out_version.outputs.RELEASE_VERSION }} + release-date: ${{ steps.format_date.outputs.RELEASE_DATE }} + action-type: ${{ env.CHANGELOG_ACTION }} + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v6 + id: cpr + with: + token: ${{ secrets.GHA_BOT_TOKEN_MANAGER }} + base: ${{ github.ref }} + branch: "task/process-changelog/${{ steps.format_date.outputs.RELEASE_DATE }}/${{ steps.figure_out_version.outputs.RELEASE_VERSION }}/${{ steps.vars.outputs.sha_short }}" + title: "[BOT] Process changelog for '${{ github.head_ref || github.ref_name }}'" + body: | + This is an automated PR created by ${{ github.actor }}. + It was generated by [this GitHub Action](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}). + labels: "automation" + commit-message: | + Process changelog for ${{ github.ref }} + This is an automated PR created by ${{ github.actor }}. + Generated by: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + - name: Check outputs + if: ${{ steps.cpr.outputs.pull-request-number }} + run: | + echo "## Pull Request" >> $GITHUB_STEP_SUMMARY + echo "* Number - ${{ steps.cpr.outputs.pull-request-number }}" >> $GITHUB_STEP_SUMMARY + echo "* URL - [${{ steps.cpr.outputs.pull-request-url }}](${{ steps.cpr.outputs.pull-request-url }})" >> $GITHUB_STEP_SUMMARY From 24fa0ed548c170df26ac338ef98253063aa309b7 Mon Sep 17 00:00:00 2001 From: tec-bot Date: Thu, 30 Jan 2025 04:12:06 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=94=84=20created=20local=20'.github/w?= =?UTF-8?q?orkflows/release-prepare-branch.yml'=20from=20remote=20'templat?= =?UTF-8?q?es/workflows/release-prepare-branch.yml'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release-prepare-branch.yml | 167 +++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 .github/workflows/release-prepare-branch.yml diff --git a/.github/workflows/release-prepare-branch.yml b/.github/workflows/release-prepare-branch.yml new file mode 100644 index 0000000000..7b824884ee --- /dev/null +++ b/.github/workflows/release-prepare-branch.yml @@ -0,0 +1,167 @@ +name: Release: Prepare Branch + +on: + workflow_dispatch: + inputs: + new-branch: + description: 'Name of the new branch (e.g. release/T24.centaur)' + default: release/T24.release-name + required: true + version-bump-type: + description: 'Type of version bump' + required: true + type: choice + options: + - major (X.x.x) + - feature (x.X.x) + - maintenance (x.x.X) + - hotfix (x.x.x.X) + +jobs: + create-pull-request: + runs-on: ubuntu-latest + + steps: + - name: Print input vars to summary + run: | + echo "### Debugging Inputs" >> $GITHUB_STEP_SUMMARY + echo "- version-bump-type: \`${{ github.event.inputs['version-bump-type'] }}\`" >> $GITHUB_STEP_SUMMARY + echo "- new-branch: \`${{ github.event.inputs['new-branch'] }}\`" >> $GITHUB_STEP_SUMMARY + + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} + + - name: Set Variables + id: vars + run: | + versionBumpType="${{ github.event.inputs.version-bump-type }}" + echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT + echo "version_bump_type=${versionBumpType%% *}" >> $GITHUB_OUTPUT + + - name: Set up Git configuration + run: | + git config --global user.email "actions@github.com" + git config --global user.name "github-actions" + + - name: Check for .puprc file and paths.versions + id: check-puprc + run: | + if [ ! -f ".puprc" ]; then + echo "Error: .puprc file not found" >> $GITHUB_STEP_SUMMARY + exit 1 + fi + if ! jq -e '.paths.versions' .puprc > /dev/null; then + echo "Error: paths.versions not found in .puprc" >> $GITHUB_STEP_SUMMARY + exit 1 + fi + + - name: Create and push release branch + id: create-release-branch + run: | + newBranch="${{ github.event.inputs.new-branch }}" + if git show-ref --quiet "refs/heads/$newBranch"; then + echo "Branch $newBranch already exists, skipping creation." + git fetch origin "$newBranch" + git checkout "$newBranch" + else + git checkout -b "$newBranch" + git push origin "$newBranch" || (git fetch origin "$newBranch" && git reset --hard "origin/$newBranch") + fi + + - name: Read and apply version bump + id: versions + run: | + changeBranch="task/version-bump-${{ github.event.inputs.new-branch }}-${{ steps.vars.outputs.sha_short }}" + git checkout -b "$changeBranch" + git push origin "$changeBranch" + versionBumpType="${{ steps.vars.outputs.version_bump_type }}" + + jq -c '.paths.versions[]' .puprc | while read -r version; do + echo "Processing version info: $version" + file=$(echo "$version" | jq -r '.file') + regex=$(echo "$version" | jq -r '.regex') + + echo "## \`$file\`" >> $GITHUB_STEP_SUMMARY + if [ -f "$file" ]; then + existing_version=$(grep -Po "$regex" "$file" | grep -Po '(\d+\.\d+\.\d+(\.\d+)?)') + if [ -z "$existing_version" ]; then + echo "Error: No version found in \`$file\` using regex \`$regex\`" >> $GITHUB_STEP_SUMMARY + exit 1 + fi + echo "* Found: \`$existing_version\`" >> $GITHUB_STEP_SUMMARY + + if [ "$versionBumpType" = "hotfix" ] && [ "$file" = "package.json" ]; then + echo "Skipping version bump in \`package.json\` for \`hotfix\` mode" >> $GITHUB_STEP_SUMMARY + continue + fi + + IFS='.' read -r -a version_parts <<< "$existing_version" + + case "$versionBumpType" in + major) + version_parts[0]=$((version_parts[0] + 1)) + version_parts[1]=0 + version_parts[2]=0 + unset version_parts[3] + ;; + feature) + version_parts[1]=$((version_parts[1] + 1)) + version_parts[2]=0 + unset version_parts[3] + ;; + maintenance) + version_parts[2]=$((version_parts[2] + 1)) + unset version_parts[3] + ;; + hotfix) + if [ -z "${version_parts[3]}" ]; then + version_parts[3]=1 + else + version_parts[3]=$((version_parts[3] + 1)) + fi + ;; + esac + + new_version="${version_parts[0]}.${version_parts[1]}.${version_parts[2]}" + if [ -n "${version_parts[3]}" ]; then + new_version="$new_version.${version_parts[3]}" + fi + + echo "* Modified: \`$new_version\`" >> $GITHUB_STEP_SUMMARY + + php_regex=$(echo "$regex" | sed "s/'/\\\\'/g") + php -r "file_put_contents('$file', preg_replace('/$php_regex/', '\${1}$new_version', file_get_contents('$file')));" + + echo "new_version=$new_version" >> $GITHUB_OUTPUT + else + echo "Error: File \`$file\` not found" >> $GITHUB_STEP_SUMMARY + exit 1 + fi + done + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v6 + id: cpr + with: + token: ${{ secrets.GHA_BOT_TOKEN_MANAGER }} + base: "${{ github.event.inputs.new-branch }}" + branch: "task/version-bump-${{ github.event.inputs.new-branch }}-${{ steps.vars.outputs.sha_short }}" + title: "[BOT] Version bump for '${{ github.event.inputs.new-branch }}'" + body: | + This is an automated PR created by ${{ github.actor }}. + It was generated by [this GitHub Action](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}). + labels: "automation" + commit-message: | + Version bump for ${{ github.event.inputs.new-branch }} + + This is an automated PR created by ${{ github.actor }}. + Generated by: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + + - name: Check outputs + if: ${{ steps.cpr.outputs.pull-request-number }} + run: | + echo "## Pull Request" >> $GITHUB_STEP_SUMMARY + echo "* Number - ${{ steps.cpr.outputs.pull-request-number }}" >> $GITHUB_STEP_SUMMARY + echo "* URL - [${{ steps.cpr.outputs.pull-request-url }}](${{ steps.cpr.outputs.pull-request-url }})" >> $GITHUB_STEP_SUMMARY From c02cf24b34523be6ee78731fb2b6c045dd219815 Mon Sep 17 00:00:00 2001 From: tec-bot Date: Thu, 30 Jan 2025 04:12:06 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=94=84=20created=20local=20'.github/w?= =?UTF-8?q?orkflows/release-sync-translations.yml'=20from=20remote=20'temp?= =?UTF-8?q?lates/workflows/release-sync-translations.yml'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../workflows/release-sync-translations.yml | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 .github/workflows/release-sync-translations.yml diff --git a/.github/workflows/release-sync-translations.yml b/.github/workflows/release-sync-translations.yml new file mode 100644 index 0000000000..2615877032 --- /dev/null +++ b/.github/workflows/release-sync-translations.yml @@ -0,0 +1,96 @@ +name: Release: Sync Translations + +on: + workflow_dispatch: # Allows you to run this workflow manually from the Actions tab + workflow_call: + secrets: + TRANSLATIONS_DEPLOY_HOST: + required: true + TRANSLATIONS_DEPLOY_USER: + required: true + TRANSLATIONS_DEPLOY_SSH_KEY: + required: true + TRANSLATIONS_DEPLOY_POT_LOCATION: + required: true + +jobs: + sync-translations: + name: 🔁 Sync Translations + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.sha }} + + - name: Set Variables + id: vars + run: | + branch_name="${{ github.head_ref || github.ref_name }}" + should_glotpress=0 + if [[ "$branch_name" =~ ^release/.* || "$branch_name" == "master" || "$branch_name" == "main" ]]; then + should_glotpress=1 + fi + echo "should_glotpress=$should_glotpress" >> $GITHUB_OUTPUT + echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT + + - name: Fetch Plugin Slug from .puprc + id: puprc + run: | + plugin_slug=$(jq '.i18n | map(select(.url | contains("translations.stellarwp.com")) | .slug) | first' .puprc) + echo "plugin_slug=$plugin_slug" >> $GITHUB_ENV + echo "plugin_slug=$plugin_slug" >> $GITHUB_OUTPUT + echo "## Plugin Slug: \`$plugin_slug\`" >> $GITHUB_STEP_SUMMARY + + - uses: the-events-calendar/actions/.github/actions/generate-pot@main + id: generate-pot + with: + plugin_path: ${{ github.workspace }} + pot_path: ${{github.workspace}}/lang/${{ steps.puprc.outputs.plugin_slug }}.pot + + - uses: the-events-calendar/actions/.github/actions/push-translations@main + id: push-translations + if: steps.vars.outputs.should_glotpress == '1' + with: + plugin_slug: ${{ steps.puprc.outputs.plugin_slug }} + pot_path: lang/${{ steps.puprc.outputs.plugin_slug }}.pot + env: + TRANSLATIONS_DEPLOY_HOST: ${{ secrets.TRANSLATIONS_DEPLOY_HOST }} + TRANSLATIONS_DEPLOY_USER: ${{ secrets.TRANSLATIONS_DEPLOY_USER }} + TRANSLATIONS_DEPLOY_SSH_KEY: ${{ secrets.TRANSLATIONS_DEPLOY_SSH_KEY }} + TRANSLATIONS_DEPLOY_POT_LOCATION: ${{ secrets.TRANSLATIONS_DEPLOY_POT_LOCATION }} + + - uses: the-events-calendar/actions/.github/actions/add-changelog@main + id: add-changelog-entry + if: steps.vars.outputs.should_glotpress == '1' + with: + file: "task-i18n-${{ steps.vars.outputs.sha_short }}" + significance: patch + type: language + entry: "${{ steps.push-translations.outputs.glotpress-result }}" + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v7 + id: create-pull-request + with: + token: ${{ secrets.GHA_BOT_TOKEN_MANAGER }} + base: ${{ github.head_ref || github.ref_name }} + branch: "task/i18n-update-${{ github.head_ref || github.ref_name }}-with-${{ steps.vars.outputs.sha_short }}" + title: "[BOT] Generate POT file for '${{ github.head_ref || github.ref_name }}'" + assignees: ${{ github.actor }} + reviewers: the-events-calendar/engineers + body: | + This is an automated PR created by ${{ github.actor }}. + It was generated by [this GitHub Action](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}). + labels: "automation" + commit-message: | + :symbols: Updating .pot file and add language changelog for ${{ github.sha }} + + This is an automated PR created by ${{ github.actor }}. + Generated by: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + + - name: Check outputs + if: ${{ steps.create-pull-request.outputs.pull-request-number }} + run: | + echo "## Pull Request" >> $GITHUB_STEP_SUMMARY + echo "* Number - ${{ steps.create-pull-request.outputs.pull-request-number }}" >> $GITHUB_STEP_SUMMARY + echo "* URL - [${{ steps.create-pull-request.outputs.pull-request-url }}](${{ steps.create-pull-request.outputs.pull-request-url }})" >> $GITHUB_STEP_SUMMARY