Skip to content

Commit

Permalink
feat(workflows): make workflows reusable (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
neilime authored Feb 24, 2023
2 parents e67a5eb + 7f97a6e commit 224cb15
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 45 deletions.
27 changes: 23 additions & 4 deletions .github/workflows/generate-dependabot-config.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
# Workflow - Generate Dependabot Config
<!-- start title -->

Reusable workflow to generate a dependabot config from predefined templates.
# GitHub Reusable Workflow: Generate Dependabot Config

Mainly using [Generate Dependabot Glob Action](https://github.com/marketplace/actions/generate-dependabot-glob), to generate a dependabot config from a glob pattern.
<!-- end title -->
<!-- start description -->

Reusable workflow to generate a dependabot config from predefined templates.
Mainly using [Generate Dependabot Glob Action](https://github.com/marketplace/actions/generate-dependabot-glob), to generate a dependabot config from a glob pattern.
Workaround for missing official support of glob directories [https://github.com/dependabot/dependabot-core/issues/2178](https://github.com/dependabot/dependabot-core/issues/2178)

## Usage
<!-- end description -->
<!-- start contents -->
<!-- end contents -->
<!-- start usage -->

```yaml
name: Generate dependabot.yml config
on:
push:
branches:
Expand All @@ -17,3 +24,15 @@ jobs:
main:
uses: hoverkraft-tech/ci-github-common/.github/workflows/generate-dependabot-config.yml@main
```
<!-- end usage -->
<!-- start secrets -->
<!-- end secrets -->
<!-- start inputs -->
<!-- end inputs -->
<!-- start outputs -->
<!-- end outputs -->
<!-- start [.github/ghadocs/examples/] -->
<!-- end [.github/ghadocs/examples/] -->
66 changes: 57 additions & 9 deletions .github/workflows/greetings.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,66 @@
# Workflow - Greetings
<!-- start title -->

# GitHub Reusable Workflow: Greetings

<!-- end title -->
<!-- start description -->

Workflow to greet new contributors.
Mainly using [First Interaction Action](https://github.com/actions/first-interaction), with some opinionated defaults.

- On issue creation, a comment is added to the issue.
- On first contribution, a comment is added to the pull request.

## Usage
<!-- end description -->
<!-- start contents -->
<!-- end contents -->
<!-- start usage -->

```yaml
name: Mark stale issues and pull requests

on:
schedule:
- cron: "30 1 * * *"

jobs:
main:
uses: hoverkraft-tech/ci-github-common/.github/workflows/greetings.yml@main
secrets:
# Token for the repository. Can be passed in using "${{ secrets.GITHUB_TOKEN }}".
# See https://github.com/actions/first-interaction#usage
github-token: ${{ secrets.GITHUB_TOKEN }}

# Optional customizations.
with:
# Comment to post on an individual's first issue.
# See https://github.com/actions/first-interaction#usage
# Default: "Hi, thank for reporting an issue, we will check it out very soon"
issue-message: ""
# Comment to post on an individual's first pull request.
# See https://github.com/actions/first-interaction#usage
# Default: "Hi, thank you for creating your PR, we will check it out very soon"
pr-message: ""
```
<!-- end usage -->
<!-- start secrets -->
| **Secret** | **Description** |
| ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| **<code>github-token</code>** | Token for the repository. Can be passed in using "${{ secrets.GITHUB_TOKEN }}". See https://github.com/actions/first-interaction#usage |
<!-- end secrets -->
<!-- start inputs -->
### As required workflow
| **Input** | **Description** | **Default** | **Required** |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ------------ |
| **<code>issue-message</code>** | Comment to post on an individual's first issue. See https://github.com/actions/first-interaction#usage | <code>Hi, thank for reporting an issue, we will check it out very soon</code> | **false** |
| **<code>issue-message</code>** | Comment to post on an individual's first pull request. See https://github.com/actions/first-interaction#usage | <code>Hi, thank you for creating your PR, we will check it out very soon</code> | **false** |
Configure workflow to be required in your organization settings.
<!-- end inputs -->
- Go to your organization actions settings to add a new required workflow: Settings > Actions > General > Required workflows > Add workflow
`https://github.com/organizations/[your-organization]/settings/actions/required_workflows/new` (replace `[your-organization]` with your organization name)
- Select the repository `ci-github-common`
- Select the workflow file: `.github/workflows/greetings.yml`
- Add workflow
<!-- start outputs -->
<!-- end outputs -->
<!-- start [.github/ghadocs/examples/] -->
<!-- end [.github/ghadocs/examples/] -->
2 changes: 1 addition & 1 deletion .github/workflows/greetings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ on:
required: false
secrets:
github-token:
description: "Token for the repository. Can be passed in using {{ secrets.GITHUB_TOKEN }}. See https://github.com/actions/first-interaction#usage"
description: 'Token for the repository. Can be passed in using "${{ secrets.GITHUB_TOKEN }}". See https://github.com/actions/first-interaction#usage'
required: true

jobs:
Expand Down
53 changes: 44 additions & 9 deletions .github/workflows/semantic-pull-request.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,51 @@
# Workflow - Semantic pull request
<!-- start title -->

# GitHub Reusable Workflow: Semantic pull request

<!-- end title -->
<!-- start description -->

Workflow to ensure "Squash and merge" Pull Request strategy provides a valid commit message.
Check that the title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification.
Mainly using [action-semantic-pull-request](https://github.com/amannn/action-semantic-pull-request#installation), with some opinionated defaults.

<!-- end description -->
<!-- start contents -->
<!-- end contents -->
<!-- start usage -->

```yaml
name: "Pull Request - Semantic Lint"

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
uses: hoverkraft-tech/ci-github-common/.github/workflows/semantic-pull-request.yml@main
secrets:
# Token for the repository. Can be passed in using "${{ secrets.GITHUB_TOKEN }}".
# See https://github.com/amannn/action-semantic-pull-request#installation
github-token: ${{ secrets.GITHUB_TOKEN }}
```
<!-- end usage -->
<!-- start secrets -->
## Usage
| **Secret** | **Description** |
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **<code>github-token</code>** | Token for the repository. Can be passed in using "${{ secrets.GITHUB_TOKEN }}". See https://github.com/amannn/action-semantic-pull-request#installation |
### As required workflow
<!-- end secrets -->
<!-- start inputs -->
Configure workflow to be required in your organization settings.
<!-- end inputs -->
- Go to your organization actions settings to add a new required workflow: Settings > Actions > General > Required workflows > Add workflow
`https://github.com/organizations/[your-organization]/settings/actions/required_workflows/new` (replace `[your-organization]` with your organization name)
- Select the repository `ci-github-common`
- Select the workflow file: `.github/workflows/semantic-pull-request.yml`
- Add workflow
<!-- start outputs -->
<!-- end outputs -->
<!-- start [.github/ghadocs/examples/] -->
<!-- end [.github/ghadocs/examples/] -->
12 changes: 11 additions & 1 deletion .github/workflows/semantic-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@ on:
- opened
- edited
- synchronize
workflow_call:
secrets:
github-token:
description: 'Token for the repository. Can be passed in using "${{ secrets.GITHUB_TOKEN }}". See https://github.com/amannn/action-semantic-pull-request#installation'
required: true

jobs:
main:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- id: set-variables
run: |
GITHUB_TOKEN="${{ secrets.github-token }}"
echo "REPO_TOKEN=${GITHUB_TOKEN:-"${{ secrets.GITHUB_TOKEN }}"}" >> "$GITHUB_ENV"
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ env.REPO_TOKEN }}
83 changes: 70 additions & 13 deletions .github/workflows/stale.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,76 @@
# Workflow - Stale
<!-- start title -->

Workflow to mark issues and pull requests as stale when needed.
# GitHub Reusable Workflow: Stale

- First add labels to issues and pull requests to mark them as stale.
- Then add a comment to the issue or pull request to explain why it is marked as stale.
- Finally, close the issue or pull request if it is still stale after a given period of time.
<!-- end title -->
<!-- start description -->

## Usage
Reusable workflow to manage stale issues and pull requests.
Mainly using [Stale Action](https://github.com/actions/stale), with some opinionated defaults.

### As required workflow
<!-- end description -->
<!-- start contents -->
<!-- end contents -->
<!-- start usage -->

Configure workflow to be required in your organization settings.
```yaml
name: Mark stale issues and pull requests

- Go to your organization actions settings to add a new required workflow: Settings > Actions > General > Required workflows > Add workflow
`https://github.com/organizations/[your-organization]/settings/actions/required_workflows/new` (replace `[your-organization]` with your organization name)
- Select the repository `ci-github-common`
- Select the workflow file: `.github/workflows/stale.yml`
- Add workflow
on:
schedule:
- cron: "30 1 * * *"

jobs:
main:
uses: hoverkraft-tech/ci-github-common/.github/workflows/stale.yml@main

# Optional customizations.
with:
# Comment on the staled issues.
# See https://github.com/actions/stale#stale-issue-message
# Default: "This issue is stale"
stale-issue-message: ""

# Comment on the staled PRs.
# See https://github.com/actions/stale#stale-pr-message
# Default: "This PR is stale"
stale-pr-message: ""

# Label to apply on staled issues.
# See https://github.com/actions/stale#stale-issue-label
# Default: "no-issue-activity"
stale-issue-label: ""

# Labels on issues exempted from stale.
# See https://github.com/actions/stale#exempt-issue-labels
# Default: "awaiting-approval,work-in-progress"
exempt-issue-labels: ""

# Label to apply on staled PRs.
# See https://github.com/actions/stale#stale-pr-label
# Default: "no-pr-activity"
stale-pr-label: ""

# Labels on PRs exempted from stale.
# See https://github.com/actions/stale#exempt-pr-labels
# Default: "awaiting-approval,work-in-progress"
exempt-pr-labels: ""
```
<!-- end usage -->
<!-- start inputs -->
| **Input** | **Description** | **Default** | **Required** |
| ------------------------------------ | ---------------------------------------------------------------------------------------------- | ----------------------------------------------- | ------------ |
| **<code>stale-issue-message</code>** | Comment on the staled issues. See https://github.com/actions/stale#stale-issue-message | <code>This issue is stale</code> | **false** |
| **<code>stale-pr-message</code>** | Comment on the staled PRs. See https://github.com/actions/stale#stale-pr-message | <code>This PR is stale</code> | **false** |
| **<code>stale-issue-label</code>** | Label to apply on staled issues. See https://github.com/actions/stale#stale-issue-label | <code>no-issue-activity</code> | **false** |
| **<code>exempt-issue-labels</code>** | Labels on issues exempted from stale. See https://github.com/actions/stale#exempt-issue-labels | <code>awaiting-approval,work-in-progress</code> | **false** |
| **<code>stale-pr-label</code>** | Label to apply on staled PRs. See https://github.com/actions/stale#stale-pr-label | <code>no-pr-activity</code> | **false** |
| **<code>exempt-pr-labels</code>** | Labels on PRs exempted from stale. See https://github.com/actions/stale#exempt-pr-labels | <code>awaiting-approval,work-in-progress</code> | **false** |
<!-- end inputs -->
<!-- start outputs -->
<!-- end outputs -->
<!-- start [.github/ghadocs/examples/] -->
<!-- end [.github/ghadocs/examples/] -->
59 changes: 52 additions & 7 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,62 @@ on:
schedule:
- cron: "30 1 * * *"

workflow_call:
inputs:
stale-issue-message:
description: "Comment on the staled issues. See https://github.com/actions/stale#stale-issue-message"
type: string
required: false
stale-pr-message:
description: "Comment on the staled PRs. See https://github.com/actions/stale#stale-pr-message"
type: string
required: false
stale-issue-label:
description: "Label to apply on staled issues. See https://github.com/actions/stale#stale-issue-label"
type: string
required: false
exempt-issue-labels:
description: "Labels on issues exempted from stale. See https://github.com/actions/stale#exempt-issue-labels"
type: string
required: false
stale-pr-label:
description: "Label to apply on staled PRs. See https://github.com/actions/stale#stale-pr-label"
type: string
required: false
exempt-pr-labels:
description: "Labels on PRs exempted from stale. See https://github.com/actions/stale#exempt-pr-labels"
type: string
required: false
secrets:
github-token:
description: "Token for the repository. Can be passed in using {{ secrets.GITHUB_TOKEN }}. See https://github.com/actions/first-interaction#usage"
required: true

jobs:
stale:
runs-on: ubuntu-latest

steps:
- id: set-variables
run: |
STALE_ISSUE_MESSAGE="${{ inputs.stale-issue-message }}"
echo "stale-issue-message=${STALE_ISSUE_MESSAGE:-"This issue is stale"}" >> "$GITHUB_OUTPUT"
STALE_PR_MESSAGE="${{ inputs.stale-pr-message }}"
echo "stale-pr-message=${STALE_PR_MESSAGE:-"This PR is stale"}" >> "$GITHUB_OUTPUT"
STALE_ISSUE_LABEL="${{ inputs.stale-issue-label }}"
echo "stale-issue-label=${STALE_ISSUE_LABEL:-"no-issue-activity"}" >> "$GITHUB_OUTPUT"
EXEMPT_ISSUE_LABELS="${{ inputs.exempt-issue-labels }}"
echo "exempt-issue-labels=${EXEMPT_ISSUE_LABELS:-"awaiting-approval,work-in-progress"}" >> "$GITHUB_OUTPUT"
STALE_PR_LABEL="${{ inputs.stale-pr-label }}"
echo "stale-pr-label=${STALE_PR_LABEL:-"no-pr-activity"}" >> "$GITHUB_OUTPUT"
EXEMPT_PR_LABELS="${{ inputs.exempt-pr-labels }}"
echo "exempt-pr-labels=${EXEMPT_PR_LABELS:-"awaiting-approval,work-in-progress"}" >> "$GITHUB_OUTPUT"
- uses: actions/stale@v7
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: "This issue is stale"
stale-pr-message: "This PR is stale"
stale-issue-label: "no-issue-activity"
exempt-issue-labels: "awaiting-approval,work-in-progress"
stale-pr-label: "no-pr-activity"
exempt-pr-labels: "awaiting-approval,work-in-progress"
stale-issue-message: ${{ steps.set-variables.outputs.stale-issue-message }}
stale-pr-message: ${{ steps.set-variables.outputs.stale-pr-message }}
stale-issue-label: ${{ steps.set-variables.outputs.stale-issue-label }}
exempt-issue-labels: ${{ steps.set-variables.outputs.exempt-issue-labels }}
stale-pr-label: ${{ steps.set-variables.outputs.stale-pr-label }}
exempt-pr-labels: ${{ steps.set-variables.outputs.exempt-pr-labels }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Opinionated GitHub actions and workflows for common continuous integration needs

### - [Slugify](actions/slugify/README.md)

## Workflows
## Reusable Workflows

### - [Generate dependabot config](.github/workflows/generate-dependabot-config.md)

Expand Down

0 comments on commit 224cb15

Please sign in to comment.