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

feat: set default values #195

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .github/workflows/test-elastic-active-branches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ jobs:

filter:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: ./elastic/active-branches
id: active-branches
with:
filter-branches: true
github-token: ${{ secrets.GITHUB_TOKEN }}
- 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" && exit 1
Expand Down
41 changes: 36 additions & 5 deletions elastic/active-branches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ Fetch the current list of active branches in Elastic (the ones based on the Unif

## Inputs
<!--inputs-->
| Name | Description | Required | Default |
|--------------------|---------------------------------------------------------------------------------|----------|---------|
| `exclude-branches` | Exclude branches comma separated | `false` | ` ` |
| `filter-branches` | Whether to fitler those branches that only exist in the {{ github.repository }} | `false` | `false` |
| `github-token` | The GitHub access token. | `false` | ` ` |
| Name | Description | Required | Default |
|---------------------|---------------------------------------------------------------------------|----------|----------------------------|
| `exclude-branches` | Exclude branches comma separated | `false` | ` ` |
| `filter-branches` | Whether to filter those branches that only exist in the github-repository | `false` | `false` |
| `github-token` | The GitHub access token. | `false` | `${{ github.token }}` |
| `github-repository` | The GitHub repository to search for active branches. | `false` | `${{ github.repository }}` |
<!--/inputs-->

## Outputs
Expand Down Expand Up @@ -53,4 +54,34 @@ jobs:

# ...
```


<!--usage action="elastic/oblt-actions/**" version="env:VERSION"-->
```yaml
jobs:
filter:
runs-on: ubuntu-latest
timeout-minutes: 1
permissions:
contents: read
outputs:
matrix: ${{ steps.generator.outputs.matrix }}
steps:
- id: generator
uses: elastic/oblt-actions/elastic/active-branches@v1
with:
filter-branches: true

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-->
12 changes: 9 additions & 3 deletions elastic/active-branches/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ inputs:
type: string
default: ''
filter-branches:
description: "Whether to fitler those branches that only exist in the {{ github.repository }}"
description: "Whether to filter those branches that only exist in the github-repository"
default: false
type: boolean
github-token:
description: 'The GitHub access token.'
required: false
type: string
default: ''
default: ${{ github.token }}
github-repository:
description: 'The GitHub repository to search for active branches.'
required: false
type: string
default: ${{ github.repository }}

outputs:
matrix:
description: "Processed matrix with the branches (using the include format)"
Expand All @@ -32,7 +38,7 @@ runs:
env:
EXCLUDE_BRANCHES: ${{ inputs.exclude-branches }}
FILTER: ${{ inputs.filter-branches }}
REPOSITORY: ${{ github.repository }}
REPOSITORY: ${{ inputs.github-repository }}
GITHUB_TOKEN: ${{ inputs.github-token }}
- id: debug
shell: bash
Expand Down
7 changes: 4 additions & 3 deletions elastic/active-branches/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ def fails(msg):
filter_str = os.environ.get('FILTER', 'false')
filter = filter_str.lower() in ('true', '1', 't', 'y', 'yes')
repository = os.environ.get('REPOSITORY', '')
github_token = os.environ.get('GITHUB_TOKEN', '')
if filter and repository and github_token:
if filter and repository:
# Check if branches exist in the GitHub repository
headers = {
'Authorization': f'token {github_token}',
'Accept': 'application/vnd.github.v3+json'
}
github_token = os.environ.get('GITHUB_TOKEN', '')
if github_token:
headers['Authorization'] = f'token {github_token}'

existing_branches = []
for branch in branches:
Expand Down
Loading