Skip to content

Commit

Permalink
feat(workflows): use reusable workflows for internal workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
neilime committed Mar 3, 2023
1 parent c9c67ae commit 63b6d05
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 142 deletions.
97 changes: 6 additions & 91 deletions .github/workflows/__main-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,96 +8,11 @@ on:
jobs:
ci:
uses: ./.github/workflows/__shared-ci.yml
secrets:
github-token: ${{ secrets.GITHUB_TOKEN }}

prepare-release:
release:
needs: ci
runs-on: "ubuntu-latest"
outputs:
changed-actions: ${{ steps.get-changed-actions.outputs.result }}
latest-tag: ${{ steps.get-latest-tag.outputs.tag }}

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- id: get-latest-tag
uses: actions-ecosystem/action-get-latest-tag@v1

- id: changed-files
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}
uses: tj-actions/changed-files@v35.6.0
with:
files: |
./actions/*
dir_names: true
dir_names_exclude_root: true

- id: get-changed-actions
run: |
CHANGED_FILES="${{ steps.changed-files.outputs.all_changed_and_modified_files }}"
IS_TAG_PUSH="${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}"
CHANGED_ACTIONS=()
for ACTION_FILE in actions/**/action.yml; do
ACTION_DIR=$(dirname "$ACTION_FILE")
if [ "$IS_TAG_PUSH" = "true" ] || [[ "$CHANGED_FILES" == *"$ACTION_DIR"* ]]; then
CHANGED_ACTIONS+=("$ACTION_DIR")
fi
done
JSON_CHANGED_ACTIONS=$(jq --compact-output --null-input '$ARGS.positional' --args -- "${CHANGED_ACTIONS[@]}");
echo "result<<EOF" >> "$GITHUB_OUTPUT" && echo "$JSON_CHANGED_ACTIONS" >> "$GITHUB_OUTPUT" && echo "EOF" >> "$GITHUB_OUTPUT"
generate-actions-readme:
needs: prepare-release
runs-on: ubuntu-latest
if: ${{ needs.prepare-release.outputs.changed-actions != '[]' }}
strategy:
fail-fast: false
matrix:
action: ${{ fromJson(needs.prepare-release.outputs.changed-actions) }}
steps:
- uses: actions/checkout@v3

- name: 📖 Generate README
uses: bitflight-devops/github-action-readme-generator@v1.3.14
with:
action: ${{ matrix.action }}/action.yml
readme: ${{ matrix.action }}/README.md
versioning_enabled: true
version_prefix: ""
version_override: ${{ needs.prepare-release.outputs.latest-tag }}

env:
INPUT_SHOW_LOGO: "true"

- uses: actions/upload-artifact@v3
with:
name: changed-actions
path: ${{ github.workspace }}/**/${{ matrix.action }}/README.md

publish-actions-readme:
needs: generate-actions-readme
runs-on: ubuntu-latest

permissions:
contents: write

steps:
- uses: actions/checkout@v3.1.0
with:
token: ${{ secrets.GH_PAT }}

- uses: actions/download-artifact@v3
with:
name: changed-actions

- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "chore: update actions README"
commit_options: "--no-verify --signoff"
push_options: "--force-with-lease"
file_pattern: actions/**/README.md
branch: main
uses: ./.github/workflows/release-actions.yml
secrets:
private-access-token: ${{ secrets.GH_PAT }}
3 changes: 2 additions & 1 deletion .github/workflows/__pull-request-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ on:

jobs:
ci:
name: Continuous Integration
uses: ./.github/workflows/__shared-ci.yml
secrets:
github-token: ${{ secrets.GITHUB_TOKEN }}
25 changes: 9 additions & 16 deletions .github/workflows/__shared-ci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
name: Internal - Continuous Integration for common tasks
name: Internal - Common Continuous Integration tasks

on:
workflow_call:
secrets:
github-token:
description: 'Token for marking the status of linter run in the Checks section. Can be passed in using "secrets.GITHUB_TOKEN". See https://github.com/github/super-linter#how-to-use'
required: true

jobs:
checks:
runs-on: "ubuntu-latest"
name: Run checks
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: 👕 Lint Code Base
uses: github/super-linter/slim@v4
env:
VALIDATE_ALL_CODEBASE: false
LOG_LEVEL: WARN
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
linter:
uses: ./.github/workflows/linter.yml
secrets:
github-token: ${{ secrets.github-token }}
23 changes: 0 additions & 23 deletions .github/workflows/__shared-get-available-actions.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/linter.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ jobs:
<!-- end usage -->
<!-- start secrets -->
| **Secret** | **Description** |
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **<code>github-token</code>** | Token for marking the status of linter run in the Checks section. Can be passed in using "${{ secrets.GITHUB_TOKEN }}". See https://github.com/github/super-linter#how-to-use |
| **Secret** | **Description** |
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **<code>github-token</code>** | Token for marking the status of linter run in the Checks section. Can be passed in using "${{ secrets.GITHUB_TOKEN }}". See [https://github.com/github/super-linter#how-to-use](https://github.com/github/super-linter#how-to-use) |
<!-- end secrets -->
<!-- start inputs -->
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ jobs:
uses: hoverkraft-tech/ci-github-common/.github/workflows/release-actions.yml@main
with:
# Private Access Token for commiting changes and bypassing branch protection if any.
github-token: ${{ secrets.GH_PAT }}
private-access-token: ${{ secrets.GH_PAT }}
```
<!-- end usage -->
<!-- start secrets -->
| **Secret** | **Description** |
| ----------------------------- | ---------------------------------------------------------------------------------- |
| **<code>github-token</code>** | Private Access Token for commiting changes and bypassing branch protection if any. |
| **Secret** | **Description** |
| ------------------------------------- | ---------------------------------------------------------------------------------- |
| **<code>private-access-token</code>** | Private Access Token for commiting changes and bypassing branch protection if any. |
<!-- end secrets -->
<!-- start inputs -->
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/release-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ name: Release Actions
on:
workflow_call:
secrets:
github-token:
private-access-token:
description: "Private Access Token for commiting changes and bypassing branch protection if any."
required: true

jobs:
prepare-release:
needs: ci
runs-on: "ubuntu-latest"
outputs:
changed-actions: ${{ steps.get-changed-actions.outputs.result }}
Expand Down Expand Up @@ -93,7 +92,7 @@ jobs:
steps:
- uses: actions/checkout@v3.1.0
with:
token: ${{ secrets.token }}
token: ${{ secrets.private-access-token }}

- uses: actions/download-artifact@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/semantic-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
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'
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:
Expand Down

0 comments on commit 63b6d05

Please sign in to comment.