Skip to content

Commit

Permalink
Merge pull request #19 from Codeinwp/feat/add-zip
Browse files Browse the repository at this point in the history
chore: add zip workflow
  • Loading branch information
HardeepAsrani authored Jan 12, 2024
2 parents 91e560c + 092a6a0 commit f82e83f
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.git
CONTRIBUTING.md
.distignore
.gitignore
.travis.yml
.jshintrc
.commitlintrc.js
docker-compose.yml
Gruntfile.js
grunt
phpcs.xml
phpcs.xml.dist
node_modules
logs
e2e-tests
cypress.json
.eslintignore
.eslintrc.js
.releaserc.yml
.gitattributes
.babelrc
.eslintrc
.github
package.json
bin
tests
phpunit.xml
npm-debug.log
package-lock.json
webpack.config.js
dist
.nvmrc
.editorconfig
artifact
composer.json
composer.lock
themeisle.enc

.idea
vendor/codeinwp/themeisle-sdk/src/Modules/Dashboard_widget.php
**/*.css.map
.DS_Store
blackfire
rollup.config.js
docker-compose.ci.yml
visual-regressions
yarn.lock
.ds_store
.storybook
stories
cypress.storybook.json
tsconfig.json
lint-staged.config.js
.stylelintrc.json
phpstan.neon
.gitkeep
assets/js/src
assets/css/src
98 changes: 98 additions & 0 deletions .github/workflows/create-build-url.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Build and publish the ZIP build file

on:
pull_request:
types: [opened, synchronize, ready_for_review]
branches-ignore:
- 'update_dependencies'
jobs:
dev-zip:
name: Build ZIP and upload to s3
if: github.event.pull_request.draft == false && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name
runs-on: ubuntu-latest
outputs:
branch-name: ${{ steps.retrieve-branch-name.outputs.branch_name }}
git-sha-8: ${{ steps.retrieve-git-sha-8.outputs.sha8 }}
steps:
- name: Check out source files
uses: actions/checkout@v2
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Configure Composer cache
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install composer deps
run: composer install --no-dev --prefer-dist --no-progress --no-suggest
- name: Install npm deps
run: npm ci
- name: Create zip
run: npm run dist
- name: Retrieve branch name
id: retrieve-branch-name
run: echo "::set-output name=branch_name::$(REF=${GITHUB_HEAD_REF:-$GITHUB_REF} && echo ${REF#refs/heads/} | sed 's/\//-/g')"
- name: Retrieve git SHA-8 string
id: retrieve-git-sha-8
run: echo "::set-output name=sha8::$(echo ${GITHUB_SHA} | cut -c1-8)"
- name: Upload Latest Version to S3
uses: jakejarvis/s3-sync-action@master
with:
args: --acl public-read --follow-symlinks --delete
env:
AWS_S3_BUCKET: ${{ secrets.AWS_DEV_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.S3_AWS_KEY_ARTIFACTS }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_AWS_SECRET_ARTIFACTS }}
SOURCE_DIR: artifact/
DEST_DIR: ${{ github.event.pull_request.base.repo.name }}-${{ steps.retrieve-branch-name.outputs.branch_name }}-${{ steps.retrieve-git-sha-8.outputs.sha8 }}/

comment-on-pr:
name: Comment on PR with links to plugin ZIPs
if: ${{ github.head_ref && github.head_ref != null }}
runs-on: ubuntu-latest
needs: dev-zip
env:
CI: true
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
outputs:
pr_number: ${{ steps.get-pr-number.outputs.num }}
comment_body: ${{ steps.get-comment-body.outputs.body }}
steps:
- name: Get PR number
id: get-pr-number
run: echo "::set-output name=num::$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')"

- name: Check if a comment was already made
id: find-comment
uses: peter-evans/find-comment@v2
with:
issue-number: ${{ steps.get-pr-number.outputs.num }}
comment-author: github-actions[bot]
body-includes: Download QuickWP - [Download]

- name: Get comment body
id: get-comment-body
run: |
body="Plugin build for ${{ github.event.pull_request.head.sha }} is ready :bellhop_bell:!
- Download QuickWP - [Download](https://verti-artifacts.s3.amazonaws.com/${{ github.event.pull_request.base.repo.name }}-${{ needs.dev-zip.outputs.branch-name }}-${{ needs.dev-zip.outputs.git-sha-8 }}/quickwp.zip)"
body="${body//$'\n'/'%0A'}"
echo "::set-output name=body::$body"
- name: Create comment on PR with links to plugin builds
if: ${{ steps.find-comment.outputs.comment-id == '' }}
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ steps.get-pr-number.outputs.num }}
body: ${{ steps.get-comment-body.outputs.body }}

- name: Update comment on PR with links to plugin builds
if: ${{ steps.find-comment.outputs.comment-id != '' }}
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body: ${{ steps.get-comment-body.outputs.body }}
24 changes: 24 additions & 0 deletions bin/dist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

BUILD_VERSION=$(node -pe "require('./package.json').version")
export BUILD_VERSION
BUILD_NAME=$(node -pe "require('./package.json').name")
export BUILD_NAME


echo "BUILD_NAME=$BUILD_NAME" >> $GITHUB_ENV
echo "BUILD_VERSION=$BUILD_VERSION" >> $GITHUB_ENV

if [ ! -d "dist" ]; then
mkdir "dist"
fi

if [ ! -d "artifact" ]; then
mkdir "artifact"
fi

rsync -rc --exclude-from ".distignore" "./" "dist/$BUILD_NAME"

cd dist
zip -r "../artifact/$BUILD_NAME" "./$BUILD_NAME/"
cd -
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"stylelint": "^14.10.0"
},
"scripts": {
"dist": "bash ./bin/dist.sh",
"lint:css": "stylelint **/*.css -i .gitignore",
"lint:css:fix": "stylelint **/*.css -i .gitignore --fix",
"lint:php": "./vendor/bin/phpcs",
Expand Down

0 comments on commit f82e83f

Please sign in to comment.