Skip to content

Commit

Permalink
1.0.0 - Extracted reusable sub-workflows (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: ponlawat-w <[email protected]>
  • Loading branch information
Ponlawat W and ponlawat-w authored Nov 4, 2023
1 parent 1993b7e commit ddb6af7
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 120 deletions.
56 changes: 48 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,69 @@ on:
type: string
default: ${{ github.ref }}
widget-backgroundcolour-branch:
description: Branch of background colour widget
description: Branch of background colour widget, latest release will be used if not provided
type: string
default: ''
widget-fontface-branch:
description: Branch of font face widget
description: Branch of font face widget, latest release will be used if not provided
type: string
default: ''
widget-fontsize-branch:
description: Branch of font size widget
description: Branch of font size widget, latest release will be used if not provided
type: string
default: ''
widget-textcolour-branch:
description: Branch of text colour widget
description: Branch of text colour widget, latest release will be used if not provided
type: string
default: ''
outputs:
widget-backgroundcolour-branch:
description: Branch of background colour widget
value: ${{ jobs.set-widget-versions.outputs.widget-backgroundcolour-branch }}
widget-fontface-branch:
description: Branch of font face widget
value: ${{ jobs.set-widget-versions.outputs.widget-fontface-branch }}
widget-fontsize-branch:
description: Branch of font size widget
value: ${{ jobs.set-widget-versions.outputs.widget-fontsize-branch }}
widget-textcolour-branch:
description: Branch of text colour widget
value: ${{ jobs.set-widget-versions.outputs.widget-textcolour-branch }}

jobs:

default-widget-versions:
name: Get default widget versions
uses: ./.github/workflows/default-widget-versions.yml

set-widget-versions:
name: Set widget versions
needs: default-widget-versions
runs-on: ubuntu-latest
outputs:
widget-backgroundcolour-branch: ${{ steps.get-widgets.outputs.WIDGET-BACKGROUNDCOLOUR-BRANCH }}
widget-fontface-branch: ${{ steps.get-widgets.outputs.WIDGET-FONTFACE-BRANCH }}
widget-fontsize-branch: ${{ steps.get-widgets.outputs.WIDGET-FONTSIZE-BRANCH }}
widget-textcolour-branch: ${{ steps.get-widgets.outputs.WIDGET-TEXTCOLOUR-BRANCH }}
steps:
- id: get-widgets
run: |
echo WIDGET-BACKGROUNDCOLOUR-BRANCH="${{ inputs.widget-backgroundcolour-branch || needs.default-widget-versions.outputs.widget-backgroundcolour-branch }}"
echo WIDGET-FONTFACE-BRANCH="${{ inputs.widget-fontface-branch || needs.default-widget-versions.outputs.widget-fontface-branch }}"
echo WIDGET-FONTSIZE-BRANCH="${{ inputs.widget-fontsize-branch || needs.default-widget-versions.outputs.widget-fontsize-branch }}"
echo WIDGET-TEXTCOLOUR-BRANCH="${{ inputs.widget-textcolour-branch || needs.default-widget-versions.outputs.widget-textcolour-branch }}"
echo WIDGET-BACKGROUNDCOLOUR-BRANCH="${{ inputs.widget-backgroundcolour-branch || needs.default-widget-versions.outputs.widget-backgroundcolour-branch }}" >> $GITHUB_OUTPUT
echo WIDGET-FONTFACE-BRANCH="${{ inputs.widget-fontface-branch || needs.default-widget-versions.outputs.widget-fontface-branch }}" >> $GITHUB_OUTPUT
echo WIDGET-FONTSIZE-BRANCH="${{ inputs.widget-fontsize-branch || needs.default-widget-versions.outputs.widget-fontsize-branch }}" >> $GITHUB_OUTPUT
echo WIDGET-TEXTCOLOUR-BRANCH="${{ inputs.widget-textcolour-branch || needs.default-widget-versions.outputs.widget-textcolour-branch }}" >> $GITHUB_OUTPUT
matrix-test:

name: Test M${{ (matrix.moodle == 'MOODLE_402_STABLE' && '4.2') || (matrix.moodle == 'MOODLE_403_STABLE' && '4.3') || matrix.moodle }} P${{ matrix.php }} ${{ matrix.db }}
runs-on: ubuntu-latest

needs: set-widget-versions

strategy:
fail-fast: true
matrix:
Expand Down Expand Up @@ -73,10 +113,10 @@ jobs:
php: ${{ matrix.php }}
db: ${{ matrix.db }}
accessibility-branch: ${{ inputs.accessibility-branch }}
widget-backgroundcolour-branch: ${{ inputs.widget-backgroundcolour-branch }}
widget-fontface-branch: ${{ inputs.widget-fontface-branch }}
widget-fontsize-branch: ${{ inputs.widget-fontsize-branch }}
widget-textcolour-branch: ${{ inputs.widget-textcolour-branch }}
widget-backgroundcolour-branch: ${{ needs.set-widget-versions.outputs.widget-backgroundcolour-branch }}
widget-fontface-branch: ${{ needs.set-widget-versions.outputs.widget-fontface-branch }}
widget-fontsize-branch: ${{ needs.set-widget-versions.outputs.widget-fontsize-branch }}
widget-textcolour-branch: ${{ needs.set-widget-versions.outputs.widget-textcolour-branch }}

- name: PHP Lint
if: ${{ !cancelled() }}
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/default-widget-versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Get Widget Versions
on:
workflow_call:
outputs:
widget-backgroundcolour-branch:
description: Branch name of background colour widget
value: ${{ jobs.widget-versions.outputs.widget-backgroundcolour-branch }}
widget-fontface-branch:
description: Branch name of font face widget
value: ${{ jobs.widget-versions.outputs.widget-fontface-branch }}
widget-fontsize-branch:
description: Branch name of font size widget
value: ${{ jobs.widget-versions.outputs.widget-fontsize-branch }}
widget-textcolour-branch:
description: Branch name of text colour widget
value: ${{ jobs.widget-versions.outputs.widget-textcolour-branch }}
jobs:
widget-versions:
name: Get default widget versions
runs-on: ubuntu-latest
outputs:
widget-backgroundcolour-branch: ${{ steps.widget-branches.outputs.WIDGET_BACKGROUNDCOLOUR_VERSION }}
widget-fontface-branch: ${{ steps.widget-branches.outputs.WIDGET_FONTFACE_VERSION }}
widget-fontsize-branch: ${{ steps.widget-branches.outputs.WIDGET_FONTSIZE_VERSION }}
widget-textcolour-branch: ${{ steps.widget-branches.outputs.WIDGET_TEXTCOLOUR_VERSION }}
steps:
- name: Get widget version
id: get-widget-versions
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "WIDGET_BACKGROUNDCOLOUR_VERSION_JSON=$(gh release view --json name -R ponlawat-w/moodle-accessibility_backgroundcolour)" >> $GITHUB_OUTPUT
echo "WIDGET_FONTFACE_VERSION_JSON=$(gh release view --json name -R ponlawat-w/moodle-accessibility_fontface)" >> $GITHUB_OUTPUT
echo "WIDGET_FONTSIZE_VERSION_JSON=$(gh release view --json name -R ponlawat-w/moodle-accessibility_fontsize)" >> $GITHUB_OUTPUT
echo "WIDGET_TEXTCOLOUR_VERSION_JSON=$(gh release view --json name -R ponlawat-w/moodle-accessibility_textcolour)" >> $GITHUB_OUTPUT
- name: Get widget branch names
id: widget-branches
run: |
echo "WIDGET_BACKGROUNDCOLOUR_VERSION=v${{ fromJson(steps.get-widget-versions.outputs.WIDGET_BACKGROUNDCOLOUR_VERSION_JSON).name }}" >> $GITHUB_OUTPUT
echo "WIDGET_FONTFACE_VERSION=v${{ fromJson(steps.get-widget-versions.outputs.WIDGET_FONTFACE_VERSION_JSON).name }}" >> $GITHUB_OUTPUT
echo "WIDGET_FONTSIZE_VERSION=v${{ fromJson(steps.get-widget-versions.outputs.WIDGET_FONTSIZE_VERSION_JSON).name }}" >> $GITHUB_OUTPUT
echo "WIDGET_TEXTCOLOUR_VERSION=v${{ fromJson(steps.get-widget-versions.outputs.WIDGET_TEXTCOLOUR_VERSION_JSON).name }}" >> $GITHUB_OUTPUT
63 changes: 63 additions & 0 deletions .github/workflows/get-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Retrieve Plugin Version from version.php
on:
workflow_call:
inputs:
repository:
type: string
default: ${{ github.repository }}
ref:
type: string
default: ''
outputs:
plugin-component:
description: Plugin component
value: ${{ jobs.get-version.outputs.plugin-component }}
plugin-release:
description: Plugin release
value: ${{ jobs.get-version.outputs.plugin-release }}
plugin-version:
description: Plugin version
value: ${{ jobs.get-version.outputs.plugin-version }}
plugin-requires:
description: Plugin requires
value: ${{ jobs.get-version.outputs.plugin-requires }}
plugin-maturity:
description: Plugin maturity
value: ${{ jobs.get-version.outputs.plugin-maturity }}
plugin-dependencies:
description: Plugin dependencies (JSON text)
value: ${{ jobs.get-version.outputs.plugin-dependencies }}
branch-name:
description: Branch name
value: ${{ jobs.get-version.outputs.branch-name }}
jobs:
get-version:
name: Get plugin version from version.php
runs-on: ubuntu-latest
outputs:
plugin-component: ${{ steps.plugin-info.outputs.PLUGIN_COMPONENT }}
plugin-release: ${{ steps.plugin-info.outputs.PLUGIN_RELEASE }}
plugin-version: ${{ steps.plugin-info.outputs.PLUGIN_VERSION }}
plugin-requires: ${{ steps.plugin-info.outputs.PLUGIN_REQUIRES }}
plugin-maturity: ${{ steps.plugin-info.outputs.PLUGIN_MATURITY }}
plugin-dependencies: ${{ steps.plugin-info.outputs.PLUGIN_DEPENDENCIES }}
branch-name: ${{ steps.get-branch.outputs.BRANCH_NAME }}
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
extensions:
ini-values: max_input_vars=5000
coverage: none
- name: Checkout
uses: actions/checkout@v4
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.ref }}
- name: Get plugin information
id: plugin-info
run: php -r 'define("MOODLE_INTERNAL",1);define("MATURITY_ALPHA",50);define("MATURITY_BETA",100);define("MATURITY_RC",150);define("MATURITY_STABLE",200);define("ANY_VERSION","any");$plugin=new stdClass();include_once("version.php");$plugin->maturity!=200&&throw new Exception("Requires plugin maturity to be stable to release!");echo "PLUGIN_COMPONENT=".(isset($plugin->component)?$plugin->component:"")."\nPLUGIN_RELEASE=".(isset($plugin->release)?$plugin->release:"")."\nPLUGIN_VERSION=".(isset($plugin->version)?$plugin->version:"")."\nPLUGIN_REQUIRES=".(isset($plugin->requires)?$plugin->requires:"")."\nPLUGIN_MATURITY=".(isset($plugin->maturity)?$plugin->maturity:"")."\nPLUGIN_DEPENDENCIES=".(isset($plugin->dependencies)?json_encode($plugin->dependencies):"{}");' >> $GITHUB_OUTPUT
- name: Get branch name
id: get-branch
run: php -r 'echo "BRANCH_NAME=".preg_replace("/(\\(|\\))/", "", strtolower(str_replace(" ", "-", preg_replace("/(\\d+)\\.(\\d+)\\.(\\d+)(.*)/","v$1.$2$4", "${{ steps.plugin-info.outputs.PLUGIN_RELEASE }}"))));' >> $GITHUB_OUTPUT
31 changes: 0 additions & 31 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,9 @@ on:
- reopened
- synchronize
jobs:
widget-versions:
name: Get default widget versions
runs-on: ubuntu-latest
outputs:
widget-backgroundcolour-branch: ${{ steps.widget-branches.outputs.WIDGET_BACKGROUNDCOLOUR_VERSION }}
widget-fontface-branch: ${{ steps.widget-branches.outputs.WIDGET_FONTFACE_VERSION }}
widget-fontsize-branch: ${{ steps.widget-branches.outputs.WIDGET_FONTSIZE_VERSION }}
widget-textcolour-branch: ${{ steps.widget-branches.outputs.WIDGET_TEXTCOLOUR_VERSION }}
steps:
- name: Get widget version
id: get-widget-versions
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "WIDGET_BACKGROUNDCOLOUR_VERSION_JSON=$(gh release view --json name -R ponlawat-w/moodle-accessibility_backgroundcolour)" >> $GITHUB_OUTPUT
echo "WIDGET_FONTFACE_VERSION_JSON=$(gh release view --json name -R ponlawat-w/moodle-accessibility_fontface)" >> $GITHUB_OUTPUT
echo "WIDGET_FONTSIZE_VERSION_JSON=$(gh release view --json name -R ponlawat-w/moodle-accessibility_fontsize)" >> $GITHUB_OUTPUT
echo "WIDGET_TEXTCOLOUR_VERSION_JSON=$(gh release view --json name -R ponlawat-w/moodle-accessibility_textcolour)" >> $GITHUB_OUTPUT
- name: Get widget branch names
id: widget-branches
run: |
echo "WIDGET_BACKGROUNDCOLOUR_VERSION=v${{ fromJson(steps.get-widget-versions.outputs.WIDGET_BACKGROUNDCOLOUR_VERSION_JSON).name }}" >> $GITHUB_OUTPUT
echo "WIDGET_FONTFACE_VERSION=v${{ fromJson(steps.get-widget-versions.outputs.WIDGET_FONTFACE_VERSION_JSON).name }}" >> $GITHUB_OUTPUT
echo "WIDGET_FONTSIZE_VERSION=v${{ fromJson(steps.get-widget-versions.outputs.WIDGET_FONTSIZE_VERSION_JSON).name }}" >> $GITHUB_OUTPUT
echo "WIDGET_TEXTCOLOUR_VERSION=v${{ fromJson(steps.get-widget-versions.outputs.WIDGET_TEXTCOLOUR_VERSION_JSON).name }}" >> $GITHUB_OUTPUT
ci:
name: CI
needs: widget-versions
uses: ./.github/workflows/ci.yml
with:
widget-backgroundcolour-branch: ${{ needs.widget-versions.outputs.widget-backgroundcolour-branch }}
widget-fontface-branch: ${{ needs.widget-versions.outputs.widget-fontface-branch }}
widget-fontsize-branch: ${{ needs.widget-versions.outputs.widget-fontsize-branch }}
widget-textcolour-branch: ${{ needs.widget-versions.outputs.widget-textcolour-branch }}
pr-ci-finished:
name: PR CI Finished
needs: ci
Expand Down
Loading

0 comments on commit ddb6af7

Please sign in to comment.