{"id":22800926,"url":"https://github.com/colindembovsky/deployment-lifecycle-actions","last_synced_at":"2025-04-19T18:22:25.384Z","repository":{"id":41334666,"uuid":"508880498","full_name":"colindembovsky/deployment-lifecycle-actions","owner":"colindembovsky","description":"Actions to manage PR deployment lifecycle","archived":false,"fork":false,"pushed_at":"2023-07-12T01:41:16.000Z","size":16667,"stargazers_count":5,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T11:34:38.162Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/colindembovsky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-30T00:08:05.000Z","updated_at":"2023-06-01T06:00:08.000Z","dependencies_parsed_at":"2023-02-09T12:30:28.245Z","dependency_job_id":null,"html_url":"https://github.com/colindembovsky/deployment-lifecycle-actions","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colindembovsky%2Fdeployment-lifecycle-actions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colindembovsky%2Fdeployment-lifecycle-actions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colindembovsky%2Fdeployment-lifecycle-actions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colindembovsky%2Fdeployment-lifecycle-actions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/colindembovsky","download_url":"https://codeload.github.com/colindembovsky/deployment-lifecycle-actions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249761798,"owners_count":21321860,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-12T08:08:26.520Z","updated_at":"2025-04-19T18:22:25.359Z","avatar_url":"https://github.com/colindembovsky.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Build](https://github.com/colindembovsky/deployment-lifecycle-actions/actions/workflows/build.yml/badge.svg) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/colindembovsky/deployment-lifecycle-actions/LICENSE)\n\n# Deployment Lifecycle Actions\n\nManaging deployments via PR is good practice and is a central tenet to GitHub flow. However, practically managing deployments is non-trivial. The Actions in this repo coupled with four workflow templates will give you a complete deployment management solution.\n\nA huge thank you to my colleague [Peter Murray](https://github.com/peter-murray) for the guts of the code in the Actions!\n\n## Overview\n\nThe process is triggered by adding a `deploy to \u003cenvironment\u003e` label to the PR. Automation processes the label and triggers a deployment workflow with your deployment steps. This creates a deployment which you will see in the PR. Once the PR is closed, the deployment is marked as inactive and a destroy workflow is invoked to clean up resources.\n\nThe Actions in this repo wrap the heavy-lifting for you. There are four workflows involved:\n\nWorkflow|Trigger|Action Used|Parameters\n--|--|--|--\n`Label Deployment`|When a label is added to the PR|[colindembovsky/deployment-lifecycle-actions/create-deployment-from-label](create-deployment-from-label/action.yml)|\u003cul\u003e\u003cli\u003eThe name of the deployment workflow\u003c/li\u003e\u003cli\u003eDeployment token (optional)\u003c/li\u003e\u003c/ul\u003e\n`Deployment`|Triggered by the `Label Deployment` workflow|_None_|_None_\n`Deactivate Deployment`|When the PR is closed|[colindembovsky/deployment-lifecycle-actions/deactivate-deployment](deactivate-deployment/action.yml)|_None_\n`Destroy Environment`|When a deployment is set to `failure`|[colindembovsky/deployment-lifecycle-actions/extract-deployment-info](extract-deployment-info/action.yml)|_None_\n\n### Deployment Phase\n\nThe deployment works as follows:\n\n![Deployment Phase](images/creation-workflows.png)\n\n1. A PR is created as usual.\n1. When ready to deploy, someone adds a `deploy to \u003cenvironment\u003e` label to the PR to deploy to the `\u003cenvironment\u003e` environment:\n\n    ![Adding the label](images/apply-label.png)\n    \n1. The `Label Deployment` workflow triggers when the label is added.\n    - This workflow uses `colindembovsky/deployment-lifecycle-actions/create-deployment-from-label`\n        - The Action first extracts the environment name (`dev` from `deploy to dev` for example) based on a customizable regex pattern\n        - The Action then invokes the `Deployment workflow` passing in the `environment` and any other inputs\n1. The `Deployment` workflow triggers.\n    - This workflow performs your deployment steps in the environment\n    - This automatically creates a `deployment` object that you will see in the PR:\n        ![Deployment added to PR](images/deployed.png)\n    - You will also see the deployment in the Environments page:\n        ![Active deployment](images/deploy-active.png)\n\n### Deployment Phase\n\nWhen the PR is closed, the deactivate phase is as follows:\n\n![Deactivation Phase](images/deactivate-workflows.png)\n\n1. The PR close event triggers the `Deactivate Deployment` workflow.\n    - This workflow uses `colindembovsky/deployment-lifecycle-actions/deactivate-deployment`\n        - The Action first transitions the deployment to `failure` to trigger the next workflow due to [this limitation](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#deployment_status)\n        - The Action then transitions the deployment to `inactive`\n\n            ![Inactive deployment](images/inactive-env.png)\n\n1. The `Destroy Environment` workflow triggers off the deployment status change.\n    - This workflow uses `colindembovsky/deployment-lifecycle-actions/extract-deployment-info` to get the `ref` and `environment` and sets them as outputs\n    - Your custom teardown steps are added after this\n       \n        ![Cleanup workflows completed](images/cleanup-workflow.png)\n\n## The Workflows\n\n### 1. Label Deployment Workflow\n\nUse this to trigger the process. You need to know the name of the workflow you want to trigger to do the actual deployments and any additional inputs.\n\n```yml\nname: Label deployment trigger\n\n# mandatory to trigger correctly\non:\n  pull_request:\n    types:\n      - labeled\n\njobs:\n  deployment:\n    name: Create deployment\n    runs-on: ubuntu-20.04\n    # filter on the 'deploy to x' labels - customize for your environment names\n    if: |\n      github.event.label.name == 'deploy to test' ||\n      github.event.label.name == 'deploy to staging' ||\n      github.event.label.name == 'deploy to qa'\n    \n    steps:\n    - name: Checkout Sources\n      uses: actions/checkout@v3\n\n    - name: Create deployment from label\n      id: create-deploy\n      uses: colindembovsky/deployment-lifecycle-actions/create-deployment-from-label@v1\n      with:\n        # this is the name of the yml file in your .github/workflows/ folder that you want to trigger\n        # to run the deployment steps. The workflow must expect at least 1 input called 'environment'\n        deployment-workflow-name: TEST-2-DeployEnvironment.yml\n        # optional: use a json format to pass additional inputs\n        additional-inputs-json: '{ \"url\": \"https://another-test-url\" }'\n        # GITHUB_TOKEN will work - but you can provide another token if needed\n        # token: ${{ secrets.DEPLOY_TOKEN }}\n    \n    # access the outputs of the create-deployment-from-label step\n    - name: Dump env name\n      run: echo $ENV\n      env:\n         ENV: ${{ steps.create-deploy.outputs.environment }}\n```\n\n### 2. Deployment Workflow\n\nYou use this to run your deployment steps. No custom actions are needed! The only requirement is that you have an `environment` input and any optional additional inputs, which you need to specify in the previous workflow.\n\n```yml\nname: Deploy Environment\n\non:\n  # this is triggered by the 'Label Deployment' workflow\n  workflow_dispatch:\n    inputs:\n      # this is mandatory\n      environment:\n        description: The name of the environment to be deployed\n        required: true\n      # other inputs can be passed using 'additional-inputs-json' in the 'Label Deployment' workflow\n      url:\n        description: The URL of the environment\n        required: false\n        default: https://test\n\njobs:\n  deploy:\n    name: Deploy to Environment\n    runs-on: ubuntu-20.04\n\n    # mandatory to actually create a deployment object\n    environment:\n      # access the input values using ${{ github.event.inputs }}\n      name: ${{ github.event.inputs.environment }}\n      url: ${{ github.event.inputs.url }}\n\n    # add your deployment steps here\n    steps:\n      - name: Deploy steps!\n        run: echo \"Deploying the app!\"\n```\n\n### 3. Deactivate Deployment Workflow\n\nNo customization needed here, so just copy it as-is. This simply marks the deployment in the PR as inactive, which triggers the `Destroy environment` workflow.\n\n```yml\nname: Deactivate Deployment\n\non:\n  pull_request:\n    types:\n      - closed\n\njobs:\n  clean:\n    name: Cleanup Review environments\n    runs-on: ubuntu-20.04\n\n    steps:\n    - name: Checkout\n      uses: actions/checkout@v3\n\n    - name: Mark environments as inactive in GitHub\n      uses: colindembovsky/deployment-lifecycle-actions/deactivate-deployment@v1\n```\n\n### 4. Destroy Environment Workflow\n\nThis workflow uses the `extract-deployment-info` action to extract the `ref` and `environment` that has been deactivated. Then perform any applicable cleanup steps.\n\n```yml\nname: Destroy Environment\n\n# mandatory\non:\n  deployment_status\n\njobs:\n  destroy:\n    name: Destroy a deployment environment\n    # mandatory to filter correctly - you don't want to run this on 'activate' for example\n    if: github.event.deployment_status.state == 'failure'\n    runs-on: ubuntu-20.04\n\n    steps:\n    - name: Checkout Sources\n      uses: actions/checkout@v3\n\n    # extract the 'ref' and 'environment' as outputs\n    - name: Extract Deployment Details and Report Deployment in Progress\n      id: deployment_data\n      uses: colindembovsky/deployment-lifecycle-actions/extract-deployment-info@v1\n    \n    # implement tear-down steps here, accessing the outputs from the previous step\n    - name: Destroy environment\n      run: |\n        echo Environment name is $ENV_NAME\n        echo Ref is $REF\n      env:\n        REF: ${{ steps.deployment_data.outputs.deployment_ref }}\n        ENV_NAME: ${{ steps.deployment_data.outputs.environment }}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcolindembovsky%2Fdeployment-lifecycle-actions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcolindembovsky%2Fdeployment-lifecycle-actions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcolindembovsky%2Fdeployment-lifecycle-actions/lists"}