Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an automated zip workflow #6862

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions .github/workflows/automated-zip-to-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: Automated Zip to PR

on:
issues:
types: [ "opened", "edited" ]

issue_comment:
type: [ "created", "edited" ]

jobs:

extrakt:

# We don't do anything on pull requests, which are also considered issues
if: ${{ !github.event.issue.pull_request }}

runs-on: ubuntu-latest

steps:

# Only do these if the target is the ISSUE not a COMMENT on the issue
- name: Extract Zip URL (body)
uses: actions-ecosystem/action-regex-match@v2
if: ${{ !github.event.comment.body }}
id: match-url
with:
text: ${{ github.event.issue.body }}
regex: '\((.*?\.zip)\)'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The action triggers for any new issue created and creates PRs if it has a Zip attached.

Trigger the action on issues that are having a special label. like New Theme may be.


- name: Extract Zip Filename (body)
uses: actions-ecosystem/action-regex-match@v2
if: ${{ !github.event.comment.body }}
id: match-filename
with:
text: ${{ github.event.issue.body }}
regex: '\(.*\/(.*?\.zip)\)'

# We do this one ALWAYS so we can compare the issue zip name to the comment zip name
- name: Extract Theme Name (body)
uses: actions-ecosystem/action-regex-match@v2
id: match-theme-name
with:
text: ${{ github.event.issue.body }}
regex: '\(.*\/(.*?)\.zip\)'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will be nice to iterate later to bring THEME_NAME from style.css instead of zip name. (if there is no such name it can fallback to zip name)


- name: Define Variables (body)
if: ${{ !github.event.comment.body }}
run: |
echo "ZIP_URL=${{ steps.match-url.outputs.group1 }}" >> $GITHUB_ENV
echo "ZIP_FILENAME=${{ steps.match-filename.outputs.group1 }}" >> $GITHUB_ENV
echo "THEME_NAME=${{ steps.match-theme-name.outputs.group1 }}" >> $GITHUB_ENV
echo "BRANCH_NAME=auto/${{ steps.match-theme-name.outputs.group1 }}" >> $GITHUB_ENV
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the branch name is derived from the zip name,
when zip name changes on edit ex: theme-name to theme-name(1),
it creates a fresh branch and a new PR instead of updating existing one.

Also, it fails to create PR for zip name with spaces.


# Only do these if the target is a COMMENT on the issue
- name: Extract Zip URL (comment)
uses: actions-ecosystem/action-regex-match@v2
if: ${{ github.event.comment.body }}
id: match-url-comment
with:
text: ${{ github.event.comment.body }}
regex: '\((.*?\.zip)\)'

- name: Extract Zip Filename (comment)
uses: actions-ecosystem/action-regex-match@v2
if: ${{ github.event.comment.body }}
id: match-filename-comment
with:
text: ${{ github.event.comment.body }}
regex: '\(.*\/(.*?\.zip)\)'

- name: Extract Theme Name (comment)
uses: actions-ecosystem/action-regex-match@v2
if: ${{ github.event.comment.body }}
id: match-theme-name-comment
with:
text: ${{ github.event.comment.body }}
regex: '\(.*\/(.*?)\.zip\)'
Comment on lines +55 to +77
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It triggers for any comment made on any issue. It should also be restricted only to issues that have special label.


# We only do this one if the BODY name matches the COMMENT name
- name: Define Variables (comment)
if: ${{ github.event.comment.body && steps.match-theme-name.outputs.group1 == steps.match-theme-name-comment.outputs.group1 }}
run: |
echo "ZIP_URL=${{ steps.match-url-comment.outputs.group1 }}" >> $GITHUB_ENV
echo "ZIP_FILENAME=${{ steps.match-filename-comment.outputs.group1 }}" >> $GITHUB_ENV
echo "THEME_NAME=${{ steps.match-theme-name-comment.outputs.group1 }}" >> $GITHUB_ENV
echo "BRANCH_NAME=auto/${{ steps.match-theme-name-comment.outputs.group1 }}" >> $GITHUB_ENV

# All the rest of these actions will only run if there's a $ZIP_URL defined (otherwise the content doesn't fit our criteria)

- uses: actions/checkout@v3
if: ${{ env.ZIP_URL }}
with:
fetch-depth: 0

- name: Download Zip & Push to Branch
if: ${{ env.ZIP_URL }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git checkout $BRANCH_NAME || git checkout -b $BRANCH_NAME
wget $ZIP_URL
unzip -o -qq ./$ZIP_FILENAME -d ./$THEME_NAME
sudo chown -R $USER:$USER .
sudo rm ./$ZIP_FILENAME
git config user.name github-actions
git config user.email github-actions@github.com
git config --global --add --bool push.autoSetupRemote true
git add --all
git commit -m "Automated Theme Change: [$THEME_NAME]"
git push origin $BRANCH_NAME

- name: Create Pull Request
if: ${{ env.ZIP_URL }}
uses: repo-sync/pull-request@v2
with:
destination_branch: "trunk"
source_branch: "${{ env.BRANCH_NAME }}"
pr_title: "Automated Theme Change: [${{ env.THEME_NAME }}]"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For title, I think its good avoid automation keyword. I suggest something like Add new theme: THEME_NAME

Suggested change
pr_title: "Automated Theme Change: [${{ env.THEME_NAME }}]"
pr_title: "Add new theme: ${{ env.THEME_NAME }}"

pr_body: |
**Automated Theme Change for: [${{ env.THEME_NAME }}]**

Closes: #${{ github.event.issue.number }}

_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add pr_reviewer (Theam) and pr_assignee (self) ?