Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: webfactory/create-aws-codedeploy-deployment
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.2.1
Choose a base ref
...
head repository: webfactory/create-aws-codedeploy-deployment
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
Showing with 121,876 additions and 50,774 deletions.
  1. +13 −0 CHANGELOG.md
  2. +44 −9 README.md
  3. +0 −87 cli.js
  4. +9 −3 { → create-deployment}/action.yml
  5. +18 −0 delete-deployment-group/action.yml
  6. +60,349 −0 dist/create-deployment/index.js
  7. +60,342 −0 dist/delete-deployment-group/index.js
  8. +0 −50,020 dist/index.js
  9. +6 −8 package.json
  10. +86 −26 create-deployment.js → src/action.js
  11. +12 −4 index.js → src/create-deployment.js
  12. +23 −0 src/delete-deployment-group.js
  13. +974 −617 yarn.lock
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# create-aws-codedeploy-deployment Action Changelog

## Version v0.5.1

- Update action code to use the AWS JavaScript SDK v3, to make warnings about the upcoming v2 EOL go away

## Version v0.5.0

- Added a second action to remove deployment groups, e. g. after a PR has been closed or merged. In order to serve both actions from a single repository, the actions were moved to subdirectories. Refer to actions as `webfactory/create-aws-codedeploy-deployment/create-deployment@v0.5.0` and `webfactory/create-aws-codedeploy-deployment/delete-deployment-group@v0.5.0` respectively in your workflow's `uses:` clause.

## Previous versions

No dedicated changelog file has been written. Refer to https://github.com/webfactory/create-aws-codedeploy-deployment/releases for release information.
53 changes: 44 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -36,19 +36,19 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: aws-actions/configure-aws-credentials@v1
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.SECRET_ACCESS_KEY }}
aws-region: eu-central-1
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- id: deploy
uses: webfactory/create-aws-codedeploy-deployment@v0.1.0
- uses: peter-evans/commit-comment@v1
uses: webfactory/create-aws-codedeploy-deployment/create-deployment@v0.5.0
- uses: peter-evans/commit-comment@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
@${{ github.actor }} this was deployed as [${{ steps.deploy.outputs.deploymentId }}](https://console.aws.amazon.com/codesuite/codedeploy/deployments/${{ steps.deploy.outputs.deploymentId }}?region=eu-central-1) to group `${{ steps.deploy.outputs.deploymentGroupName }}`.
@${{ github.actor }} this was deployed as [${{ steps.deploy.outputs.deploymentId }}](https://console.aws.amazon.com/codesuite/codedeploy/deployments/${{ steps.deploy.outputs.deploymentId }}?region=eu-central-1) to group `${{ steps.deploy.outputs.deploymentGroupName }}`.
```
First, this configures AWS Credentials in the GitHub Action runner. The [aws-actions/configure-aws-credentials](https://github.com/aws-actions/configure-aws-credentials) action is used for that, and credentials are kept in [GitHub Actions Secrets](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets).
@@ -98,6 +98,8 @@ The first entry makes the action skip the deployment (do nothing at all) when th

Commits on the `master` branch are to be deployed in a Deployment Group called `production`. All other commits will create or update a Deployment Group named `$BRANCH.staging.acme.tld`, where `$BRANCH` will be replaced with a DNS-safe name derived from the current branch. Basically, a branch called `feat/123/new_gimmick` will use `feat-123-new-gimmick` for `$BRANCH`. Since the Deployment Group Name is available in the `$DEPLOYMENT_GROUP_NAME` environment variable inside your CodeDeploy Lifecycle Scripts, you can use that to create "staging" environments with a single, generic configuration statement.

Similar to `$BRANCH`, for workflows triggered by Pull Requests, the string `$PR_NUMBER` will be replaced by the pull request number.

The `deploymentGroupConfig` and `deploymentConfig` keys in each of the two cases contain configuration that is passed as-is to the
[`CreateDeploymentGroup`](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_CreateDeploymentGroup.html) or
[`UpdateDeploymentGroup`](https://docs.aws.amazon.com/codedeploy/latest/APIReference/API_UpdateDeploymentGroup.html) API calls (for
@@ -114,7 +116,7 @@ The only addition made will be that the `revision` parameter for `CreateDeployme
2. Connect your CodeDeploy Application with your repository following [these instructions](https://docs.aws.amazon.com/codedeploy/latest/userguide/deployments-create-cli-github.html).
3. Configure the [aws-actions/configure-aws-credentials](https://github.com/aws-actions/configure-aws-credentials) action in your workflow and provide the necessary IAM credentials as secrets. See the section below for the necessary IAM permissions.
4. Add the `branch_config` section to your `appspec.yml` file to map branches to Deployment Groups and their configuration. In the above example, the `master` and `.*` sub-sections show the minimal configuration required.
5. Add `uses: webfactory/create-aws-codedeploy-deployment@v0.1.0` as a step to your workflow file. If you want to use the action's outputs, you will also need to provide an `id` for the step.
5. Add `uses: webfactory/create-aws-codedeploy-deployment/create-deployment@v0.5.0` as a step to your workflow file. If you want to use the action's outputs, you will also need to provide an `id` for the step.

### AWS IAM Permissions

@@ -136,7 +138,8 @@ The IAM User that is used to run the action requires the following IAM permissio
"codedeploy:GetDeploymentConfig",
"codedeploy:GetDeploymentGroup",
"codedeploy:UpdateDeploymentGroup",
"codedeploy:CreateDeploymentGroup"
"codedeploy:CreateDeploymentGroup",
"codedeploy:DeleteDeploymentGroup"
],
"Resource": [
"arn:aws:iam::{your_account_id}:role/{your_codedeploy_service_role}",
@@ -164,12 +167,44 @@ This workaround should catch a good share of possible out-of-order deployments.
### Input

* `application`: The name of the CodeDeploy Application to work with. Defaults to the "short" repo name.
* `skip-sequence-check`: When set to `true`, do not attempt to make sure deployments happen in order. Use this when the workflow count has been reset or changed to a lower value; possible cause is renaming the workflow file.
* `config-name`: Name used to look up the deployment config in the `branch_config` section of the `appspec.yml` file. Defaults to the current branch name. By using this override, you can force a particular config to be used regardless of the branch name. Or, you can run the action several times within the same job to create multiple (different) deployments from the same branch.

### Outputs

* `deploymentId`: AWS CodeDeployment Deployment-ID of the deployment created
* `deploymentGroupName`: AWS CodeDeployment Deployment Group name used
* `deploymentGroupCreated`: True, if a new deployment group was created. False, if an existing group was updated.
* `deploymentGroupCreated`: `1`, if a new deployment group was created; `0` if an existing group was updated.

You can use the expression `if: steps.<your-deployment-step>.outputs.deploymentGroupCreated==true` (or `...==false`) on subsequent workflow steps to run actions only if the deployment created a new deployment group (or updated an existing deployment, respectively).

## Cleaning Up

Sooner or later you might want to get rid of the CodeDeploy Deployment Groups created by this action. For example, when you create deployments for pull requests opened in a repo, you might want to delete those once the PR has been closed or merged.

To help you with this, a second action is included in this repo that can delete Deployment Groups, and uses the same rules to derive the group name as described above.

Here is an example workflow that runs for closed pull requests:

```yaml
# .github/workflows/cleanup-deployment-groups.yml
on:
pull_request:
types:
- closed
jobs:
deployment:
runs-on: ubuntu-latest
steps:
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.SECRET_ACCESS_KEY }}
aws-region: eu-central-1
- uses: actions/checkout@v4
- uses: webfactory/create-aws-codedeploy-deployment/delete-deployment-group@v0.5.0
```

## Hacking

@@ -191,4 +226,4 @@ If you're a developer looking for new challenges, we'd like to hear from you! Ot
- <https://www.webfactory.de>
- <https://twitter.com/webfactory>

Copyright 2020 webfactory GmbH, Bonn. Code released under [the MIT license](LICENSE).
Copyright 2020 - 2024 webfactory GmbH, Bonn. Code released under [the MIT license](LICENSE).
87 changes: 0 additions & 87 deletions cli.js

This file was deleted.

12 changes: 9 additions & 3 deletions action.yml → create-deployment/action.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
name: 'webfactory/create-aws-codedeploy-deployment'
name: 'webfactory/create-aws-codedeploy-deployment/create-deployment'
description: 'An Action to deploy GitHub repos with AWS CodeDeploy'
inputs:
application:
description: 'AWS CodeDeploy application name; defaults to short repository name'
skip-sequence-check:
description: 'When set, skip the check making sure no earlier workflow results are deployed'
default: false
config-name:
description: 'Override name to look up branch_config; default is to use the current branch name.'
default: ''
outputs:
deploymentId:
description: AWS CodeDeployment Deployment-ID of the deployment created
@@ -11,8 +17,8 @@ outputs:
deploymentGroupCreated:
description: True, if a new deployment group was created; false if an already existing group was used.
runs:
using: 'node12'
main: 'dist/index.js'
using: 'node20'
main: '../dist/create-deployment/index.js'

branding:
icon: cast
18 changes: 18 additions & 0 deletions delete-deployment-group/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: 'webfactory/create-aws-codedeploy-deployment/delete-deployment-group'
description: 'Delete an AWS CodeDeploy deployment group, e. g. after a PR has been closed'
inputs:
application:
description: 'AWS CodeDeploy application name; defaults to short repository name'
config-name:
description: 'Override name to look up branch_config; default is to use the current branch name.'
default: ''
outputs:
deploymentGroupName:
description: AWS CodeDeployment Deployment Group name used
runs:
using: 'node20'
main: '../dist/delete-deployment-group/index.js'

branding:
icon: cast
color: orange
Loading