Fix the check #25
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Prepare for translation | |
on: | |
push: | |
branches: | |
- 'pre-release' | |
workflow_dispatch: | |
inputs: | |
tmate_enabled: | |
type: boolean | |
description: 'Enable "tmate" for debugging' | |
required: false | |
default: false | |
jobs: | |
check: | |
name: Check the POT file and prepare for translation | |
env: | |
# ISSUE_ASSIGNEE: wocmultimedia | |
ISSUE_ASSIGNEE: andergmartins | |
# ISSUE_CC: "@wocmultimedia, @andergmartins, @stevejburge" | |
ISSUE_CC: "@andergmartins" | |
GH_TOKEN: ${{ github.token }} | |
runs-on: ubuntu-latest | |
container: | |
image: publishpress/dev-workspace-terminal:future-free | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@master | |
- name: Setup tmate session for Debugging, if inputs.tmate_enabled is true | |
uses: mxschmitt/action-tmate@v3 | |
if: ${{ inputs.tmate_enabled }} | |
timeout-minutes: 10 | |
- name: Prepare composer | |
run: | | |
composer validate | |
composer install | |
- name: Show version of tools inside the dev-workspace | |
run: | | |
composer info:versions | |
- name: Run POT file check against the main branch | |
id: check-pot-diff | |
run: | | |
OUTPUT=$(composer check:pot-diff-md) | |
PLUGIN_VERSION="${{ steps.get-plugin-version.outputs.PLUGIN_VERSION }}" | |
echo "Checking for changes in POT file for version $PLUGIN_VERSION" | |
echo "$OUTPUT" | |
# Set output variable based on check result | |
[[ "$OUTPUT" =~ "No messages found" ]] && \ | |
echo "POT_HAS_CHANGES=false" >> $GITHUB_OUTPUT || \ | |
echo "POT_HAS_CHANGES=true" >> $GITHUB_OUTPUT | |
- name: Check if POT file has no change. If so, exit the flow | |
run: | | |
[[ "${{ steps.check-pot-diff.outputs.POT_HAS_CHANGES }}" == "false" ]] && { | |
echo "No changes found in POT file" | |
exit 0 | |
} | |
- name: Get the current version number and store it in a variable | |
id: get-plugin-version | |
run: | | |
PLUGIN_VERSION=$(pversion) | |
echo "Current version: $PLUGIN_VERSION" | |
echo "PLUGIN_VERSION=$PLUGIN_VERSION" >> $GITHUB_OUTPUT | |
- name: Build the testing package and get its url for download | |
id: build-testing-package | |
run: | | |
ZIPFILE_NAME=$(pzipfile) | |
echo "ZIPFILE_NAME=$ZIPFILE_NAME" >> $GITHUB_OUTPUT | |
composer build | |
- name: Upload zip as artifact | |
id: upload-artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ steps.build-testing-package.outputs.ZIPFILE_NAME }} | |
path: dist/${{ steps.build-testing-package.outputs.ZIPFILE_NAME }} | |
retention-days: 7 | |
- name: Handle the Github issue creation | |
id: create-issue | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const pluginVersion = process.env.PLUGIN_VERSION; | |
const output = process.env.OUTPUT; | |
const issueCC = process.env.ISSUE_CC; | |
const issueAssignee = process.env.ISSUE_ASSIGNEE; | |
const searchQuery = `POT file has changes that need to be reviewed for version ${pluginVersion} in:title is:open`; | |
const issues = await github.rest.search.issuesAndPullRequests({ | |
q: searchQuery, | |
per_page: 1 | |
}); | |
if (issues.data.total_count === 0) { | |
console.log('\nNo issue found, creating a new one'); | |
await github.rest.issues.create({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
title: `POT file has changes that need to be reviewed for version ${pluginVersion}`, | |
body: `The POT file check detected changes between the main branch and the current branch.<br />Please review and update the PO files.<br /><br />Download the testing package for this version: ${{ steps.upload-artifact.outputs.artifact-url }}<br /><br />CC: ${issueCC}<br /><br />Output of \`check:pot-diff\`:<br />${output}`, | |
labels: ['translation'], | |
assignees: [issueAssignee] | |
}); | |
} else { | |
const issueNumber = issues.data.items[0].number; | |
console.log('\nChanges found'); | |
console.log(`Commenting on issue ${issueNumber}`); | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issueNumber, | |
body: `Additional changes detected in the repository for version ${pluginVersion}. Please review the latest differences below.<br /><br />Download the testing package for this version: ${{ steps.upload-artifact.outputs.artifact-url }}<br /><br />CC: ${issueCC}<br /><br />Latest output of \`check:pot-diff\`:<br />${output}` | |
}); | |
} |