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 new workflows into CI #148

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ca70dbe
ci: add Compressed Size workflow
rezaelahidev Aug 19, 2024
9e8cbed
ci: improve setup-node step on bundle-size
rezaelahidev Aug 19, 2024
d1b4bb2
merge: branch 'develop' into add/workflows
rezaelahidev Aug 24, 2024
c9b5431
ci: add concurrency to workflows to cancelling progress
rezaelahidev Aug 24, 2024
a60548a
Merge branch 'develop' into add/workflows
Aug 28, 2024
96a8e92
chore: modified bin/build-plugin-zip.sh with auto generated comments
Aug 28, 2024
cb72972
feat: php script to generate build-plugin-zip.sh dynamically with docs
Aug 28, 2024
020f045
ci: added build-plugin-zip workflow on Github
Aug 28, 2024
57206bc
ci: wrong trunk branch name
Aug 28, 2024
170c4d5
ci: fix typo error
Aug 28, 2024
b4f9870
ci: added Blockera Plugin Checkup workflow
rezaelahidev Aug 29, 2024
9daf519
ci: provided token for executing build-plugin-zip
rezaelahidev Aug 29, 2024
0becd6d
ci: improved plugin-check workflow
rezaelahidev Aug 29, 2024
0b490f0
Revert "ci: provided token for executing build-plugin-zip"
rezaelahidev Aug 29, 2024
3a61dae
ci: try to fix build-plugin-zip on CI
rezaelahidev Aug 29, 2024
c5436be
ci: add setup-node and turn on NO_INSTALL_NPM flag
rezaelahidev Aug 29, 2024
ee52928
ci: added setup-php custom github action
rezaelahidev Aug 29, 2024
6b948d4
ci: replace native setup-node
rezaelahidev Aug 29, 2024
2d84f31
refactor: generate-readme-text with add polyfill for str_starts_with …
rezaelahidev Aug 29, 2024
04ab71c
fix: setup-php
rezaelahidev Aug 29, 2024
3546f53
refactor: auto generator build-plugin-zip bash script
rezaelahidev Aug 30, 2024
b52d0bf
refactor: hard codes of bash script
rezaelahidev Aug 30, 2024
89884ec
docs: updated auto generating build-plugin-zip temp file
rezaelahidev Aug 30, 2024
c1986a1
ci: added new custom github action to build plugin zip
rezaelahidev Aug 30, 2024
bef553e
ci: replace build-plugin-zip custom action
rezaelahidev Aug 30, 2024
bd64d29
ci: fix bash file generator wrong path
rezaelahidev Aug 30, 2024
c0aea2f
ci: added new pattern to detect compressed size of blockera.zip
rezaelahidev Aug 30, 2024
ba1e95f
ci: added composer-options input on setup-php github action
rezaelahidev Aug 30, 2024
8f9dd5e
ci: improved build-plugin-zip workflow
rezaelahidev Aug 30, 2024
00c139e
ci: improved bundle-size workflow
rezaelahidev Aug 30, 2024
eaf040f
ci: fix setup-node
rezaelahidev Aug 30, 2024
bfdd26f
ci(plugin-check): fix exclude_checks
rezaelahidev Aug 30, 2024
fb6720f
ci(plugin-check): just check build directory
rezaelahidev Aug 30, 2024
06274dd
ci(composer-options): pass options
rezaelahidev Aug 30, 2024
c254c80
ci(plugin-check): fix wrong build directory
rezaelahidev Aug 30, 2024
b974bf1
ci(bundle-size): fix wrong action version
rezaelahidev Aug 30, 2024
9064b1b
ci(VirusTotal): added virus scan workflow
rezaelahidev Aug 30, 2024
b984521
ci(bundle-size): remove wrong inputs
rezaelahidev Aug 30, 2024
abff361
refactor: change tested up to and requires at least wp version
rezaelahidev Aug 30, 2024
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
24 changes: 24 additions & 0 deletions .github/build-plugin-zip/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 'Auto Generate build-plugin-zip.temp.sh file'
description: 'Generating temporary bash file to use of that to create blockera.zip file.'

runs:
using: 'composite'
steps:
- name: Regenerating Bash Script
run: php ./bin/generate-build-plugin-zip-sh.php > ./bin/build-plugin-zip.temp.sh
shell: bash

- name: CHMOD
run: chmod +x ./bin/build-plugin-zip.temp.sh
shell: bash

- name: Execute Created Temporary Bash Script
run: ./bin/build-plugin-zip.temp.sh
env:
NO_CHECKS: 'true'
NO_INSTALL_DEPS: 'true'
shell: bash

- name: Delete Permanently Temporary File
run: rm -rf ./bin/build-plugin-zip.temp.sh
shell: bash
41 changes: 41 additions & 0 deletions .github/setup-php/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: 'Install Composer Dependencies'
description: 'Composer Install while managing all aspects of caching.'
inputs:
php-version:
description: 'Optional. The PHP version to use. When not specified, the version is 7.4'
required: false
default: '7.4'
composer-options:
description: 'Optional. The options to use on composer install. When not specified, the options is empty'
required: false
default: ''

runs:
using: 'composite'
steps:
##
# This allows Composer dependencies to be installed using a single step.
#
# Since the tests are currently run within the Docker containers where the PHP version varies,
# the same PHP version needs to be configured for the action runner machine so that the correct
# dependency versions are installed and cached.
##
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '${{ inputs.php-version }}'
ini-file: development
coverage: none

# Ensure that Composer installs the correct versions of packages.
- name: Override PHP version in composer.json
run: composer config platform.php ${{ inputs.php-version }}
shell: bash

# Since Composer dependencies are installed using `composer update` and no lock file is in version control,
# passing a custom cache suffix ensures that the cache is flushed at least once per week.
- name: Install Composer dependencies
uses: ramsey/composer-install@v2
with:
custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F")
composer-options: '${{ inputs.composer-options }}'
303 changes: 303 additions & 0 deletions .github/workflows/build-plugin-zip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,303 @@
name: Build Blockera Plugin Zip

on:
pull_request:
push:
branches: [master]
workflow_dispatch:
inputs:
version:
description: 'rc or stable?'
required: true

# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
# The concurrency group contains the workflow name and the branch name for pull requests
# or the commit hash for any other events.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true

jobs:
compute-stable-branches:
name: Compute current and next stable release branches
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' }}
outputs:
current_stable_branch: ${{ steps.get_branches.outputs.current_stable_branch }}
next_stable_branch: ${{ steps.get_branches.outputs.next_stable_branch }}

steps:
- name: Get current and next stable release branches
id: get_branches
run: |
curl \
-H "Accept: application/vnd.github.v3+json" \
-o latest.json \
"https://api.github.com/repos/${{ github.repository }}/releases/latest"
LATEST_STABLE_TAG=$(jq --raw-output '.tag_name' latest.json)
IFS='.' read LATEST_STABLE_MAJOR LATEST_STABLE_MINOR LATEST_STABLE_PATCH <<< "${LATEST_STABLE_TAG#v}"
echo "current_stable_branch=release/${LATEST_STABLE_MAJOR}.${LATEST_STABLE_MINOR}" >> $GITHUB_OUTPUT
if [[ ${LATEST_STABLE_MINOR} == "9" ]]; then
echo "next_stable_branch=release/$((LATEST_STABLE_MAJOR + 1)).0" >> $GITHUB_OUTPUT
else
echo "next_stable_branch=release/${LATEST_STABLE_MAJOR}.$((LATEST_STABLE_MINOR + 1))" >> $GITHUB_OUTPUT
fi

bump-version:
name: Bump version
runs-on: ubuntu-latest
needs: compute-stable-branches
if: |
github.event_name == 'workflow_dispatch' && (
(
github.ref == 'refs/heads/main' ||
endsWith( github.ref, needs.compute-stable-branches.outputs.next_stable_branch )
) && (
github.event.inputs.version == 'rc' ||
github.event.inputs.version == 'stable'
) || (
startsWith( github.ref, 'refs/heads/release/' ) &&
github.event.inputs.version == 'stable'
)
)
outputs:
old_version: ${{ steps.get_version.outputs.old_version }}
new_version: ${{ steps.get_version.outputs.new_version }}
release_branch: ${{ steps.get_version.outputs.release_branch }}
release_branch_commit: ${{ steps.commit_version_bump_to_release_branch.outputs.version_bump_commit }}
main_commit: ${{ steps.commit_version_bump_to_main.outputs.version_bump_commit }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.BLOCKERA_TOKEN }}
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}

- name: Compute old and new version
id: get_version
run: |
OLD_VERSION=$(jq --raw-output '.version' package.json)
echo "old_version=${OLD_VERSION}" >> $GITHUB_OUTPUT
if [[ ${{ github.event.inputs.version }} == 'stable' ]]; then
NEW_VERSION=$(npx semver $OLD_VERSION -i patch)
else
if [[ $OLD_VERSION == *"rc"* ]]; then
NEW_VERSION=$(npx semver $OLD_VERSION -i prerelease)
else
# WordPress version guidelines: If minor is 9, bump major instead.
IFS='.' read -r -a OLD_VERSION_ARRAY <<< "$OLD_VERSION"
if [[ ${OLD_VERSION_ARRAY[1]} == "9" ]]; then
NEW_VERSION="$(npx semver $OLD_VERSION -i major)-rc.1"
else
NEW_VERSION="$(npx semver $OLD_VERSION -i minor)-rc.1"
fi
fi
fi
echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT
IFS='.' read -r -a NEW_VERSION_ARRAY <<< "$NEW_VERSION"
RELEASE_BRANCH="release/${NEW_VERSION_ARRAY[0]}.${NEW_VERSION_ARRAY[1]}"
echo "release_branch=${RELEASE_BRANCH}" >> $GITHUB_OUTPUT

- name: Configure git user name and email
run: |
git config user.name "Blockera Repository Automation"
git config user.email [email protected]

- name: Create and switch to release branch
if: |
github.event.inputs.version == 'rc' &&
! contains( steps.get_version.outputs.old_version, 'rc' )
run: git checkout -b "${{ steps.get_version.outputs.release_branch }}"

- name: Switch to release branch
if: |
github.event.inputs.version == 'stable' ||
contains( steps.get_version.outputs.old_version, 'rc' )
run: |
git fetch --depth=1 origin "${{ steps.get_version.outputs.release_branch }}"
git checkout "${{ steps.get_version.outputs.release_branch }}"

- name: Update plugin version
env:
VERSION: ${{ steps.get_version.outputs.new_version }}
run: |
cat <<< $(jq --tab --arg version "${VERSION}" '.version = $version' package.json) > package.json
cat <<< $(jq --tab --arg version "${VERSION}" '.version = $version | .packages[""].version = $version' package-lock.json) > package-lock.json
sed -i "s/${{ steps.get_version.outputs.old_version }}/${VERSION}/g" blockera.php

- name: Commit the version bump to the release branch
id: commit_version_bump_to_release_branch
run: |
git add blockera.php package.json package-lock.json
git commit -m "Bump plugin version to ${{ steps.get_version.outputs.new_version }}"
git push --set-upstream origin "${{ steps.get_version.outputs.release_branch }}"
echo "version_bump_commit=$(git rev-parse --verify --short HEAD)" >> $GITHUB_OUTPUT

- name: Fetch main
if: ${{ github.ref != 'refs/heads/main' }}
run: git fetch --depth=1 origin main

- name: Cherry-pick the version bump commit to main
id: commit_version_bump_to_main
run: |
git checkout main
git pull
MASTER_VERSION=$(jq --raw-output '.version' package.json)
if [[ ${{ steps.get_version.outputs.old_version }} == "$MASTER_VERSION" ]]; then
git cherry-pick "${{ steps.get_version.outputs.release_branch }}"
git push
echo "version_bump_commit=$(git rev-parse --verify --short HEAD)" >> $GITHUB_OUTPUT
fi

build:
name: Build Release Artifact
runs-on: ubuntu-latest
needs: bump-version
if: |
always() && (
github.event_name == 'pull_request' ||
github.event_name == 'workflow_dispatch' ||
github.repository == 'blockeraai/blockera'
)
outputs:
job_status: ${{ job.status }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ needs.bump-version.outputs.release_branch || github.ref }}
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}

- name: Setup Node.js and install dependencies
uses: ./.github/setup-node

- name: Setup PHP Composer install dependencies
uses: ./.github/setup-php
with:
composer-options: '--no-dev -o --apcu-autoloader -a'

- name: Build Plugin Zip File
uses: ./.github/build-plugin-zip

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: blockera-plugin
path: ./blockera.zip

- name: Build release notes draft
if: ${{ needs.bump-version.outputs.new_version }}
env:
VERSION: ${{ needs.bump-version.outputs.new_version }}
run: |
IFS='.' read -r -a VERSION_ARRAY <<< "${VERSION}"
MILESTONE="Blockera ${VERSION_ARRAY[0]}.${VERSION_ARRAY[1]}"
npm run other:changelog -- --milestone="$MILESTONE" --unreleased > release-notes.txt
sed -ie '1,6d' release-notes.txt
if [[ ${{ needs.bump-version.outputs.new_version }} != *"rc"* ]]; then
# Include previous RCs' release notes, if any
CHANGELOG_REGEX="=\s[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?\s="
RC_REGEX="=\s${VERSION}(-rc\.[0-9]+)?\s="
awk "/${RC_REGEX}/ {found=1;print;next} /${CHANGELOG_REGEX}/ {found=0} found" changelog.txt >> release-notes.txt
fi

- name: Upload release notes artifact
if: ${{ needs.bump-version.outputs.new_version }}
uses: actions/upload-artifact@v4
with:
name: release-notes
path: ./release-notes.txt

revert-version-bump:
name: Revert version bump if build failed
needs: [bump-version, build]
runs-on: ubuntu-latest
if: |
always() &&
( needs.build.outputs.job_status == 'failure' ) &&
needs.bump-version.outputs.release_branch_commit

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2
ref: ${{ needs.bump-version.outputs.release_branch }}
token: ${{ secrets.BLOCKERA_TOKEN }}
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}

- name: Configure git user name and email
run: |
git config user.name "Blockera Repository Automation"
git config user.email [email protected]

- name: Revert version bump commit on release branch
if: |
github.event.inputs.version == 'stable' ||
contains( needs.bump-version.outputs.old_version, 'rc' )
run: |
git revert --no-edit ${{ needs.bump-version.outputs.release_branch_commit }}
git push --set-upstream origin "${{ needs.bump-version.outputs.release_branch }}"

- name: Delete release branch if it was only just created for the RC
if: |
github.event.inputs.version == 'rc' &&
! contains( needs.bump-version.outputs.old_version, 'rc' )
run: |
git push origin :"${{ needs.bump-version.outputs.release_branch }}"

- name: Revert version bump on main
if: ${{ needs.bump-version.outputs.main_commit }}
run: |
git fetch --depth=2 origin main
git checkout main
git revert --no-edit ${{ needs.bump-version.outputs.main_commit }}
git push --set-upstream origin main

create-release:
name: Create Release Draft and Attach Asset
needs: [bump-version, build]
runs-on: ubuntu-latest

steps:
- name: Set Release Version
id: get_release_version
env:
VERSION: ${{ needs.bump-version.outputs.new_version }}
run: echo "version=$(echo $VERSION | cut -d / -f 3 | sed 's/-rc./ RC/' )" >> $GITHUB_OUTPUT

- name: Download Plugin Zip Artifact
uses: actions/download-artifact@v4
with:
name: blockera-plugin

- name: Download Release Notes Artifact
uses: actions/download-artifact@v4
with:
name: release-notes

- name: Create Release Draft
id: create_release
uses: actions/create-release@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: 'v${{ needs.bump-version.outputs.new_version }}'
release_name: ${{ steps.get_release_version.outputs.version }}
commitish: ${{ needs.bump-version.outputs.release_branch || github.ref }}
draft: true
prerelease: ${{ contains(needs.bump-version.outputs.new_version, 'rc') }}
body_path: release-notes.txt

- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./blockera.zip
asset_name: blockera.zip
asset_content_type: application/zip
Loading
Loading