Skip to content
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

Alternative implementation of the deployment-status action. #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 0 additions & 13 deletions deployment-status/Dockerfile

This file was deleted.

49 changes: 23 additions & 26 deletions deployment-status/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# GitHub Deployment/Release Script

This action is used to manage github deployments and releases on a target repository
This action is used to set the deployment status for GitHub deployments on a different repository.

ex. https://github.com/mozilla/fxa/deployments & https://github.com/mozilla/fxa/releases

## Inputs

### `command`

The command to run. Supported values delete-deployment, delete-release, get-all-deployments, get-all-releases, update-deployment, update-release. Default `"update-deployment"`

### `github_org`

The GitHub organization hosting the target repository. Default `"mozilla"`
Expand All @@ -20,19 +16,27 @@ The GitHub organization hosting the target repository. Default `"mozilla"`

### `environment_url`

The environment URL to set in the deployment request.
The environment URL to set in the deployment request.

### `state`

The deployment state. Supported values in_progress, success, failed. Default `"in_progress"`
The deployment state. Supported values in_progress, success, failure. Default `"in_progress"`

### `deployment_id`

The id of the pre-existing GitHub deployment to set the status for.

### `environment`
### `environment`, `ref`, `sha`

The target deployment environment. Default `"staging"`
Used to uniquely identify the deployment to update, as an alternative to `deployment_id`. Will be ignored if `deployment_id` is set. If no deployment with the given settings exists, a new deployment will be created using this information.

### `ref`
### `app_id`

**Required** The git ref being deployed from the target repository.
The id of the GitHub app with the permission to update deployment statuses on the target repo.

### `private_key`

The private key of the GitHub app.

### Example usage
```
Expand All @@ -48,31 +52,26 @@ on:
description: "Target deployment environment"
type: string
default: "staging"
ref:
ref:
description: "Deployed git ref"
required: true
default: "v1.269.2"

env:
APPLICATION_ID: ${{ secrets.APPLICATION_ID }}
INSTALLATION_ID: ${{ secrets.INSTALLATION_ID }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}

jobs:
update_deployment_job:
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
steps:
- name: Set repository deployment status
uses: mozilla-it/deploy-actions/[email protected]
with:
github_org: mozilla
repository: fxa
environment_url: "https://accounts.stage.mozaws.net/__version__"
state: ${{ github.event.inputs.state }}
environment: ${{ github.event.inputs.environment }}
ref: ${{ github.event.inputs.ref }}
state: ${{ inputs.state }}
environment: ${{ inputs.environment }}
ref: ${{ inputs.ref }}
app_id: ${{ secrets.APPLICATION_ID }}
private_key: ${{ secrets.PRIVATE_KEY }}
```


Expand All @@ -82,6 +81,4 @@ A GitHub app with the permissions to create/modify deployments and/or releases o

- `APPLICATION_ID` - The application ID of the required GitHub app

- `INSTALLATION_ID` - The installation ID of the GitHub app installed in the target repository

- `PRIVATE_KEY` - The private key of the required GitHub app
- `PRIVATE_KEY` - The private key of the required GitHub app
111 changes: 71 additions & 40 deletions deployment-status/action.yml
Original file line number Diff line number Diff line change
@@ -1,59 +1,90 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

name: Deployment status
description: Creates and manages GitHub deployments and releases on target repositories
description: Sets the deployment status for a deployment on a different repository

inputs:
command:
description: Command to run. Supported values delete-deployment, delete-release, get-all-deployments, get-all-releases, update-deployment, update-release
required: false
type: string
default: update-deployment
github_org:
description: GitHub organization hosting the target repository
required: false
type: string
default: mozilla
required: true
repository:
description: GitHub repository to target
type: string
required: true
environment_url:
description: Environment URL to set in deployment
deployment_id:
description: The id of the dpeloyment we want to set the status for
type: string
required: false
default: ""
state:
description: State of deployment. Supported values in_progress, success, failed
type: choice
default: in_progress
environment:
description: Target deployment environment
required: false
sha:
description: Deployed git sha
type: string
default: staging
ref:
required: false
ref:
description: Deployed git ref
type: string
required: false
environment:
description: Target deployment environment
type: string
required: false
state:
description: State of deployment. Supported values in_progress, success, failure
type: choice
required: true
environment_url:
description: Environment URL to set in deployment
type: string
required: false
app_id:
description: The id of the GitHub app to set the deployment status
type: string
required: false
private_key:
description: The private key of the deployment status app
type: string
required: false

runs:
using: docker
image: Dockerfile
args:
- -r
- ${{ inputs.repository }}
- -o
- ${{ inputs.github_org }}
- ${{ inputs.command }}
- --tag
- ${{ inputs.ref }}
- --environment
- ${{ inputs.environment }}
- --state
- ${{ inputs.state }}
- --environment_url
- ${{ inputs.environment_url }}
using: "composite"
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: "${{ inputs.app_id || env.APPLICATION_ID }}"
private-key: "${{ inputs.private_key || env.PRIVATE_KEY }}"
owner: "${{ inputs.github_org }}"
repositories: "${{ inputs.repository }}"
- name: Set deployment status
uses: actions/github-script@v7
with:
github-token: "${{ steps.app-token.outputs.token }}"
script: |
const inputs = ${{ toJSON(inputs) }};
let deployment_id = inputs.deployment_id;

if (!deployment_id) {
deployment_data = {
owner: inputs.github_org,
repo: inputs.repository,
sha: inputs.sha,
ref: inputs.ref,
environment: inputs.environment,
}
const deployments = (await github.rest.repos.listDeployments(deployment_data)).data;
if (deployments.length) {
deployment_id = deployments[0].id;
} else {
deployment_data.auto_merge = false;
deployment_data.required_contexts = [];
const deployment = (await github.rest.repos.createDeployment(deployment_data)).data;
deployment_id = deployment.id;
}
}

github.rest.repos.createDeploymentStatus({
owner: inputs.github_org,
repo: inputs.repository,
deployment_id,
state: inputs.state,
log_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
environment_url: inputs.environment_url,
})
3 changes: 0 additions & 3 deletions deployment-status/app/entrypoint.sh

This file was deleted.

Loading