deployment-status icon indicating copy to clipboard operation
deployment-status copied to clipboard

Note: If you want to show deployments in PRs / pull requests, pass `ref`

Open tony opened this issue 4 years ago • 5 comments

Want this?

image

Pass your branch name to ref ref: <your branch>

Looks like this:

name: CI

on:
  push:
    branches: [master]
  pull_request:

jobs:
  deployment:
    steps:
      - name: Get git output names
        id: git
        shell: bash
        run: |
          if [[ "${{ github.ref }}" != "refs/tags/"* ]]; then
            if [[ ${{ github.event_name }} == 'pull_request' ]]; then
              echo "::set-output name=current_branch::$HEAD_REF"
            else
              echo "::set-output name=current_branch::$REF_BRANCH"
            fi
          else
            REF=$(printf "%q" "${{ github.ref }}")
            REF_BRANCH=${REF/refs\/tags\/${{ inputs.strip_tag_prefix }}/}
            echo "::set-output name=current_branch::$(eval printf "%s" "$REF_BRANCH")"
          fi
  
      - uses: chrnorm/deployment-action@releases/v1
        name: Create GitHub deployment
        id: deployment
        with:
          token: "${{ github.token }}"
          target_url: http://my-app-url.com
          environment: production
          ref: ${{ steps.git.outputs.current_branch }}
  
      - name: Deploy my app
        run: |
          # add your deployment code here
  
      - name: Update deployment status (success)
        if: success()
        uses: chrnorm/deployment-status@releases/v1
        with:
          token: "${{ github.token }}"
          target_url: http://my-app-url.com
          state: "success"
          deployment_id: ${{ steps.deployment.outputs.deployment_id }}
          ref: ${{ steps.git.outputs.current_branch }}
  
      - name: Update deployment status (failure)
        if: failure()
        uses: chrnorm/deployment-status@releases/v1
        with:
          token: "${{ github.token }}"
          target_url: http://my-app-url.com
          state: "failure"
          deployment_id: ${{ steps.deployment.outputs.deployment_id }}
          ref: ${{ steps.git.outputs.current_branch }}

In practice, I used a fork with @jimCresswell's change at #26

tony avatar Sep 30 '21 11:09 tony

Thanks for this @tony! I've pinned this issue for visibility.

chrnorm avatar May 21 '22 22:05 chrnorm

@tony are you sure about that?

There is no reference to 'ref' in the code as you can see here: https://github.com/chrnorm/deployment-status/blob/7a586aaf8193756591e6e9590a581789583ce4b8/src/main.ts#L51

I think it needs to add something like this

...
const ref = core.getInput('ref', {required: false}) || ''
...
await octokit.rest.repos.createDeploymentStatus({
      owner,
      repo,
      environment,
      auto_inactive: autoInactive, // GitHub API defaults to true if undefined.
      deployment_id: parseInt(deploymentId),
      state,
      log_url: logUrl,
      description,
      environment_url: environmentUrl,
      ref
    })
...

matteovivona avatar Jan 29 '24 08:01 matteovivona

@matteovivona I may not have time to look until the weekend, but I don't remember since this was a few years ago. Things may have changed since I originally wrote the message, I could also have made a mistake / have been wrong.

tony avatar Jan 29 '24 10:01 tony

Right now, you don't need to specify ref option. With v2.0.1 you just need to specify these options here:

      - name: Updates deployment status
        uses: chrnorm/[email protected]
        with:
          state: "in_progress"
          deployment-id: ${{ steps.deployment.outputs.deployment_id }}
          token: ${{ secrets.PAT }}
          environment: production
          environment-url: https://github.com

matteovivona avatar Feb 06 '24 17:02 matteovivona