Skip to content

Commit

Permalink
update ci (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjaudiomv authored Oct 13, 2022
1 parent d1218a7 commit a745b45
Show file tree
Hide file tree
Showing 19 changed files with 331 additions and 74 deletions.
15 changes: 11 additions & 4 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
composer.json export-ignore
.travis.yml export-ignore
.gitignore export-ignore
.editorconfig export-ignore
.gitattributes export-ignore

.gitignore export-ignore
composer.json export-ignore
composer.lock export-ignore
Dockerfile export-ignore
docker-compose.yml export-ignore
Makefile export-ignore
/assets export-ignore
/docs export-ignore
/.github export-ignore
.phpcs.xml export-ignore
81 changes: 71 additions & 10 deletions .github/workflows/latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,91 @@ on:
branches: [ 'master' ]

jobs:
deploy-bmlt-versions-latest:
lint:
runs-on: ubuntu-latest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
steps:
- name: Check out code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
id: install-dependencies
run: make composer

- name: PHPCS checker
id: php-codesniffer
run: make lint

- uses: act10ns/slack@v1
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
channel: '#bmlt-versions'
if: failure()

deploy:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
S3_BUCKET: archives.bmlt.app
S3_KEY: bmlt-versions
BUILD_DIR: build
DIST_DIR_S3: dist/s3
PLUGIN: "bmlt-versions"
needs: [ lint ]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
id: code-checkout

- name: Prepare zip file
- name: Prepare to deploy
run: |
export ARTIFACT_FILE=bmlt-versions
export ARTIFACT_FILENAME=bmlt-versions.zip
echo "ARTIFACT_FILENAME=${ARTIFACT_FILENAME}" >> $GITHUB_ENV
echo ${GITHUB_SHA} > ${ARTIFACT_FILE}/build.txt
zip -r ${ARTIFACT_FILENAME} ${ARTIFACT_FILE}
export FILENAME=${PLUGIN}-build-${GITHUB_RUN_NUMBER}-${GITHUB_SHA}
export ZIP_FILENAME=$FILENAME.zip
echo "ZIP_FILENAME=${ZIP_FILENAME}" >> $GITHUB_ENV
make build
mkdir -p ${DIST_DIR_S3} && cp ${BUILD_DIR}/${ZIP_FILENAME} ${DIST_DIR_S3}/${ZIP_FILENAME}
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/github-actions/gh-ci-s3-artifact
role-session-name: gh-actions-bmlt-versions
role-session-name: gh-actions-${{ env.PLUGIN }}
aws-region: us-east-1

- name: copy artifact to s3
run: |
aws s3 cp ${ARTIFACT_FILENAME} s3://${{ secrets.S3_BUCKET }}/bmlt-versions/bmlt-versions-build${GITHUB_RUN_NUMBER}-${GITHUB_SHA}.zip
aws s3 cp $DIST_DIR_S3/$ZIP_FILENAME s3://$S3_BUCKET/$S3_KEY/$ZIP_FILENAME
- name: Publish Release to Latest WP
id: publish_latest
uses: bmlt-enabled/wordpress-releases-github-action@v1
with:
file: ${{ env.DIST_DIR_S3 }}/${{ env.ZIP_FILENAME }}
s3_key: ${{ env.S3_KEY }}
aws_account_id: ${{ secrets.AWS_ACCOUNT_ID }}

- uses: act10ns/slack@v1
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
channel: '#bmlt-versions'
if: failure()
8 changes: 4 additions & 4 deletions .github/workflows/pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
id: code-checkout

- name: Validate composer.json and composer.lock
Expand All @@ -17,7 +17,7 @@ jobs:

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
Expand All @@ -27,8 +27,8 @@ jobs:
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
id: install-dependencies
run: composer install --prefer-dist --no-progress --no-suggest
run: make composer

- name: PHPCS checker
id: php-codesniffer
run: vendor/squizlabs/php_codesniffer/bin/phpcs --warning-severity=6 --standard=PSR2 --ignore=vendor --extensions=php --report=summary ./
run: make lint
87 changes: 66 additions & 21 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,76 @@ name: 'release'

on:
push:
tags: ['*']
tags: [ '*' ]

jobs:
deploy-bmlt-versions-release:
lint:
runs-on: ubuntu-latest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
steps:
- uses: actions/checkout@v2
- name: Check out code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
id: install-dependencies
run: make composer

- name: PHPCS checker
id: php-codesniffer
run: make lint

- uses: act10ns/slack@v1
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
channel: '#bmlt-versions'
if: failure()

package:
runs-on: ubuntu-latest
env:
BUILD_DIR: "build"
DIST_DIR_GITHUB: "dist/github"
GITHUB_RELEASE_FILENAME: "bmlt-versions.zip"
PLUGIN: "bmlt-versions"
MAINFILE: "bmlt-versions.php"
needs: [ lint ]
steps:
- uses: actions/checkout@v3
id: code-checkout

- name: Prepare zip file
- name: Build package
id: build-package
run: |
export ARTIFACT_FILE=bmlt-versions
export ARTIFACT_FILENAME=bmlt-versions.zip
echo "ARTIFACT_FILENAME=${ARTIFACT_FILENAME}" >> $GITHUB_ENV
echo ${GITHUB_SHA} > ${ARTIFACT_FILE}/build.txt
zip -r ${ARTIFACT_FILENAME} ${ARTIFACT_FILE}
curl -sLO https://raw.githubusercontent.com/bmlt-enabled/release-notes-tool/master/gh-release-notes.sh
export ZIP_FILENAME=${PLUGIN}-build${GITHUB_RUN_NUMBER}-${GITHUB_SHA}.zip
find ./ -type d | xargs chmod 755
find ./ -name '*.php' | xargs chmod 644
echo ${GITHUB_SHA} > build.txt
make build
zip $ZIP_FILENAME build.txt
mv $ZIP_FILENAME ${PLUGIN}-${GITHUB_REF##*/}.zip
mkdir -p $DIST_DIR_GITHUB && cp $BUILD_DIR/$ZIP_FILENAME $DIST_DIR_GITHUB/$GITHUB_RELEASE_FILENAME
curl -LO https://raw.githubusercontent.com/bmlt-enabled/release-notes-tool/master/gh-release-notes.sh
chmod +x gh-release-notes.sh
./gh-release-notes.sh bmlt-versions/readme.txt "wp"
- name: Prepare artifact metadata
id: prepare_artifact_metadata
run: |
echo ::set-output name=ARTIFACT_PATH::./${ARTIFACT_FILENAME}
echo ::set-output name=ARTIFACT_NAME::${ARTIFACT_FILENAME}
./gh-release-notes.sh readme.txt "wp"
echo "ARTIFACT_PATH=./${PLUGIN}-${GITHUB_REF##*/}.zip" >> $GITHUB_ENV
echo "ARTIFACT_NAME=${PLUGIN}-${GITHUB_REF##*/}.zip" >> $GITHUB_ENV
- name: Release beta
if: contains(github.ref, 'beta')
Expand All @@ -48,8 +93,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.beta_release.outputs.upload_url }}
asset_path: ${{ steps.prepare_artifact_metadata.outputs.ARTIFACT_PATH }}
asset_name: ${{ steps.prepare_artifact_metadata.outputs.ARTIFACT_NAME }}
asset_path: ${{ env.ARTIFACT_PATH }}
asset_name: ${{ env.ARTIFACT_NAME }}
asset_content_type: application/zip

- name: Release stable
Expand All @@ -73,6 +118,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.stable_release.outputs.upload_url }}
asset_path: ${{ steps.prepare_artifact_metadata.outputs.ARTIFACT_PATH }}
asset_name: ${{ steps.prepare_artifact_metadata.outputs.ARTIFACT_NAME }}
asset_path: ${{ env.ARTIFACT_PATH }}
asset_name: ${{ env.ARTIFACT_NAME }}
asset_content_type: application/zip
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
.project
.settings/*
.vscode/*
.DS_Store
.idea
*.lock
logs/
vendor/
logs/
build/
47 changes: 47 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version='1.0'?>
<ruleset name='BMLT'>
<description>The BMLT Coding Standards</description>
<!--
If no files or directories are specified on the command line
your custom standard can specify what files should be checked
instead.
Note that specifying any file or directory path
on the command line will ignore all file tags.
-->
<file>.</file>

<!--
You can hard-code command line values into your custom standard.
Note that this does not work for the command line values:
-v[v][v], -l, -d, -sniffs and -standard
The following tags are equivalent to the command line arguments:
-p
-->
<arg name='encoding' value='utf-8'/>
<arg name='extensions' value='php'/>
<arg name='warning-severity' value='6'/>
<arg name="report" value="full"/>
<arg name="parallel" value="4" />
<arg value='s'/>

<!--
You can hard-code custom php.ini settings into your custom standard.
The following tag sets the memory limit to 64M.
-->
<ini name="memory_limit" value="128M"/>

<!--
You can hard-code ignore patterns directly into your
custom standard so you don't have to specify the
patterns on the command line.
-->
<exclude-pattern>vendor/*</exclude-pattern>

<!--
You can add specific global ignores to different
rules here.
-->
<rule ref='PSR2'></rule>
<rule ref="PSR1"></rule>
</ruleset>
27 changes: 11 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
FROM wordpress:5.3.2-php7.2-apache
FROM wordpress:6.0.2-php8.0-apache

RUN apt-get update && \
apt-get install -y --no-install-recommends ssl-cert && \
rm -r /var/lib/apt/lists/* && \
a2enmod ssl rewrite expires && \
a2ensite default-ssl

ENV PHP_INI_PATH "/usr/local/etc/php/php.ini"
ENV PHP_INI_PATH /usr/local/etc/php/php.ini
ENV PHP_XDEBUG_ENABLED: 1

RUN echo "zend_extension=$(find /usr/lib/php/ -name xdebug.so)" >> ${PHP_INI_PATH} \
&& echo "xdebug.mode=coverage,debug" >> ${PHP_INI_PATH} \
&& echo "xdebug.client_port=9003" >> ${PHP_INI_PATH} \
&& echo "xdebug.client_host=host.docker.internal" >> ${PHP_INI_PATH} \
&& echo "xdebug.start_with_request=yes" >> ${PHP_INI_PATH} \
&& echo "xdebug.log=/tmp/xdebug.log" >> ${PHP_INI_PATH} \
&& echo "xdebug.idekey=IDE_DEBUG" >> ${PHP_INI_PATH}

RUN pecl install xdebug-2.6.1 \
&& docker-php-ext-enable xdebug \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" >> ${PHP_INI_PATH} \
&& echo "xdebug.remote_port=9000" >> ${PHP_INI_PATH} \
&& echo "xdebug.remote_enable=1" >> ${PHP_INI_PATH} \
&& echo "xdebug.remote_connect_back=0" >> ${PHP_INI_PATH} \
&& echo "xdebug.remote_host=docker.for.mac.localhost" >> ${PHP_INI_PATH} \
&& echo "xdebug.idekey=IDEA_DEBUG" >> ${PHP_INI_PATH} \
&& echo "xdebug.remote_autostart=1" >> ${PHP_INI_PATH} \
&& echo "xdebug.remote_log=/tmp/xdebug.log" >> ${PHP_INI_PATH} \
&& echo "xdebug.profiler_enable_trigger=1" >> ${PHP_INI_PATH} \
&& echo "log_errors = On" >> ${PHP_INI_PATH} \
&& echo "error_reporting = E_ALL" >> ${PHP_INI_PATH} \
&& echo "error_log=/var/www/php_error.log" >> ${PHP_INI_PATH}

EXPOSE 80
EXPOSE 443
26 changes: 17 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
COMMIT := $(shell git rev-parse --short=8 HEAD)
ZIP_FILENAME := $(or $(ZIP_FILENAME),"bmlt-build-file.zip")
BUILD_DIR := $(or $(BUILD_DIR),"build")
VENDOR_AUTOLOAD := vendor/autoload.php

help: ## Print the help documentation
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: build
build: ## Build
git archive --format=zip --output=${ZIP_FILENAME} $(COMMIT)
mkdir ${BUILD_DIR} && mv ${ZIP_FILENAME} ${BUILD_DIR}/

.PHONY: clean
clean: ## clean
rm -rf build dist

$(VENDOR_AUTOLOAD):
composer install
composer install --prefer-dist --no-progress --no-suggest

.PHONY: composer
composer: $(VENDOR_AUTOLOAD) ## Runs composer install

.PHONY: dev
run: ## Docker Run
docker-compose up --build

.PHONY: lint
lint: composer ## Lint
vendor/squizlabs/php_codesniffer/bin/phpcs --warning-severity=6 --standard=PSR2 --ignore=vendor --extensions=php --report=full .
lint: composer ## PHP Lint
vendor/squizlabs/php_codesniffer/bin/phpcs

.PHONY: lint-fix
lint-fix: composer ## Lint Fix
vendor/squizlabs/php_codesniffer/bin/phpcbf --warning-severity=6 --standard=PSR2 --ignore=vendor --extensions=php --report=full .
lint-fix: composer ## PHP Lint Fix
vendor/squizlabs/php_codesniffer/bin/phpcbf
Loading

0 comments on commit a745b45

Please sign in to comment.