Skip to content

Commit

Permalink
MNT Add auto-tag workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jun 12, 2022
1 parent ef94bbe commit 0c8b876
Show file tree
Hide file tree
Showing 7 changed files with 389 additions and 309 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/auto-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Auto-tag
on:
push:
tags:
- '*.*.*'
jobs:
auto-tag:
name: Auto-tag
runs-on: ubuntu-latest
steps:
- name: Auto-tag
uses: silverstripe/gha-auto-tag@main
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Create a dynamic Silverstripe CI matrix

See [gha-ci](https://github.com/silverstripe/gha-ci)
Only intended to be used within [gha-ci](https://github.com/silverstripe/gha-ci). See that repository for details on inputs.
13 changes: 13 additions & 0 deletions action.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

include 'consts.php';
include 'job_creator.php';

// Reads inputs.yml and creates a new json matrix
$inputs = yaml_parse(file_get_contents('__inputs.yml'));
if ($inputs === false) {
echo 'Unable to parse __inputs.yml';
exit(1);
}
$jobCreator = new JobCreator();
echo $jobCreator->createJson($inputs);
30 changes: 22 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
name: Generate Matrix
description: GitHub Action to create a dynamic Silverstripe CI matrix

inputs:
# extra jobs must be multi-line string, as there's no support for type: array for inputs
extra_jobs:
type: string
required: false
default: ''
# simple matrix will only run a single php 7.4 mysql 5.7 job instead of a full matrix
# simple matrix will only run a single job with the lowest supported PHP and mysql versions instead of a full matrix
simple_matrix:
type: boolean
default: false
Expand All @@ -26,21 +27,26 @@ inputs:
js:
type: boolean
default: true

# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions
outputs:
matrix:
description: JSON matrix
value: ${{ steps.php-script.outputs.matrix }}

runs:
using: composite
steps:

- name: Checkout code
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 #v2
uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2.4.2

- name: Install PHP
uses: shivammathur/setup-php@aa1fe473f9c687b6fb896056d771232c0bc41161 #v2
uses: shivammathur/setup-php@3eda58347216592f618bb1dff277810b6698e4ca # v2.19.1
with:
php-version: '7.4'
php-version: '8.1'
extensions: yaml

- name: Create __inputs.yml
shell: bash
# Add string inputs to memory instead of using string substituion in shell script
Expand All @@ -52,7 +58,12 @@ runs:
# github.ref_name is the name of the branch on push, and the tag on tag
GITHUB_MY_REF: ${{ github.base_ref && github.base_ref || github.ref_name }}
run: |
if [ -f __inputs.yml ]; then rm __inputs.yml; fi
# Escape double quotes '"' => '\"'
EXTRA_JOBS=${EXTRA_JOBS//\"/\\\"}
GITHUB_MY_REF=${GITHUB_MY_REF//\"/\\\"}
if [ -f __inputs.yml ]; then
rm __inputs.yml
fi
touch __inputs.yml
echo "endtoend: ${{ inputs.endtoend }}" >> __inputs.yml
echo "js: ${{ inputs.js }}" >> __inputs.yml
Expand All @@ -62,14 +73,17 @@ runs:
echo "simple_matrix: ${{ inputs.simple_matrix }}" >> __inputs.yml
echo "github_repository: $GITHUB_REPOSITORY" >> __inputs.yml
echo "github_my_ref: $GITHUB_MY_REF" >> __inputs.yml
if [[ "$EXTRA_JOBS" != "" ]]; then echo "extra_jobs:" >> __inputs.yml; fi
if [[ "$EXTRA_JOBS" != "" ]]; then echo "$EXTRA_JOBS" >> __inputs.yml; fi
if [[ "$EXTRA_JOBS" != "" ]]; then
echo "extra_jobs:" >> __inputs.yml
echo "$EXTRA_JOBS" >> __inputs.yml
fi
echo "cat __inputs.yml"
cat __inputs.yml
- name: Run php script
id: php-script
shell: bash
run: |
MATRIX_JSON=$(php ${{ github.action_path }}/script.php)
MATRIX_JSON=$(php ${{ github.action_path }}/action.php)
echo "MATRIX_JSON: $MATRIX_JSON"
echo "::set-output name=matrix::${MATRIX_JSON}"
68 changes: 68 additions & 0 deletions consts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

# Manually update this after each minor CMS release
const INSTALLER_TO_PHP_VERSIONS = [
'4.9' => [
'7.1',
'7.2',
'7.3',
'7.4'
],
'4.10' => [
'7.3',
'7.4',
'8.0',
],
'4.11' => [
'7.4',
'8.0',
'8.1',
],
'4' => [
'7.4',
'8.0',
'8.1',
],
];

const DB_MYSQL_57 = 'mysql57';
const DB_MYSQL_57_PDO = 'mysql57pdo';
const DB_MYSQL_80 = 'mysql80';
const DB_PGSQL = 'pgsql';

// Used when determining the version of installer to used. Intentionally doesn't include recipes
const LOCKSTEPED_REPOS = [
'silverstripe-admin',
'silverstripe-asset-admin',
'silverstripe-assets',
'silverstripe-campaign-admin',
'silverstripe-cms',
'silverstripe-errorpage',
'silverstripe-framework',
'silverstripe-reports',
'silverstripe-siteconfig',
'silverstripe-versioned',
'silverstripe-versioned-admin',
// recipe-solr-search doesn't include recipe-cms or recipe-core unlike our other recipes
'recipe-solr-search',
];

// Repositories that do not require silverstripe/installer to be explicitly added as a dependency for testing
const NO_INSTALLER_REPOS = [
// these are/include recipe-cms or recipe-core, so we don't want to composer require installer
// in .travis.yml they used the 'self' provision rather than 'standard'
'recipe-authoring-tools',
'recipe-blog',
'recipe-ccl',
'recipe-cms',
'recipe-collaboration',
'recipe-content-blocks',
'recipe-core',
'recipe-form-building',
'recipe-kitchen-sink',
'recipe-reporting-tools',
'recipe-services',
'silverstripe-installer',
// vendor-plugin is not a recipe, though we also do not want installer
'vendor-plugin'
];
Loading

0 comments on commit 0c8b876

Please sign in to comment.