Skip to content

Commit

Permalink
feat(delete-deployment): add delete-deployment helper (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
danadajian authored Jan 18, 2022
1 parent 16b2ec0 commit fc5e6fd
Show file tree
Hide file tree
Showing 10 changed files with 380 additions and 57 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/deployments.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Deployments

on:
pull_request_target:
branches: [ main ]
paths:
- 'src/helpers/delete-deployment.ts'
- 'src/helpers/initiate-deployment.ts'
- 'src/helpers/set-deployment-status.ts'

jobs:
initiate-deployment:
name: Initiate Deployment
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

- uses: ./
with:
helper: initiate-deployment
sha: ${{ github.event.pull_request.head.sha }}
environment: test
description: PR#${{ github.event.pull_request.number }} has been merged; pipeline in progress...
github_token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

set-deployment-status:
name: Set Deployment Status
needs: [ initiate-deployment ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

- uses: ./
with:
helper: set-deployment-status
sha: ${{ github.event.pull_request.head.sha }}
environment: test
state: success
description: Deployment succeeded.
target_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
github_token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

delete-deployment:
name: Delete Deployment
needs: [ initiate-deployment, set-deployment-status ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

- uses: ./
with:
helper: delete-deployment
sha: ${{ github.event.pull_request.head.sha }}
environment: test
github_token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
26 changes: 0 additions & 26 deletions .github/workflows/initiate-deployment.yml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/set-deployment-status.yml

This file was deleted.

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Each of the following helpers are defined in a file of the same name in `src/hel
* Checks whether PR title matches a certain regular expression
### [**create-pr-comment**](.github/workflows/create-pr-comment.yml)
* Comments on a pull request or other issue
### [**delete-deployment**](.github/workflows/deployments.yml#L53)
* Deletes a Github [deployment](https://docs.github.com/en/rest/reference/repos#deployments)
### [**filter-paths**](.github/workflows/filter-paths.yml)
* Returns `true` if specified file paths have changed for a PR, and `false` otherwise
### [**generate-path-matrix**](.github/workflows/generate-path-matrix.yml)
Expand All @@ -49,7 +51,7 @@ Additionally, the following parameters can be used for additional control over t

### [**get-changed-files**](.github/workflows/get-changed-files.yml)
* Returns a comma-separated list of changed files for a PR
### [**initiate-deployment**](.github/workflows/initiate-deployment.yml)
### [**initiate-deployment**](.github/workflows/deployments.yml#L12)
* Creates a new in-progress Github "deployment" for a commit. More information on Github deployment events can be found [here](https://docs.github.com/en/rest/reference/repos#deployments)
### [**manage-merge-queue**](.github/workflows/manage-merge-queue.yml)
* Manages a queue for PRs as follows:
Expand All @@ -70,7 +72,7 @@ Additionally, the following parameters can be used for additional control over t
* Removes a label from a PR
### [**set-commit-status**](.github/workflows/set-commit-status.yml)
* Sets a [commit status](https://github.blog/2012-09-04-commit-status-api/)
### [**set-deployment-status**](.github/workflows/set-deployment-status.yml)
### [**set-deployment-status**](.github/workflows/deployments.yml#L31)
* Updates a Github [deployment status](https://docs.github.com/en/rest/reference/repos#deployments)
### [**set-latest-pipeline-status**](.github/workflows/set-latest-pipeline-status.yml)
* Determines whether the pipeline is clear for a PR. This means it will set the "pipeline" commit status to `pending` if there is an in-progress production deployment for the repo, and `success` otherwise.
Expand Down
138 changes: 138 additions & 0 deletions dist/12.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/12.index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18866,6 +18866,16 @@ var map = {
438,
124
],
"./delete-deployment": [
7012,
438,
12
],
"./delete-deployment.ts": [
7012,
438,
12
],
"./filter-paths": [
9794,
438,
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions src/helpers/delete-deployment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2021 Expedia, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { GITHUB_OPTIONS } from '../constants';
import { context } from '@actions/github';
import { octokit } from '../octokit';

interface DeleteDeployment {
sha: string;
environment: string;
}

export const deleteDeployment = async ({ sha, environment }: DeleteDeployment) => {
const { data } = await octokit.repos.listDeployments({
sha,
environment,
...context.repo,
...GITHUB_OPTIONS
});
const deployment_id = data.find(Boolean)?.id;
if (deployment_id) {
await octokit.repos.createDeploymentStatus({
state: 'inactive',
deployment_id,
...context.repo,
...GITHUB_OPTIONS
});
return octokit.repos.deleteDeployment({
deployment_id,
...context.repo,
...GITHUB_OPTIONS
});
}
};
Loading

0 comments on commit fc5e6fd

Please sign in to comment.