forked from fairpm/fair-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (74 loc) · 2.86 KB
/
generate-pot-pr.yml
File metadata and controls
87 lines (74 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: Generate POT PR
on:
workflow_dispatch:
push:
branches:
- main
jobs:
generate-pot:
name: Generate POT PR
if: github.repository == ${{ github.event.repository.full_name }}
permissions:
contents: write
pull-requests: write
env:
BRANCH_NAME: generate-pot
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v4
- name: Set up PHP environment
uses: shivammathur/setup-php@v2
with:
php-version: "7.4"
- name: Setup WP-CLI
uses: godaddy-wordpress/setup-wp-cli@1
- name: Configure git user
run: |
git config user.name ${{ github.actor }}
git config user.email ${{ github.actor }}@users.noreply.github.com
- name: Check if remote branch exists
run: echo "REMOTE_BRANCH_EXISTS=$([[ -z $(git ls-remote --heads origin ${BRANCH_NAME}) ]] && echo "0" || echo "1")" >> $GITHUB_ENV
- name: Create branch to base pull request on
if: env.REMOTE_BRANCH_EXISTS == 0
run: |
git checkout -b ${BRANCH_NAME}
- name: Fetch existing branch to add commits to
if: env.REMOTE_BRANCH_EXISTS == 1
run: |
git fetch --all --prune
git checkout ${BRANCH_NAME}
git pull --no-rebase
- name: Generate POT
run: |
wp i18n make-pot . "./languages/fair.pot" --headers='{"Report-Msgid-Bugs-To":"https://github.com/${{ github.event.repository.full_name }}/issues"}'
- name: Check if there are changes
run: echo "CHANGES_DETECTED=$([[ -z $(git diff --ignore-matching-lines='^"POT-Creation-Date') ]] && echo "0" || echo "1")" >> $GITHUB_ENV
- name: Commit changes
if: env.CHANGES_DETECTED == 1
run: |
git add "./languages/fair.pot"
git commit -s -m "Generate POT - $(date +'%Y-%m-%d')"
git push origin ${BRANCH_NAME}
- name: Create pull request
if: env.CHANGES_DETECTED == 1 && env.REMOTE_BRANCH_EXISTS == 0
run: |
TITLE="Generate POT - $(date +'%Y-%m-%d-%H%M%S')"
BODY="Updated translation files."
echo "Checking for any existing Generate POT PRs..."
gh pr list \
--head ${BRANCH_NAME} \
--repo ${{ github.repository }} \
--state open \
--json number,headRefName \
--jq '.[] | select(.headRefName == "'${BRANCH_NAME}'") | .number' | \
xargs -r -I {} gh pr close {} \
--repo ${{ github.repository }} \
--comment "Closing this PR in favor of ${TITLE}."
gh pr create \
--base ${{ github.event.repository.default_branch }} \
--title "${TITLE}" \
--head ${BRANCH_NAME} \
--body "${BODY}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}