-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support active branches (#109)
- Loading branch information
Showing
4 changed files
with
174 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,54 @@ | ||
name: test-elastic-active-branches | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
paths: | ||
- '.github/workflows/test-elastic-active-branches.yml' | ||
- 'elastic/active-branches/**' | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- '.github/workflows/test-elastic-active-branches.yml' | ||
- 'elastic/active-branches/**' | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
|
||
test: | ||
needs: | ||
- main | ||
- exclude-main | ||
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 }} | ||
|
||
main: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ./elastic/active-branches | ||
id: active-branches | ||
- name: Verify main is in the active branches | ||
if: ${{ !contains(fromJSON(steps.active-branches.outputs.branches), 'main') }} | ||
run: echo "Main branch could not be found" | ||
|
||
exclude-main: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ./elastic/active-branches | ||
id: active-branches | ||
with: | ||
exclude-branches: main | ||
- name: Verify main is not in the active branches | ||
if: contains(fromJSON(steps.active-branches.outputs.branches), 'main') | ||
run: echo "Main branch could be found but should be excluded" |
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,55 @@ | ||
# <!--name-->elastic/active-branches<!--/name--> | ||
|
||
[![usages](https://img.shields.io/badge/usages-white?logo=githubactions&logoColor=blue)](https:/search?q=elastic%2Foblt-actions%2Felastic%2Factive-branches+%28path%3A.github%2Fworkflows+OR+path%3A**%2Faction.yml+OR+path%3A**%2Faction.yaml%29&type=code) | ||
[![test-elastic-active-branches](https:/elastic/oblt-actions/actions/workflows/test-elastic-active-branches.yml/badge.svg?branch=main)](https:/elastic/oblt-actions/actions/workflows/test-elastic-active-branches.yml) | ||
|
||
<!--description--> | ||
Fetch the current list of active branches in Elastic (the ones based on the Unified Release process) | ||
<!--/description--> | ||
|
||
## Inputs | ||
<!--inputs--> | ||
| Name | Description | Required | Default | | ||
|--------------------|----------------------------------|----------|---------| | ||
| `exclude-branches` | Exclude branches comma separated | `false` | ` ` | | ||
<!--/inputs--> | ||
|
||
## Outputs | ||
|
||
<!--outputs--> | ||
| Name | Description | | ||
|------------|---------------------------------------------------------------| | ||
| `matrix` | Processed matrix with the branches (using the include format) | | ||
| `branches` | Processed list of branches | | ||
<!--/outputs--> | ||
|
||
## Usage | ||
|
||
<!--usage action="elastic/oblt-actions/**" version="env:VERSION"--> | ||
```yaml | ||
jobs: | ||
filter: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 1 | ||
outputs: | ||
matrix: ${{ steps.generator.outputs.matrix }} | ||
steps: | ||
- id: generator | ||
uses: elastic/oblt-actions/elastic/active-branches@v1 | ||
with: | ||
exclude-branches: '7.17' | ||
|
||
bump-elastic-stack: | ||
runs-on: ubuntu-latest | ||
needs: [filter] | ||
strategy: | ||
matrix: ${{ fromJson(needs.filter.outputs.matrix) }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: "${{ matrix.branch }}" | ||
|
||
|
||
# ... | ||
``` | ||
<!--/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,28 @@ | ||
name: elastic/active-branches | ||
description: | | ||
Fetch the current list of active branches in Elastic (the ones based on the Unified Release process) | ||
inputs: | ||
exclude-branches: | ||
description: "Exclude branches comma separated" | ||
required: false | ||
type: string | ||
default: '' | ||
outputs: | ||
matrix: | ||
description: "Processed matrix with the branches (using the include format)" | ||
value: ${{ steps.generator.outputs.matrix }} | ||
branches: | ||
description: "Processed list of branches" | ||
value: ${{ steps.generator.outputs.branches }} | ||
runs: | ||
using: composite | ||
steps: | ||
- id: generator | ||
shell: bash | ||
run: python ${{ github.action_path }}/script.py | ||
env: | ||
EXCLUDE_BRANCHES: ${{ inputs.exclude-branches }} | ||
- id: debug | ||
shell: bash | ||
run: | | ||
echo 'Matrix: ${{ steps.generator.outputs.matrix }}' |
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,37 @@ | ||
#!/usr/bin/env python | ||
|
||
import json | ||
import os | ||
import requests | ||
|
||
def fails(msg): | ||
print(msg) | ||
exit(1) | ||
|
||
req = requests.get(url='https://storage.googleapis.com/artifacts-api/snapshots/branches.json') | ||
if req.status_code != requests.codes.ok: | ||
fails("Failed to fetch active branches") | ||
|
||
try: | ||
payload = req.json() | ||
except requests.exceptions.JSONDecodeError: | ||
fails("Failed to decode json payload") | ||
|
||
branches = payload.get('branches') | ||
if not branches: | ||
fails("Failed to retrieve active branches") | ||
|
||
exclude_branches = os.environ.get('EXCLUDE_BRANCHES', '') | ||
exclude_branches = set(filter(lambda branch: len(branch) > 0, exclude_branches.split(','))) | ||
if exclude_branches: | ||
branches = list(filter(lambda branch: branch not in exclude_branches, branches)) | ||
|
||
include_branches = list(map(lambda branch: {"branch": branch}, branches)) | ||
matrix = {'include': include_branches} | ||
|
||
with open(os.environ.get('GITHUB_OUTPUT'), "a") as file_descriptor: | ||
file_descriptor.write(f"matrix={json.dumps(matrix)}\n") | ||
file_descriptor.write(f"branches={json.dumps(branches)}\n") | ||
|
||
print(f"INFO: matrix={json.dumps(matrix)}") | ||
print(f"INFO: branches={json.dumps(branches)}") |