Giter Site home page Giter Site logo

deployment-action's Introduction

deployment-action

A GitHub action to create Deployments as part of your GitHub CI workflows.

Required Permissions

**Important: you must grant your GitHub Actions workflow deployment permissions as shown below. Otherwise, this Action will not work.

jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest

    permissions:
      deployments: write

    # ...

Example usage

name: Deploy

on: [push]

jobs:
  deploy:
    name: Deploy my app

    runs-on: ubuntu-latest

    permissions:
      deployments: write

    steps:
      - uses: actions/checkout@v4

      - uses: chrnorm/deployment-action@v2
        name: Create GitHub deployment
        id: deployment
        with:
          token: '${{ github.token }}'
          environment-url: http://my-app-url.com
          environment: production
        # more steps below where you run your deployment scripts inside the same action

Action inputs

name description
initial-status (Optional) Initial status for the deployment. Must be one of the accepted strings
repo (Optional) A custom repository to create the deployment for. Defaults to the repo the action is running in.
owner A custom owner to create the deployment for. Defaults to the repo owner the action is running in.
token GitHub token
log-url (Optional) Sets the URL for deployment output
description (Optional) Descriptive message about the deployment
environment (Optional - default is production) Name for the target deployment environment
environment-url (Optional) Sets the URL for accessing your environment
auto-merge (Optional - default is false) Whether to attempt to auto-merge the default branch into the branch that the action is running on if set to "true". More details in the GitHub deployments API. Warning - setting this to "true" has caused this action to fail in some cases
ref (Optional - default is GITHUB_HEAD_REF if set and GITHUB_REF otherwise) The ref to deploy. This can be a branch, tag, or SHA. More details in the GitHub deployments API.
sha (Optional) The SHA recorded at creation time. More details in the GitHub deployments API.
task (Optional) The name of the task for the deployment (e.g., deploy or deploy:migrations). Defaults to deploy. More details in the GitHub deployments API.
required-contexts (Optional) If provided, must be formatted as a comma-separated string. The status contexts to verify against commit status checks. If you omit this parameter, GitHub verifies all unique contexts before creating a deployment. To bypass checking entirely, pass an empty array. Defaults to all unique contexts.
payload (Optional) JSON payload with extra information about the deployment. Can be provided as a JSON string.
transient-environment (Optional) Specifies if the given environment is specific to the deployment and will no longer exist at some point in the future.
production-environment (Optional) Specifies if the given environment is one that end-users directly interact with. Default: true when environment is production and false otherwise.
auto-inactive (Optional) Adds a new inactive status to all prior non-transient, non-production environment deployments with the same repository and environment name as the created status's deployment. An inactive status is only added to deployments that had a success state. Default: true
github-base-url (Optional) Changes the API base URL for a GitHub Enterprise server.

Action outputs

name description
deployment_id The ID of the deployment as returned by the GitHub API
deployment_url The URL of the created deployment
environment_url The environment URL of the deployment (the same as the input variable)

Notes

Heads up! Currently, there is a GitHub Actions limitation where events fired inside an action will not trigger further workflows. If you use this action in your workflow, it will not trigger any "Deployment" workflows. Thanks to @rclayton-the-terrible for finding a workaround for this:

While not ideal, if you use a token that is not the Action's GITHUB_TOKEN, this will work. I define a secret called GITHUB_DEPLOY_TOKEN and use that for API calls.

A workaround for this is to create the Deployment, perform the deployment steps, and then trigger an action to create a Deployment Status using my other action: chrnorm/deployment-status.

For example:

name: Deploy

on: [push]

jobs:
  deploy:
    name: Deploy my app

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v1

      - uses: chrnorm/deployment-action@v2
        name: Create GitHub deployment
        id: deployment
        with:
          token: '${{ github.token }}'
          environment-url: http://my-app-url.com
          environment: production

      - name: Deploy my app
        run: |
          # add your deployment code here

      - name: Update deployment status (success)
        if: success()
        uses: chrnorm/deployment-status@v2
        with:
          token: '${{ github.token }}'
          environment-url: ${{ steps.deployment.outputs.environment_url }}
          deployment-id: ${{ steps.deployment.outputs.deployment_id }}
          state: 'success'

      - name: Update deployment status (failure)
        if: failure()
        uses: chrnorm/deployment-status@v2
        with:
          token: '${{ github.token }}'
          environment-url: ${{ steps.deployment.outputs.environment_url }}
          deployment-id: ${{ steps.deployment.outputs.deployment_id }}
          state: 'failure'

Breaking changes

v2 of this action removes the target_url input and replaces it with the environment_url and log_url inputs to match GitHub's API. v2 also standardises on using kebab-case rather than snake_case for inputs to match GitHub's built-in actions.

Releasing

  1. Merge the main branch into releases/v2

  2. Tag the release

    git tag v2.0.6
    git tag v2 -f # force update the existing v2 major release tag
  3. Push the tags

    git push -f --tags

deployment-action's People

Contributors

aarontwf avatar ansman avatar baikang-serai avatar chrnorm avatar dependabot[bot] avatar j-catania avatar liamoneill avatar localheinz avatar louy avatar maks-oleksyuk avatar ogizanagi avatar piotrekkr avatar shallwefootball avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

deployment-action's Issues

Think about setting default for `ref` conveniently :)

Currently ref is not provided, will be set to github.ref however, in the context of a PR this won't associate the deployment with the pull request and thus it won't show up as a deployment.

I'd suggest that you default ref to github.head_ref if the action is called within a pull request. You'd do this trivially by checking for the existence of it, because it is only available when the event that triggers a workflow run is a pull_request.

I'd do it myself, however I am afraid of changing documentation and actually is is a breaking change...

Does not respect deploy branch protection rules

Hey. I noticed that this action does not respect https://github.blog/changelog/2021-02-17-github-actions-limit-which-branches-can-deploy-to-an-environment/ - meaning anybody can change an action in a PR and curl a secret to their server etc. if it's the only thing that you use for deployments

I assume this is contrary to using standard GitHub environment tag

I understand that this action is a github's deployment api helper and doesn't have access to the same APIs as whatever github employees write.

I was wondering if I'm on the right track with my thinking? If I want the security (deploy branch protection, deployment acceptance by a team member) features I should use the default GitHub YAML environment: tag on a job, and only use this action (or deployment-status) for more granular control when I need it?

Example for passing status to inactive on PR closed

name: "Wipe environment"

on:
  pull_request:
    types: [closed]

jobs:
  wipe:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/setup-node@v2
      with:
        registry-url: 'https://registry.npmjs.org'

    - name: Remove from S3
      uses: vitorsgomes/s3-rm-action@master
      with:
        args: --recursive
      env:
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        AWS_REGION: ${{ secrets.AWS_REGION }}
        AWS_S3_BUCKET: ${{ secrets.AWS_BUCKET }}
        PATH_TO_DELETE: /pr-${{ github.event.pull_request.number }}

      - uses: chrnorm/deployment-status@releases/v1
        if: success()
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          deployment_id: ${{ steps.deployment.outputs.deployment_id }}
          state: inactive

Question is simple: how to retrieve the deployment_id ?

`production-environment` is default false when environment used is `production`

Hello.

Just noticed that documentation specifies:

production-environment | (Optional) Specifies if the given environment is one that end-users  directly interact with. Default: true when environment is production and  false otherwise.

but GitHub API returns "production_environment": false when asked about created deployment:

[
  {
    "url": "https://api.github.com/repos/XXXXX/XXXXXX/deployments/571000164",
    "id": 571000164,
    "node_id": "DE_kwDODNDcKM4iCMVk",
    "task": "deploy",
    "original_environment": "production",
    "environment": "production",
    "description": "Deploy of v1.704.0",
    "created_at": "2022-05-26T08:18:42Z",
    "updated_at": "2022-05-26T08:19:34Z",
    "statuses_url": "https://api.github.com/repos/XXXXX/XXXXXX/deployments/571000164/statuses",
    "repository_url": "https://api.github.com/repos/XXXXX/XXXXXX",
    "creator": {
      "login": "github-actions[bot]",
      "id": 41898282,
      "node_id": "MDM6Qm90NDE4OTgyODI=",
      "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/github-actions%5Bbot%5D",
      "html_url": "https://github.com/apps/github-actions",
      "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers",
      "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}",
      "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions",
      "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs",
      "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos",
      "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}",
      "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events",
      "type": "Bot",
      "site_admin": false
    },
    "sha": "b7209186793095ca0c4bb72103f507b5645d76d0",
    "ref": "v1.704.0",
    "payload": {},
    "transient_environment": false,
    "production_environment": false,
    "performed_via_github_app": null
  }
]

I'm using this action like this:

      - name: Create GitHub deployment
        uses: chrnorm/deployment-action@v2
        id: deployment
        with:
          token: "${{ secrets.GITHUB_TOKEN }}"
          environment-url: "${{ env.APP_VERSION_URL}}"
          environment: "production"
          initial-status: "in_progress"
          description: "Deploy of ${{ steps.version.outputs.ref }}"
          log-url: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
          ref: "${{ steps.version.outputs.ref }}"

Am I doing something wrong? Thanks.

Use kebab-case for inputs and outputs?

All of the documentation for GitHub Actions uses the kebab-case naming convention. This project, however, uses snake-case. As such, it's the only part of our entire CD config that uses snake-case and it can throw people off.

I wouldn't want to break anything on anyone, so if supporting both isn't a problem, that'd be helpful. I can do up a PR for it, but don't want to spend the time if there's no support for the change.

Referecing deployment_id between jobs.

I have a need to run a script with private runner that is Windows Server.
This action is not compatible with windows runner, and so I have split the jobs, where the first job creates the deployment and then uploads the deployment_id as artifact.

The second job runs the script on private runner.

The third job downloads the artifacts and sets the deployment id as env var and I have tried passing the deployment id as env var but the action is complaining with below error.
Error: HttpError: Invalid value for parameter 'deployment_id': null is NaN
Error: Invalid value for parameter 'deployment_id': null is NaN

Stage 1
DBUP-Create-GitDeployment:
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
steps:
- name: Create deployment
uses: chrnorm/deployment-action@releases/v1
id: deployment
with:
initial_status: in_progress
token: "${{ env.Password }}"
environment: uat-jl
- name: Export deployment_id to file
run: |
${{ steps.deployment.outputs.deployment_id }} | out-file deployment_id.txt
- name: Upload deployment_id as artifacts
uses: actions/upload-artifact@v2
with:
name: deployment_id
path: deployment_id.txt

Stage 3
DBUP-Git-Deployment-Status-Update:
runs-on: ubuntu-latest
needs: DBUP-Start-Deployment
defaults:
run:
shell: pwsh
steps:
- name: Download the deployment_id
uses: actions/download-artifact@v2
with:
name: deployment_id
- name: Set deloyment_id as envvar
run: |
$env:deployment_id = Get-content deployment_id.txt
Write-Output "printing file contents"
Get-content deployment_id.txt
Write-Output "printing env var"
$env:deployment_id
- name: Update deployment status (success)
if: success()
uses: chrnorm/deployment-status@releases/v1
with:
token: "${{ env.Password }}"
state: "success"
deployment_id: "${{ env.deployment_id }}"

  - name: Update deployment status (failure)
    if: failure()
    uses: chrnorm/deployment-status@releases/v1
    with:
      token: "${{ env.Password }}"
      state: "failure"
      deployment_id: "${{ env.deployment_id }}"

[Error: Not Found] Provide better error messaging

This is all that is shown if the configured user's github token does not have permissions to create deployments on the repository:

> Run chrnorm/[email protected]
Error: HttpError: Not Found
Error: Not Found

It'd be a lot more helpful if the messaging indicated that this HTTP error was specifically related to the call to the github api (and not that the target_url is attempted to be queried for some reason, which was my first hunch since I had provided an internal server).

Error: Unable to create deployment. Either the repository does not exist or the provided token does not have the proper permissions to do so.

Misleading info about target_url, typos in doc + support for environment_url

Hi there!

In docs, you write:

target_url | (Optional) The target URL. This should be the URL of the app once deployed

But it is actually not true (source):

The target URL to associate with this status. This URL should contain output to keep the user updated while the task is running or serve as historical information for what happened in the deployment. Default: "" Note: It's recommended to use the log_url parameter, which replaces target_url.

As well it is deprecated and should use log_url instead.

Another thing, in your examples you use input target-url with dash, instead of underscore.

Do you plan adding environment_url input support?

Thank you

Unexpected input(s) 'state' for 'in_progress'

I tried to set 'in_progress' state for deployment instead of 'pending' and got the error:

Warning: Unexpected input(s) 'state', valid inputs are ['repo', 'owner', 'initial-status', 'token', 'log-url', 'description', 'environment', 'environment-url', 'auto-merge', 'ref', 'sha', 'task', 'required-contexts', 'payload', 'transient-environment', 'production-environment', 'auto-inactive', 'github-base-url']

Workflow code:

- name: Create GitHub deployment
  uses: chrnorm/deployment-action@v2
  id: deployment
  with:
    token: '${{ github.token }}'
    environment: production
    state: 'in_progress'

Error creating deployment

Hi there, I have successfully used this action in a develop branch. After merging into master it fails with:

##[error]HttpError: Conflict merging develop into refs/heads/master.
##[error]Conflict merging develop into refs/heads/master.
##[error]Node run failed with exit code 1

I don't understand this output, there were no conflicts merging the PR, it was merged. This workflow is running on push events, so it would be triggered on a new clean master commit.
As you can see, the merge was successful:
Screenshot 2019-10-21 at 10 50 21

Any idea what's going on?

Thank you,
Tiago

Node.js 12 actions are deprecated on Github

Github will drop support for Node 12, any runs using this action will show a warning:

Node.js 12 actions are deprecated. For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/. Please update the following actions to use Node.js 16: chrnorm/deployment-action

New `auto_merge` option logic not in tagged release

Your action yaml is pointing to lib/main.js but the new auto_merge option is not present here on the tagged release: https://github.com/chrnorm/deployment-action/blob/v1.1.0/lib/main.js

This is causing the action to fail for us with similar errors to #1

Run chrnorm/[email protected]
  with:
    environment: production
    initial_status: success
    target_url: ***
    token: ***

##[error]HttpError: Conflict merging development into refs/heads/master.
##[error]Conflict merging development into refs/heads/master.
##[error]Node run failed with exit code 1

Cannot set deployment status

Instead of changing the status of a running deployment, it seems to create a new one as if the deployment_id variable wasn't given.

name: Deploy
on:
  push:
    branches:
    - master

jobs:
  deploy:
    name: Terraform
    runs-on: ubuntu-latest
    steps:

    - uses: chrnorm/[email protected]
      name: Create GitHub deployment
      id: deployment
      with:
        token: ${{ secrets.GITHUB_TOKEN }}
        target-url: https://cluster.ironpeak.be/
        environment: production
        initial_status: in_progress
    
    - run: exit 1

    - uses: chrnorm/[email protected]
      name: "Set GitHub Deployment: Success"
      if: success()
      with:
        token: ${{ secrets.GITHUB_TOKEN }}
        state: "success"
        deployment_id: ${{ steps.deployment.outputs.deployment_id }}

    - uses: chrnorm/[email protected]
      name: "Set GitHub Deployment: Failed"
      if: failure()
      with:
        token: ${{ secrets.GITHUB_TOKEN }}
        state: "failure"
        deployment_id: ${{ steps.deployment.outputs.deployment_id }}

Deployments for the same commit:
afbeelding

And you can see the commit failed here in the CI/CD run: https://github.com/ironPeakServices/infrastructure/runs/497252378?check_suite_focus=true

Figured out how to trigger `deployment` action from inside the workflow

Heads up! Currently, there is a GitHub Actions limitation where events fired inside an action will not trigger further workflows. If you use this action in your workflow, it will not trigger any "Deployment" workflows.

I was able to work around this. While not ideal, if you use a token that is not the Action's GITHUB_TOKEN, this will work. I define a secret called GITHUB_DEPLOY_TOKEN and use that for API calls.

Suggestion: Use `deployment-status` action as `runs.post` script

Both deployment-action and deployment-status are useful and works nicely together.
But using both of them comes with a duplication of the configuration data, and make the workflow a bit too complex.

GitHub Actions support a nice (actually quite common) feature: runs.post.
The most obvious usage of this feature is for caching data at the end of a job, like actions/setup-node.

Using this with deployment-action could be very valuable as well:

  • Only one additional input would be sufficient to enable (or disable) the status submission
    • All the rest of the configuration is done only once
  • It runs at the end of the job per default wherever the deployment is created
  • The status of the job is available to the post script, not limited to success only

Create Deployment Action is Failing

Hi @chrnorm ,

Create deployment action is failing with below, do you have any ideas on where to actually look at:

  Run chrnorm/[email protected]
    with:
      token: ***
      environment: test
      initial-status: pending
      auto-merge: false
      task: deploy
      transient-environment: false
      auto-inactive: true
  Error: HttpError: invalid json response body at <URL HIDDEN> reason: Unexpected end of JSON input
  Error: Error creating GitHub deployment: invalid json response body at <HIDDEN URL> reason: Unexpected end of JSON input

The hidden URL shows this:

    {
      "message": "Not Found",
      "documentation_url": "https://docs.github.com/rest/deployments/statuses#list-deployment-statuses"
    }

It seems like we are hitting a no 'ID' case, somehow at the time of running of the below if check:

https://github.com/chrnorm/deployment-action/blob/6e62572161cddc34701816e65b5539572ff80325/src/main.ts#L97C8-L97C8

However, when I run a postman get to the statuses, I get back a response with the ID. So the deployment is actually created.

Any ideas?

Is this action still relevant?

First of all, thank you for publishing this action. I have been using it for 1.5 years to track deployments by GitHub Actions and it works very well.

However, today I found out that GitHub Actions now has its own feature to manage deployments. By adding environment: production to a job, GitHub Actions will create a deployment (and an environment, if it doesn't exist yet) and update its status based on the result of the job.

The URL for the deployment can also be specified, which is then also shown in the visualization graph for the workflow run:

Deploy graph

And the deployment history will now show the user who triggered the deployment instead of github-actions:

afbeelding

So I am opening this issue to discuss the question whether or not this action is still relevant. Is all the provided functionality now covered by GitHub Actions itself? Or are there still reasons / scenarios for which this action is offering functionality not covered by GitHub Actions?

GitHub deprecating `set-output`

GitHub is deprecating echo "::set-output name=etc::etc" in favor of a new syntax.

Run chrnorm/deployment-action@v2

::set-output name=deployment_id::680226386
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/
##[debug]steps.gh_deploy.outputs.deployment_id='680226386'

chrnorm/deployment-action failing due to node20

Error: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter ''using: node20' is not supported, use 'docker', 'node12' or 'node16' instead.')
Error: Fail to load chrnorm/deployment-action/v2/action.yml

Validation failures when using in_progress state

| "in_progress"

In this action and in https://github.com/chrnorm/deployment-status I believe you need to include the following media types:

application/vnd.github.flash-preview+json
application/vnd.github.ant-man-preview+json

Here's an example failure https://github.com/sjparkinson/isitup.org/commit/8f493dc202948137370dddc9c002733194d985d9/checks.

##[error]HttpError: Validation Failed
##[error]Validation Failed
##[error]Node run failed with exit code 1

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.