Skip to content

Commit

Permalink
Split into jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
andergmartins committed Nov 20, 2024
1 parent 692a62c commit 7c4b46b
Showing 1 changed file with 54 additions and 60 deletions.
114 changes: 54 additions & 60 deletions .github/workflows/prepare-for-translation.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: Prepare for translation
on:
push:
branches:
- 'pre-release'

branches: ['pre-release']
workflow_dispatch:
inputs:
tmate_enabled:
Expand All @@ -13,112 +11,108 @@ on:
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 }}
setup:
name: Setup and Check POT
runs-on: ubuntu-latest
container:
image: publishpress/dev-workspace-terminal:future-free
outputs:
pot_has_changes: ${{ steps.check-pot-diff.outputs.POT_HAS_CHANGES }}
plugin_version: ${{ steps.get-plugin-version.outputs.PLUGIN_VERSION }}
steps:
- name: Checkout the repository
uses: actions/checkout@master
- uses: actions/checkout@master

- name: Setup tmate session for Debugging, if inputs.tmate_enabled is true
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
if: ${{ inputs.tmate_enabled }}
timeout-minutes: 10

- name: Prepare composer
- name: Setup composer
run: |
composer validate
composer install
composer info:versions
- name: Show version of tools inside the dev-workspace
- name: Get plugin version
id: get-plugin-version
run: |
composer info:versions
PLUGIN_VERSION=$(pversion)
echo "PLUGIN_VERSION=$PLUGIN_VERSION" >> $GITHUB_OUTPUT
- name: Run POT file check against the main branch
- name: Check POT differences
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
echo "OUTPUT=$OUTPUT" >> $GITHUB_OUTPUT
[[ "$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
build:
needs: setup
if: needs.setup.outputs.pot_has_changes == 'true'
runs-on: ubuntu-latest
container:
image: publishpress/dev-workspace-terminal:future-free
outputs:
zipfile_name: ${{ steps.build-package.outputs.ZIPFILE_NAME }}
steps:
- uses: actions/checkout@master

- name: Build the testing package and get its url for download
id: build-testing-package
- name: Build package
id: build-package
run: |
ZIPFILE_NAME=$(pzipfile)
echo "ZIPFILE_NAME=$ZIPFILE_NAME" >> $GITHUB_OUTPUT
composer build
- name: Upload zip as artifact
id: upload-artifact
- name: 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 }}
name: ${{ steps.build-package.outputs.ZIPFILE_NAME }}
path: dist/${{ steps.build-package.outputs.ZIPFILE_NAME }}
retention-days: 7

- name: Handle the Github issue creation
id: create-issue
create-issue:
needs: [setup, build]
if: needs.setup.outputs.pot_has_changes == 'true'
runs-on: ubuntu-latest
env:
ISSUE_ASSIGNEE: andergmartins
ISSUE_CC: "@andergmartins"
GH_TOKEN: ${{ github.token }}
PLUGIN_VERSION: ${{ needs.setup.outputs.plugin_version }}
steps:
- name: Create or update 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 searchQuery = `POT file has changes that need to be reviewed for version ${process.env.PLUGIN_VERSION} in:title is:open`;
const issues = await github.rest.search.issuesAndPullRequests({
q: searchQuery,
per_page: 1
});
const body = `The POT file check detected changes between the main branch and the current branch.
\nPlease review and update the PO files.
\nDownload the testing package for this version: ${{ steps.upload-artifact.outputs.artifact-url }}
\nCC: ${process.env.ISSUE_CC}
\nOutput of \`check:pot-diff\`: ${process.env.OUTPUT}`;
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}`,
title: `POT file has changes that need to be reviewed for version ${process.env.PLUGIN_VERSION}`,
body,
labels: ['translation'],
assignees: [issueAssignee]
assignees: [process.env.ISSUE_ASSIGNEE]
});
} 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}`
issue_number: issues.data.items[0].number,
body: `Additional changes detected. ${body}`
});
}

0 comments on commit 7c4b46b

Please sign in to comment.