diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 4c431dc..fe8b5f7 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -79,3 +79,22 @@ jobs: assert.ok(changelogContent.includes('v0.1.0 (2025-11-20)'), 'Expected changelog to contain version 0.1.0'); assert.ok(changelogContent.includes('### Feat'), 'Expected changelog to contain a header for features'); assert.ok(changelogContent.includes('### Fix'), 'Expected changelog to contain a header for fixes'); + test-trigger-other-job: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + - uses: ./ + - id: get-version + run: | + current_version="$(cz version -p)" # ATTENTION: You may have to add the v* at the beginning of the version + echo "current_version=$current_version" >> $GITHUB_OUTPUT + - name: trigger other workflow + env: + GH_TOKEN: ${{ github.token }} + run: | + gh workflow list + gh workflow run .github/workflows/trigger-me.yaml \ + --ref "${{ github.head_ref }}" \ + -f "version=${{ steps.get-version.outputs.current_version }}" diff --git a/.github/workflows/trigger-me.yaml b/.github/workflows/trigger-me.yaml new file mode 100644 index 0000000..e84827d --- /dev/null +++ b/.github/workflows/trigger-me.yaml @@ -0,0 +1,16 @@ +on: + workflow_dispatch: + inputs: + version: + description: "Version to trigger" + required: true + +jobs: + triggered-echo: + runs-on: ubuntu-latest + permissions: + actions: write + steps: + - name: Trigger other job + run: | + echo "Version: ${{ inputs.version }}" diff --git a/examples/trigger-other-job/.github/workflows/README.md b/examples/trigger-other-job/.github/workflows/README.md new file mode 100644 index 0000000..69dc36e --- /dev/null +++ b/examples/trigger-other-job/.github/workflows/README.md @@ -0,0 +1,34 @@ +# Trigger other job + +In this example, we trigger another job without having to configure a PAT token. +This is achieved by using github API and workflow_dispatch event. + +```mermaid +flowchart LR + subgraph BR["bump-release"] + direction TB + bump + git_push["git push"] + create_changelog["create changelog"] + release + workflow_dispatch + + bump --> git_push + git_push --> create_changelog + create_changelog --> release + release --> workflow_dispatch + end + + subgraph TM["trigger-me"] + echo_version["echo version"] + + %% Workaround to increase height of the graph + echo_version ~~~ spacer1[" "]:::hidden + spacer1 ~~~ spacer2[" "]:::hidden + spacer2 ~~~ spacer3[" "]:::hidden + spacer3 ~~~ spacer4[" "]:::hidden + spacer4 ~~~ spacer5[" "]:::hidden + end + + BR --> TM +``` diff --git a/examples/trigger-other-job/.github/workflows/bump-release.yaml b/examples/trigger-other-job/.github/workflows/bump-release.yaml new file mode 100644 index 0000000..ba0d94e --- /dev/null +++ b/examples/trigger-other-job/.github/workflows/bump-release.yaml @@ -0,0 +1,48 @@ +# YES, YOU CAN COPY-PASTE THIS ACTION AND IT SHOULD WORK +# keep in mind, that it won't trigger other actions because it's using action permissions. +# You can: use a PAT token or a workflow_call to trigger another action +on: + push: + branches: + - main + +jobs: + bump: + runs-on: ubuntu-latest + permissions: + contents: write + actions: write + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + fetch-tags: true + - name: Set up git config + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + - uses: commitizen-tools/setup-cz@main + - id: bump-version + run: | + cz bump --yes --annotated-tag + git push --follow-tags + current_version="$(cz version -p)" # ATTENTION: You may have to add the v* at the beginning of the version + echo "current_version=$current_version" >> $GITHUB_OUTPUT + - name: Build changelog for Release + env: + CURRENT_VERSION: ${{ steps.bump-version.outputs.current_version }} + run: | + cz changelog --dry-run "${CURRENT_VERSION}" > .changelog.md + - name: Release + uses: softprops/action-gh-release@v2 + with: + body_path: ".changelog.md" + tag_name: ${{ steps.bump-version.outputs.current_version }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: trigger other workflow + env: + GH_TOKEN: ${{ github.token }} + run: | + gh workflow run .github/workflows/trigger-me.yaml \ + -f "version=${{ steps.bump-version.outputs.current_version }}" diff --git a/examples/trigger-other-job/.github/workflows/trigger-me.yaml b/examples/trigger-other-job/.github/workflows/trigger-me.yaml new file mode 100644 index 0000000..9fa9d2a --- /dev/null +++ b/examples/trigger-other-job/.github/workflows/trigger-me.yaml @@ -0,0 +1,14 @@ +on: + workflow_dispatch: + inputs: + version: + description: "Version to trigger" + required: true + +jobs: + triggered-echo: + runs-on: ubuntu-latest + steps: + - name: Trigger other job + run: | + echo "Version: ${{ inputs.version }}" diff --git a/flake.nix b/flake.nix index a69739b..98d1016 100644 --- a/flake.nix +++ b/flake.nix @@ -27,6 +27,7 @@ python3 nodejs commitizen + gh ]; shellHook = ''