Code Monkey home page Code Monkey logo

get-workflow-origin's Introduction

get-workflow-origin status

NOTE! This project is not actively maintained. There are other ways to get this information from workflow (for example Github API in Python) that are likely easier to maintain and use.

If someone would like to take over maintenance of it I am happy to transfer it or you can make a fork of this project.

Get Workflow Origin action

Table of Contents generated with DocToc

Context and motivation

Get Workflow Origin is an action that provides information about the pull requests that triggered the workflow for the pull_request and pull_request_review events or for the workflow_run event that is triggered by one of those events.

Often in those events you want to get more information about the source run than the one provided directly via GitHub context.

For example, you would like to know what is the merge commit generated by pull request in case the workflow is triggered by a pull request, or labels associated with the Pull Request.

This action provides outputs that give that information. You should add this action as first one in your workflow and then you will be able to use those outputs using 'needs' dependency.

The sourceRunId input should not be specified in case of the pull_request event, but it should be set to ${{ github.event.workflow_run.id }} in case of the workflow_run event.

Inputs and outputs

Inputs

Input Required Default Comment
token yes The github token passed from ${{ secrets.GITHUB_TOKEN }}
sourceRunId no In case of 'workflow_run' event it should be set to ${{ github.event.workflow_run.id }}

Outputs

Output No sourceRunId specified The sourceRunId set to ${{ github.event.workflow_run.id }}
sourceHeadRepo Current repository. Format: owner/repo Repository of the run that triggered this workflow_run. Format: owner/repo
sourceHeadBranch Current branch. Branch of the run that triggered this workflow_run. Might be forked repo, if it is a pull_request.
sourceHeadSha Current commit SHA: {{ github.sha }} Commit sha of the run that triggered this workflow_run.
mergeCommitSha Merge commit SHA if PR-triggered event. Merge commit SHA if PR-triggered event.
targetCommitSha Target commit SHA (merge if present, otherwise source). Target commit SHA (merge if present, otherwise source).
pullRequestNumber Number of the associated Pull Request (if PR triggered) Number of the associated Pull Request (if PR triggered)
pullRequestLabels Stringified JSON array of Labels of the associated Pull Request (if PR triggered) Stringified JSON array of Labels of the associated Pull Request (if PR triggered)
targetBranch Target branch of the pull request or target branch for push Target branch of the pull request or target branch for push
sourceEvent Current event: ${{ github.event }} Event of the run that triggered this workflow_run

Examples

Workflow Run event

name: Get information
on:
  pull_request:
    branches: ['main']

jobs:
  get-info:
    name: "Get information about the source run"
    runs-on: ubuntu-latest
    outputs:
      sourceHeadRepo: ${{ steps.workflow-run-info.outputs.sourceHeadRepo }}
      sourceHeadBranch: ${{ steps.workflow-run-info.outputs.sourceHeadBranch }}
      sourceHeadSha: ${{ steps.workflow-run-info.outputs.sourceHeadSha }}
      mergeCommitSha: ${{ steps.workflow-run-info.outputs.mergeCommitSha }}
      targetCommitSha: ${{ steps.workflow-run-info.outputs.targetCommitSha }}
      pullRequestNumber: ${{ steps.workflow-run-info.outputs.pullRequestNumber }}
      pullRequestLabels: ${{ steps.workflow-run-info.outputs.pullRequestLabels }}
      targetBranch: ${{ steps.source-run-info.outputs.targetBranch }}
      sourceEvent: ${{ steps.workflow-run-info.outputs.sourceEvent }}
    steps:
      - name: "Get information about the current run"
        uses: potiuk/get-workflow-origin@v1_1
        id: workflow-run-info
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

Workflow Run event

name: Build
on:
  workflow_run:
    workflows: ['CI']
    types: ['requested']

jobs:
  get-info:
    name: "Get information about the source run"
    runs-on: ubuntu-latest
    outputs:
      sourceHeadRepo: ${{ steps.source-run-info.outputs.sourceHeadRepo }}
      sourceHeadBranch: ${{ steps.source-run-info.outputs.sourceHeadBranch }}
      sourceHeadSha: ${{ steps.source-run-info.outputs.sourceHeadSha }}
      mergeCommitSha: ${{ steps.source-run-info.outputs.mergeCommitSha }}
      targetCommitSha: ${{ steps.source-run-info.outputs.targetCommitSha }}
      pullRequestNumber: ${{ steps.source-run-info.outputs.pullRequestNumber }}
      pullRequestLabels: ${{ steps.source-run-info.outputs.pullRequestLabels }}
      targetBranch: ${{ steps.source-run-info.outputs.targetBranch }}
      sourceEvent: ${{ steps.source-run-info.outputs.sourceEvent }}
    steps:
      - name: "Get information about the origin 'CI' run"
        uses: potiuk/get-workflow-origin@v1_1
        id: source-run-info
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          sourceRunId: ${{ github.event.workflow_run.id }}```

Development environment

It is highly recommended tu use pre commit. The pre-commits installed via pre-commit tool handle automatically linting (including automated fixes) as well as building and packaging Javascript index.js from the main.ts Typescript code, so you do not have to run it yourself.

License

MIT License covers the scripts and documentation in this project.

get-workflow-origin's People

Contributors

danepowell avatar ferruzzi avatar potiuk avatar thedaviddias avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

get-workflow-origin's Issues

v1_6 fails with file not found

Using v1_6 fails with error:

Run potiuk/get-workflow-origin@v1_6
Error: File not found: '/runner/_work/_actions/potiuk/get-workflow-origin/v1_6/dist/index.js'

Get origin of workflow triggered by `issue_comment`

if the origin workflow was triggered by a issue_comment event on a pull request, this action doesn't determine the pull request number correctly:

Run potiuk/get-workflow-origin@v1_1
  with:
    token: ***
    sourceRunId: 4[2](https://github.com/flyweightrocks/nebula/actions/runs/4202039823/jobs/7289700802#step:2:2)020[3](https://github.com/flyweightrocks/nebula/actions/runs/4202039823/jobs/7289700802#step:2:3)7368
[@octokit/rest] `const Octokit = require("@octokit/rest")` is deprecated. Use `const { Octokit } = require("@octokit/rest")` instead
[@octokit/rest] `const Octokit = require("@octokit/rest")` is deprecated. Use `const { Octokit } = require("@octokit/rest")` instead

Getting workflow id for source run id: [4](https://github.com/flyweightrocks/nebula/actions/runs/4202039823/jobs/7289700802#step:2:4)202037368, owner: flyweightrocks, repo: nebula

The source run 4202037368 is in https://api.github.com/repos/flyweightrocks/nebula/actions/workflows/48[5](https://github.com/flyweightrocks/nebula/actions/runs/4202039823/jobs/7289700802#step:2:6)8[6](https://github.com/flyweightrocks/nebula/actions/runs/4202039823/jobs/7289700802#step:2:7)1[7](https://github.com/flyweightrocks/nebula/actions/runs/4202039823/jobs/7289700802#step:2:8)0 workflow
Repository: flyweightrocks/nebula, Owner: flyweightrocks, Repo: nebula, Event name: workflow_run,sourceWorkflowId: 4[8](https://github.com/flyweightrocks/nebula/actions/runs/4202039823/jobs/7289700802#step:2:9)586170, sourceRunId: 4202037368, selfRunId: 420203[9](https://github.com/flyweightrocks/nebula/actions/runs/4202039823/jobs/7289700802#step:2:10)823, 
Source workflow: Head repo: flyweightrocks/nebula, Head branch: master Event: issue_comment, Head sha: ce6e183eeac85ab7ee[10](https://github.com/flyweightrocks/nebula/actions/runs/4202039823/jobs/7289700802#step:2:11)ee960e36250029c7c043, url: https://api.github.com/repos/flyweightrocks/nebula/actions/runs/4202037368
Setting output: sourceHeadRepo: flyweightrocks/nebula
Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-[11](https://github.com/flyweightrocks/nebula/actions/runs/4202039823/jobs/7289700802#step:2:12)-github-actions-deprecating-save-state-and-set-output-commands/
Setting output: sourceHeadBranch: master
Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
Setting output: sourceHeadSha: ce6e183eeac85ab7ee10ee960e36250029c7c043
Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
Setting output: sourceEvent: issue_comment
Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
Setting output: pullRequestNumber: 
Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
Setting output: pullRequestLabels: []
Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
Setting output: mergeCommitSha: 
Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
Setting output: targetCommitSha: ce6e[18](https://github.com/flyweightrocks/nebula/actions/runs/4202039823/jobs/7289700802#step:2:19)3eeac85ab7ee10ee960e36250029c7c043
Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

############### Get Workflow Origin complete ##################

Did you consider supporting this issue_event?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.