-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: replace apm-pipeline-library version-framework (#150)
- Loading branch information
Showing
7 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
name: test-version-framework | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
dry-run: | ||
description: 'Dry run' | ||
required: true | ||
default: false | ||
type: boolean | ||
push: | ||
paths: | ||
- '.github/workflows/test-version-framework.yml' | ||
- 'version-framework/**' | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
test: | ||
if: always() | ||
needs: | ||
- valid-all | ||
- valid-no-excluded | ||
- invalid | ||
runs-on: ubuntu-latest | ||
steps: | ||
- id: check | ||
uses: elastic/oblt-actions/check-dependent-jobs@v1 | ||
with: | ||
jobs: ${{ toJSON(needs) }} | ||
- run: ${{ steps.check.outputs.is-success }} | ||
|
||
valid-all: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ./version-framework | ||
id: validation | ||
with: | ||
versions-file: version-framework/test-data/versions.yml | ||
frameworks-file: version-framework/test-data/frameworks.yml | ||
excluded-file: version-framework/test-data/excluded.yml | ||
- id: want | ||
run: echo "matrix={\"include\":[{\"version\":\"ruby:3.1\",\"framework\":\"rails-7.0\"},{\"version\":\"ruby:3.1\",\"framework\":\"rails-6.1\"},{\"version\":\"ruby:2.4\",\"framework\":\"rails-6.1\"}]}" >> $GITHUB_OUTPUT | ||
- name: Assert is valid | ||
run: | | ||
echo '${{ steps.validation.outputs.matrix }}' | jq . > validation.json | ||
echo '${{ steps.want.outputs.matrix }}' | jq . > want.json | ||
diff validation.json want.json | ||
valid-no-excluded: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ./version-framework | ||
id: validation | ||
with: | ||
versions-file: version-framework/test-data/versions.yml | ||
frameworks-file: version-framework/test-data/frameworks.yml | ||
- id: want | ||
run: echo "matrix={\"include\":[{\"version\":\"ruby:3.1\",\"framework\":\"rails-7.0\"},{\"version\":\"ruby:3.1\",\"framework\":\"rails-6.1\"},{\"version\":\"ruby:2.4\",\"framework\":\"rails-7.0\"},{\"version\":\"ruby:2.4\",\"framework\":\"rails-6.1\"}]}" >> $GITHUB_OUTPUT | ||
- name: Assert is valid | ||
run: | | ||
echo '${{ steps.validation.outputs.matrix }}' | jq . > validation.json | ||
echo '${{ steps.want.outputs.matrix }}' | jq . > want.json | ||
diff validation.json want.json | ||
invalid: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ./version-framework | ||
id: validation | ||
continue-on-error: true | ||
with: | ||
versions-file: invalid.yml | ||
frameworks-file: invalid.yml | ||
|
||
- name: Verify step failed | ||
if: steps.validation.outcome != 'failure' | ||
run: exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# <!--name-->version-framework<!--/name--> | ||
|
||
[![usages](https://img.shields.io/badge/usages-white?logo=githubactions&logoColor=blue)](https://github.com/search?q=elastic%2Foblt-actions%2Fversion-framework+%28path%3A.github%2Fworkflows+OR+path%3A**%2Faction.yml+OR+path%3A**%2Faction.yaml%29&type=code) | ||
|
||
<!--description--> | ||
Create matrix for the supported versions and frameworks | ||
<!--/description--> | ||
|
||
## Inputs | ||
|
||
<!--inputs--> | ||
| Name | Description | Required | Default | | ||
|-------------------|-----------------------------------------------------------------------------------------------------------|----------|---------| | ||
| `versions-file` | The YAML file with the versions. Being VERSION the key for the list | `true` | ` ` | | ||
| `frameworks-file` | The YAML file with the frameworks. Being FRAMEWORK the key for the list | `true` | ` ` | | ||
| `excluded-file` | The YAML file with the excluded tuples. Being exclude the key for the list of tuples (VERSION, FRAMEWORK) | `false` | ` ` | | ||
<!--/inputs--> | ||
|
||
## Outputs | ||
<!--outputs--> | ||
| Name | Description | | ||
|----------|--------------------------------------------------------------------| | ||
| `matrix` | Processed matrix with the required tuples of version and framework | | ||
<!--/outputs--> | ||
|
||
## Usage | ||
|
||
<!--usage action="elastic/oblt-actions/**" version="env:VERSION"--> | ||
```yaml | ||
on: | ||
push: | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
create-test-matrix: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
matrix: ${{ steps.generate.outputs.matrix }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- id: generate | ||
uses: elastic/oblt-actions/version-framework@v1 | ||
with: | ||
versions-file: .ci/.ruby.yml | ||
frameworks-file: .ci/.main_framework.yml | ||
excluded-file: .ci/.exclude.yml | ||
|
||
test: | ||
needs: | ||
- create-test-matrix | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
max-parallel: 20 | ||
matrix: ${{ fromJSON(needs.create-test-matrix.outputs.matrix) }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
[..] | ||
``` | ||
<!--/usage--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
name: 'version-framework' | ||
description: Create matrix for the supported versions and frameworks | ||
|
||
inputs: | ||
versions-file: | ||
description: 'The YAML file with the versions. Being VERSION the key for the list' | ||
required: true | ||
frameworks-file: | ||
description: 'The YAML file with the frameworks. Being FRAMEWORK the key for the list' | ||
required: true | ||
excluded-file: | ||
description: 'The YAML file with the excluded tuples. Being exclude the key for the list of tuples (VERSION, FRAMEWORK)' | ||
required: false | ||
|
||
outputs: | ||
matrix: | ||
description: "Processed matrix with the required tuples of version and framework" | ||
value: ${{ steps.generator.outputs.matrix }} | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- id: generator | ||
run: python ${{ github.action_path }}/matrix.py | ||
env: | ||
VERSIONS_FILE: ${{ inputs.versions-file }} | ||
FRAMEWORKS_FILE: ${{ inputs.frameworks-file }} | ||
EXCLUDED_FILE: ${{ inputs.excluded-file }} | ||
shell: bash | ||
|
||
- name: debug | ||
run: | | ||
echo 'Matrix to test: ${{ steps.generator.outputs.matrix }}' | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import json | ||
import os | ||
import yaml | ||
from pathlib import Path | ||
|
||
|
||
def run() -> None: | ||
excluded_file = os.getenv("EXCLUDED_FILE", "") | ||
framework_file = os.environ["FRAMEWORKS_FILE"] | ||
versions_file = os.environ["VERSIONS_FILE"] | ||
|
||
excludes = {'exclude': []} | ||
|
||
if len(excluded_file) > 0: | ||
excludes = yaml.safe_load(Path(excluded_file).read_text()) | ||
frameworks = yaml.safe_load(Path(framework_file).read_text()) | ||
versions = yaml.safe_load(Path(versions_file).read_text()) | ||
|
||
matrix = {'include': []} | ||
for version in versions['VERSION']: | ||
for framework in frameworks['FRAMEWORK']: | ||
if len(list(filter(lambda item: item['VERSION'] == version and item["FRAMEWORK"] == framework, excludes['exclude']))) > 0: | ||
print('excluded ' + version + ' with ' + framework) | ||
else: | ||
matrix['include'].append({"version": version, "framework": framework}) | ||
|
||
with open(os.environ.get('GITHUB_OUTPUT'), "a") as f: | ||
f.write("matrix={}\n".format(json.dumps(matrix))) | ||
|
||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
exclude: | ||
- VERSION: ruby:2.4 | ||
FRAMEWORK: rails-7.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FRAMEWORK: | ||
- rails-7.0 | ||
- rails-6.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
VERSION: | ||
- ruby:3.1 | ||
- ruby:2.4 |