Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tony opened this issue Sep 30, 2021 · 4 comments
Open

Comments

@tony
Copy link

tony commented Sep 30, 2021

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

@chrnorm chrnorm pinned this issue May 21, 2022
@chrnorm
Copy link
Owner

chrnorm commented May 21, 2022

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

@matteovivona
Copy link

matteovivona commented Jan 29, 2024

@tony are you sure about that?

There is no reference to 'ref' in the code as you can see here:

await octokit.rest.repos.createDeploymentStatus({

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
    })
...

@tony
Copy link
Author

tony commented Jan 29, 2024

@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.

@matteovivona
Copy link

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/deployment-status@v2.0.1
        with:
          state: "in_progress"
          deployment-id: ${{ steps.deployment.outputs.deployment_id }}
          token: ${{ secrets.PAT }}
          environment: production
          environment-url: https://github.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants