From fce631ef9f3798b72baa8f343edf0ead920726cb Mon Sep 17 00:00:00 2001 From: Emilien Escalle Date: Mon, 16 Dec 2024 20:17:26 +0100 Subject: [PATCH] feat: transfer relase actions workflow Signed-off-by: Emilien Escalle --- .github/ISSUE_TEMPLATE/feature_request.md | 7 +- .github/workflows/__main-ci.yml | 2 +- .github/workflows/need-fix-to-issue.md | 4 +- .github/workflows/release-actions.md | 102 ------- .github/workflows/release-actions.yml | 256 ------------------ README.md | 10 +- .../create-and-merge-pull-request/README.md | 24 +- actions/get-matrix-outputs/README.md | 8 +- actions/set-matrix-output/README.md | 8 +- 9 files changed, 36 insertions(+), 385 deletions(-) delete mode 100644 .github/workflows/release-actions.md delete mode 100644 .github/workflows/release-actions.yml diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index bbcbbe7..2bc5d5f 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,10 +1,9 @@ --- name: Feature request about: Suggest an idea for this project -title: '' -labels: '' -assignees: '' - +title: "" +labels: "" +assignees: "" --- **Is your feature request related to a problem? Please describe.** diff --git a/.github/workflows/__main-ci.yml b/.github/workflows/__main-ci.yml index b71f74b..583a207 100644 --- a/.github/workflows/__main-ci.yml +++ b/.github/workflows/__main-ci.yml @@ -24,7 +24,7 @@ jobs: release: needs: ci - uses: ./.github/workflows/release-actions.yml + uses: hoverkraft-tech/ci-github-publish/.github/workflows/release-actions.yml@0.1.0 with: update-all: ${{ (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) || github.event_name == 'workflow_dispatch' }} github-app-id: ${{ vars.CI_BOT_APP_ID }} diff --git a/.github/workflows/need-fix-to-issue.md b/.github/workflows/need-fix-to-issue.md index 45ca499..2174d2d 100644 --- a/.github/workflows/need-fix-to-issue.md +++ b/.github/workflows/need-fix-to-issue.md @@ -9,8 +9,8 @@ -Reusable workflow to convert comments requiring fixes (TODO, FIXME) to issues. -Mainly using [TODO to Issue Action](https://github.com/alstr/todo-to-issue-action), with some opinionated defaults. +Reusable workflow to convert comments requiring fixes (todo, FIXME) to issues. +Mainly using [Todo to Issue Action](https://github.com/alstr/todo-to-issue-action), with some opinionated defaults. diff --git a/.github/workflows/release-actions.md b/.github/workflows/release-actions.md deleted file mode 100644 index 89352a5..0000000 --- a/.github/workflows/release-actions.md +++ /dev/null @@ -1,102 +0,0 @@ - - - - -# GitHub Reusable Workflow: Release Actions - - - - - - -Reusable workflow that performs actions and workflows release. - -- Generates README for changed actions and workflows (documentation, versioning, etc.) -- Commits and pushes the changes to the main branch - - - - - -# Usage - - - -```yaml -name: "Release Actions" - -on: - push: - branches: [main] - tags: ["*"] - -permissions: - contents: write - # FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659 - id-token: write - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - release: - uses: hoverkraft-tech/ci-github-common/.github/workflows/release-actions.yml@0.14.0 - with: - # Update all actions and workflows, regardless of changes. - update-all: false - - # GitHub App ID to generate GitHub token in place of private-access-token. - # See https://github.com/actions/create-github-app-token. - github-app-id: "" - - secrets: - # GitHub token for creating and merging pull request (permissions contents: write and pull-requests: write, workflows: write). - # See [actions/create-and-merge-pull-request](../../actions/create-and-merge-pull-request) - github-token: "" - - # GitHub App private key to generate GitHub token in place of github-token. - # See https://github.com/actions/create-github-app-token. - github-app-key: "" -``` - - - -## Permissions - - - -This workflow requires the following permissions: - -- `contents: read`: To read the contents of the repository -- `id-token: write`: This is a workaround for having workflow ref. See . - - - -## Secrets - - - -| **Secret** | **Description** | **Default** | **Required** | -| ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------- | ------------ | -| **github-token** | GitHub token for creating and merging pull request (permissions contents: write and pull-requests: write, workflows: write). See [../../actions/create-and-merge-pull-request](../../actions/create-and-merge-pull-request) | GITHUB_TOKEN | **false** | -| **github-app-key** | GitHub App private key to generate GitHub token in place of github-token. See . | | **false** | - - - -## Inputs - - - -| **Input** | **Description** | **Default** | **Required** | -| ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | ------------ | -| **runs-on** | Json array of runner(s) to use. See . | ["ubuntu-latest"] | **false** | -| **update-all** | Update all actions and workflows, regardless of changes. | false | **false** | -| **github-app-id** | GitHub App ID to generate GitHub token in place of private-access-token. See . | | **false** | - - - - - - - diff --git a/.github/workflows/release-actions.yml b/.github/workflows/release-actions.yml deleted file mode 100644 index 59cd981..0000000 --- a/.github/workflows/release-actions.yml +++ /dev/null @@ -1,256 +0,0 @@ -# Release Actions -# ========================== -# Reusable workflow that performs actions and workflows release. -# - Generates README for changed actions and workflows (documentation, versioning, etc.) -# - Commits and pushes the changes to the main branch - -name: Release Actions - -on: - workflow_call: - inputs: - runs-on: - description: "Json array of runner(s) to use. See https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job." - type: string - default: '["ubuntu-latest"]' - required: false - update-all: - description: "Update all actions and workflows, regardless of changes." - required: false - default: false - type: boolean - github-app-id: - description: "GitHub App ID to generate GitHub token in place of private-access-token. See https://github.com/actions/create-github-app-token." - required: false - type: string - secrets: - github-token: - description: "GitHub token for creating and merging pull request (permissions contents: write and pull-requests: write, workflows: write). See [actions/create-and-merge-pull-request](../../actions/create-and-merge-pull-request)" - github-app-key: - description: "GitHub App private key to generate GitHub token in place of github-token. See https://github.com/actions/create-github-app-token." - -permissions: - contents: read - # FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659 - id-token: write - -jobs: - prepare-release: - runs-on: ${{ fromJson(inputs.runs-on) }} - outputs: - changed-actions: ${{ steps.get-changed-actions.outputs.result }} - changed-workflows: ${{ steps.get-changed-workflows.outputs.result }} - latest-tag: ${{ steps.get-latest-tag.outputs.tag }} - - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - id: get-latest-tag - uses: actions-ecosystem/action-get-latest-tag@v1 - - - id: changed-files - if: ${{ inputs.update-all == false }} - uses: tj-actions/changed-files@v45.0.5 - with: - files: | - ./actions/* - ./.github/workflows/* - dir_names_exclude_current_dir: true - - - id: changed-variables - shell: bash - run: | - CHANGED_FILES="${{ steps.changed-files.outputs.all_changed_and_modified_files }}" - echo "changed-files=$CHANGED_FILES" >> "$GITHUB_OUTPUT" - - CURRENT_WORKFLOW=$(echo "${{ github.workflow_ref }}" | sed "s|${{ github.repository }}/||g" | sed 's/@.*//g') - CURRENT_WORKFLOW_HAS_CHANGED=$([[ "$CHANGED_FILES" == *"$CURRENT_WORKFLOW"* ]] && echo "true" || echo "false") - UPDATE_ALL="${{ inputs.update-all }}" - - FORCE_UPDATE=$([[ "$CURRENT_WORKFLOW_HAS_CHANGED" = "true" || "$UPDATE_ALL" = "true" ]] && echo "true" || echo "false") - echo "force-update=$FORCE_UPDATE" >> "$GITHUB_OUTPUT" - - - id: get-changed-actions - shell: bash - run: | - CHANGED_FILES="${{ steps.changed-variables.outputs.changed-files }}" - FORCE_UPDATE="${{ steps.changed-variables.outputs.force-update }}" - - CHANGED_ACTIONS=() - while read -r FILE; do - ACTION_HAS_CHANGED=$([[ "$CHANGED_FILES" == *"$FILE"* ]] && echo "true" || echo "false") - SHOULD_UPDATE_FILE=$([[ "$FORCE_UPDATE" = "true" || "$ACTION_HAS_CHANGED" = "true" ]] && echo "true" || echo "false") - echo "::debug::File $FILE has changed: $ACTION_HAS_CHANGED, should update file: $SHOULD_UPDATE_FILE" - - if [ "$SHOULD_UPDATE_FILE" == "true" ]; then - CHANGED_ACTIONS+=("$(dirname "$FILE")") - fi - done < <(find actions -name "action.yml" -type f) - - echo "::debug::Changed files: ${CHANGED_ACTIONS[*]}" - JSON_CHANGED_ACTIONS=$(jq --compact-output --null-input '$ARGS.positional' --args -- "${CHANGED_ACTIONS[@]}"); - echo "result<> "$GITHUB_OUTPUT" && echo "$JSON_CHANGED_ACTIONS" >> "$GITHUB_OUTPUT" && echo "EOF" >> "$GITHUB_OUTPUT" - - - id: get-changed-workflows - shell: bash - run: | - CHANGED_FILES="${{ steps.changed-variables.outputs.changed-files }}" - FORCE_UPDATE="${{ steps.changed-variables.outputs.force-update }}" - - CHANGED_WORKFLOWS=() - for FILE in .github/workflows/*.yml; do - # Ignore internal workflows - if [[ $(basename "$FILE") == __* ]]; then - continue - fi - - WORKFLOW_HAS_CHANGED=$([[ "$CHANGED_FILES" == *"$FILE"* ]] && echo "true" || echo "false") - SHOULD_UPDATE_FILE=$([[ "$FORCE_UPDATE" = "true" || "$WORKFLOW_HAS_CHANGED" = "true" ]] && echo "true" || echo "false") - echo "::debug::File $FILE has changed: $WORKFLOW_HAS_CHANGED, should update file: $SHOULD_UPDATE_FILE" - - if [ "$SHOULD_UPDATE_FILE" == "true" ]; then - CHANGED_WORKFLOWS+=("$FILE") - fi - done - - echo "::debug::Changed files: ${CHANGED_WORKFLOWS[*]}" - JSON_CHANGED_WORKFLOWS=$(jq --compact-output --null-input '$ARGS.positional' --args -- "${CHANGED_WORKFLOWS[@]}"); - echo "result<> "$GITHUB_OUTPUT" && echo "$JSON_CHANGED_WORKFLOWS" >> "$GITHUB_OUTPUT" && echo "EOF" >> "$GITHUB_OUTPUT" - - generate-actions-readme: - needs: prepare-release - runs-on: ${{ fromJson(inputs.runs-on) }} - if: ${{ needs.prepare-release.outputs.changed-actions != '[]' }} - strategy: - fail-fast: false - matrix: - action: ${{ fromJson(needs.prepare-release.outputs.changed-actions) }} - steps: - - uses: actions/checkout@v4 - - # FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659 - # jscpd:ignore-start - - id: oidc - uses: ChristopherHX/oidc@v3 - - uses: actions/checkout@v4 # checks out called workflow - with: - path: ./self-workflow - repository: ${{ steps.oidc.outputs.job_workflow_repo_name_and_owner }} - ref: ${{ steps.oidc.outputs.job_workflow_repo_ref }} - # jscpd:ignore-end - - - id: action-slug - uses: ./self-workflow/actions/slugify - with: - value: ${{ matrix.action }} - - - id: prepare-readme-generator - run: | - jq '.paths.action = "${{ matrix.action }}/action.yml"' .ghadocs.json > .ghadocs.json.tmp - mv .ghadocs.json.tmp .ghadocs.json - - jq '.paths.readme = "${{ matrix.action }}/README.md"' .ghadocs.json > .ghadocs.json.tmp - mv .ghadocs.json.tmp .ghadocs.json - - WORKSPACE_PATH=$(echo "${{ github.workspace }}" | sed 's/\/\([^/]\+\)/\/*\1/') - echo "readme-file=${WORKSPACE_PATH}/${{ matrix.action }}/README.md" >> "$GITHUB_OUTPUT" - - - name: 📖 Generate README - uses: bitflight-devops/github-action-readme-generator@v1.8.0 - with: - action: ${{ matrix.action }}/action.yml - readme: ${{ matrix.action }}/README.md - owner: ${{ github.repository_owner }} - repo: ${{ github.event.repository.name }} - pretty: true - versioning_enabled: true - version_prefix: "" - version_override: ${{ needs.prepare-release.outputs.latest-tag }} - branding_as_title_prefix: true - env: - INPUT_SHOW_LOGO: "true" - - - uses: actions/upload-artifact@v4 - with: - name: changed-files-${{ steps.action-slug.outputs.result }} - path: ${{ steps.prepare-readme-generator.outputs.readme-file }} - - generate-workflows-readme: - needs: prepare-release - runs-on: ${{ fromJson(inputs.runs-on) }} - if: ${{ needs.prepare-release.outputs.changed-workflows != '[]' }} - strategy: - fail-fast: false - matrix: - workflow: ${{ fromJson(needs.prepare-release.outputs.changed-workflows) }} - steps: - - uses: actions/checkout@v4 - - # FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659 - # jscpd:ignore-start - - id: oidc - uses: ChristopherHX/oidc@v3 - - uses: actions/checkout@v4 # checks out called workflow - with: - path: ./self-workflow - repository: ${{ steps.oidc.outputs.job_workflow_repo_name_and_owner }} - ref: ${{ steps.oidc.outputs.job_workflow_repo_ref }} - # jscpd:ignore-end - - - id: workflow-slug - uses: ./self-workflow/actions/slugify - with: - value: ${{ matrix.workflow }} - - - name: 📖 Generate README - id: generate-readme - run: | - # Readme file is same name but without yml by .md extension - WORKFLOW_FILE="${{ matrix.workflow }}" - README_FILE="${WORKFLOW_FILE%.*}.md" - - WORKSPACE_PATH=$(echo "${{ github.workspace }}" | sed 's/\/\([^/]\+\)/\/*\1/') - echo "readme-file=${WORKSPACE_PATH}/${README_FILE}" >> "$GITHUB_OUTPUT" - - WORKFLOW_FULL_PATH="${{ github.repository }}/${WORKFLOW_FILE}" - sed -i "s|${WORKFLOW_FULL_PATH}@.*|${WORKFLOW_FULL_PATH}@${{ needs.prepare-release.outputs.latest-tag }}|g" "${README_FILE}" - - - uses: actions/upload-artifact@v4 - with: - name: changed-files-${{ steps.workflow-slug.outputs.result }} - path: ${{ steps.generate-readme.outputs.readme-file }} - - publish-actions-readme: - needs: [prepare-release, generate-actions-readme, generate-workflows-readme] - if: always() && (needs.prepare-release.outputs.changed-actions != '[]' || needs.prepare-release.outputs.changed-workflows != '[]') - runs-on: ${{ fromJson(inputs.runs-on) }} - steps: - - uses: actions/checkout@v4 - - - uses: actions/download-artifact@v4 - with: - pattern: changed-files-* - merge-multiple: true - path: / - - # jscpd:ignore-start - - uses: actions/create-github-app-token@v1 - if: inputs.github-app-id - id: generate-token - with: - app-id: ${{ inputs.github-app-id }} - private-key: ${{ secrets.github-app-key }} - - - uses: hoverkraft-tech/ci-github-common/actions/create-and-merge-pull-request@main - with: - github-token: ${{ steps.generate-token.outputs.token || secrets.github-token || github.token }} - branch: docs/actions-workflows-documentation-update - title: "docs: update actions and workflows documentation" - body: Update actions and workflows documentation - commit-message: | - docs: update actions and workflows documentation - - [skip ci] - # jscpd:ignore-end diff --git a/README.md b/README.md index 4c17215..72522b2 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![License](https://img.shields.io/badge/License-MIT-blue)](#license) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) -Opinionated GitHub actions and workflows for common continuous integration needs +Opinionated GitHub Actions and workflows for common continuous integration needs --- @@ -17,7 +17,7 @@ Opinionated GitHub actions and workflows for common continuous integration needs ### - [Create or update comment](actions/create-or-update-comment/README.md) -### - [Get GitHub actions bot user](actions/get-github-actions-bot-user/README.md) +### - [Get GitHub Actions bot user](actions/get-github-actions-bot-user/README.md) ### - [Get issue number](actions/get-issue-number/README.md) @@ -37,8 +37,6 @@ Opinionated GitHub actions and workflows for common continuous integration needs ### - [Need fix to Issue](.github/workflows/need-fix-to-issue.md) -### - [Release actions](.github/workflows/release-actions.md) - ### - [Semantic pull request](.github/workflows/semantic-pull-request.md) ### - [Stale](.github/workflows/stale.md) @@ -51,8 +49,8 @@ Opinionated GitHub actions and workflows for common continuous integration needs 🏢 **Hoverkraft ** -- Website: [https://hoverkraft.cloud](https://hoverkraft.cloud) -- Github: [@hoverkraft-tech](https://github.com/hoverkraft-tech) +- Site: [https://hoverkraft.cloud](https://hoverkraft.cloud) +- GitHub: [@hoverkraft-tech](https://github.com/hoverkraft-tech) ## License diff --git a/actions/create-and-merge-pull-request/README.md b/actions/create-and-merge-pull-request/README.md index 003aa4b..f216c96 100644 --- a/actions/create-and-merge-pull-request/README.md +++ b/actions/create-and-merge-pull-request/README.md @@ -6,7 +6,11 @@ -Release%20by%20tagRelease%20by%20dateCommitOpen%20IssuesDownloads +Release%20by%20tag +Release%20by%20date +Commit +Open%20Issues +Downloads @@ -16,8 +20,8 @@ Action to create and merge Pull Request. Opinionated, set GitHub Actions bot as -For this action to work you must explicitly allow GitHub Actions to create pull requests. See [ -Allow GitHub Actions to create and approve pull requests](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository) +For this action to work you must explicitly allow GitHub Actions to create pull requests. +See [Allow GitHub Actions to create and approve pull requests](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository) @@ -59,13 +63,13 @@ Allow GitHub Actions to create and approve pull requests](https://docs.github.co -| **Input** | **Description** | **Default** | **Required** | -| --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- | ------------ | -| github-token | GitHub token for creating and merging pull request (permissions contents: write and pull-requests: write). See https://github.com/peter-evans/create-pull-request#action-inputs. | ${{ github.token }} | **false** | -| branch | The pull request branch name | | **true** | -| title | The pull request title | | **true** | -| body | The pull request body | | **true** | -| commit-message | The commit message for the pull request | | **true** | +| **Input** | **Description** | **Default** | **Required** | +| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- | ------------ | +| github-token | GitHub token for creating and merging pull request (permissions contents: write and pull-requests: write). See . | ${{ github.token }} | **false** | +| branch | The pull request branch name | | **true** | +| title | The pull request title | | **true** | +| body | The pull request body | | **true** | +| commit-message | The commit message for the pull request | | **true** | diff --git a/actions/get-matrix-outputs/README.md b/actions/get-matrix-outputs/README.md index e949315..4f93953 100644 --- a/actions/get-matrix-outputs/README.md +++ b/actions/get-matrix-outputs/README.md @@ -8,7 +8,11 @@ --> -Release%20by%20tagRelease%20by%20dateCommitOpen%20IssuesDownloads +Release%20by%20tag +Release%20by%20date +Commit +Open%20Issues +Downloads -Download matrix ouputs from artifacts, because GitHub action does not handle job outputs for matrix +Download matrix ouputs from artifacts, because GitHub Action does not handle job outputs for matrix diff --git a/actions/set-matrix-output/README.md b/actions/set-matrix-output/README.md index 0b7d593..d7b6160 100644 --- a/actions/set-matrix-output/README.md +++ b/actions/set-matrix-output/README.md @@ -8,7 +8,11 @@ --> -Release%20by%20tagRelease%20by%20dateCommitOpen%20IssuesDownloads +Release%20by%20tag +Release%20by%20date +Commit +Open%20Issues +Downloads -Set matrix ouput in file to be uploaded as artifacts, because GitHub action does not handle job outputs for matrix +Set matrix ouput in file to be uploaded as artifacts, because GitHub Action does not handle job outputs for matrix