Skip to content

Add a second action to delete deployment groups (e. g. after PR merge) #31

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

Merged
merged 7 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# create-aws-codedeploy-deployment Action Changelog

## 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/[email protected]` and `webfactory/create-aws-codedeploy-deployment/[email protected]` 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.
39 changes: 34 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ jobs:
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.2.2
uses: webfactory/create-aws-codedeploy-deployment/create-deployment@v0.5.0
- uses: peter-evans/commit-comment@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -116,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

Expand All @@ -138,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}",
Expand Down Expand Up @@ -177,6 +178,34 @@ This workaround should catch a good share of possible out-of-order deployments.

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@v2
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/[email protected]
```

## Hacking

As a note to my future self, in order to work on this repo:
Expand All @@ -197,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 - 2022 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.

6 changes: 3 additions & 3 deletions action.yml → create-deployment/action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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:
Expand All @@ -17,8 +17,8 @@ outputs:
deploymentGroupCreated:
description: True, if a new deployment group was created; false if an already existing group was used.
runs:
using: 'node16'
main: 'dist/index.js'
using: 'node20'
main: '../dist/create-deployment/index.js'

branding:
icon: cast
Expand Down
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