diff --git a/.gitattributes b/.gitattributes
index 7999b201..59664b7b 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1 +1 @@
-dist/* linguist-generated
+dist/* linguist-generated -diff
diff --git a/.github/workflows/cleanup.yaml b/.github/workflows/cleanup.yaml
new file mode 100644
index 00000000..e1d60d1c
--- /dev/null
+++ b/.github/workflows/cleanup.yaml
@@ -0,0 +1,48 @@
+name: cleanup
+
+on:
+ pull_request:
+ types: [ closed ]
+
+jobs:
+ delete-env:
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ scenario: [ 'success', 'failure' ]
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
+ with:
+ node-version: '18'
+
+ # Dependencies
+ # https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#example-using-the-cache-action
+ - name: Cache node modules
+ uses: actions/cache@v2
+ env:
+ cache-name: cache-node-modules
+ with:
+ path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
+ key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
+ restore-keys: |
+ ${{ runner.os }}-build-${{ env.cache-name }}-
+ ${{ runner.os }}-build-
+ ${{ runner.os }}-
+ - run: npm install
+ - run: npm run build
+
+ - name: extract branch name
+ id: get_branch
+ shell: bash
+ env:
+ PR_HEAD: ${{ github.head_ref }}
+ run: echo "##[set-output name=branch;]$(echo ${PR_HEAD#refs/heads/} | tr / -)"
+
+ - name: delete environment
+ uses: ./
+ with:
+ step: delete-env
+ token: ${{ secrets.GITHUB_TOKEN }}
+ env: integration-test-${{ steps.get_branch.outputs.branch }}-${{ matrix.scenario }}
+ debug: true
diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml
index 658a38bc..7041cae2 100644
--- a/.github/workflows/pipeline.yaml
+++ b/.github/workflows/pipeline.yaml
@@ -1,16 +1,20 @@
name: pipeline
-on: [push]
+on:
+ push:
+ branches:
+ - '**'
+ pull_request: {}
jobs:
- build:
+ checks:
runs-on: ubuntu-latest
steps:
# Environment
- - uses: actions/checkout@v2
- - uses: actions/setup-node@v2
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
with:
- node-version: '12'
+ node-version: '18'
# Dependencies
# https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#example-using-the-cache-action
@@ -30,3 +34,133 @@ jobs:
# Checks
- run: npm run prettier:check
- run: npm run build:check
+
+ integration-tests:
+ runs-on: ubuntu-latest
+ needs: checks
+ strategy:
+ matrix:
+ scenario: [ 'success', 'failure' ]
+ include:
+ - scenario: 'success'
+ exit_code: 0
+ - scenario: 'failure'
+ exit_code: 1
+ fail-fast: false
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
+ with:
+ node-version: '18'
+
+ # Dependencies
+ # https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#example-using-the-cache-action
+ - name: Cache node modules
+ uses: actions/cache@v2
+ env:
+ cache-name: cache-node-modules
+ with:
+ path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
+ key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
+ restore-keys: |
+ ${{ runner.os }}-build-${{ env.cache-name }}-
+ ${{ runner.os }}-build-
+ ${{ runner.os }}-
+ - run: npm install
+ - run: npm run build
+
+ - name: extract branch name
+ id: get_branch
+ shell: bash
+ run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/} | tr / -)"
+
+ - name: start deployment
+ uses: ./
+ id: deployment
+ with:
+ step: start
+ token: ${{ secrets.GITHUB_TOKEN }}
+ env: integration-test-${{ steps.get_branch.outputs.branch }}-${{ matrix.scenario }}
+ desc: 'Deployment starting!'
+ debug: true
+
+ - name: parse repo name and owner
+ id: parse_repo
+ shell: bash
+ # outputs: owner, name
+ run: |
+ echo "owner=$(cut -d "/" -f 1 <<<"${{ github.repository }}")" >> $GITHUB_OUTPUT
+ echo "name=$(cut -d "/" -f 2 <<<"${{ github.repository }}")" >> $GITHUB_OUTPUT
+
+
+ - name: assert deployment in progress
+ uses: actions/github-script@v6
+ env:
+ deployment_id: ${{ steps.deployment.outputs.deployment_id }}
+ status_id: ${{ steps.deployment.outputs.status_id }}
+ with:
+ script: |
+ const { deployment_id, status_id } = process.env;
+ if (!deployment_id) {
+ throw new Error("deployment_id not set");
+ }
+ if (!status_id) {
+ throw new Error("status_id not set");
+ }
+ const res = await github.rest.repos.getDeploymentStatus({
+ owner: "${{ steps.parse_repo.outputs.owner }}",
+ repo: "${{ steps.parse_repo.outputs.name }}",
+ deployment_id: parseInt(deployment_id, 10),
+ status_id: parseInt(status_id, 10),
+ });
+ console.log(res)
+ if (res.data.state !== "in_progress") {
+ throw new Error(`unexpected status ${res.data.state}`);
+ }
+
+ - name: set deployment status to ${{ matrix.scenario }}
+ uses: ./
+ id: finish
+ with:
+ step: finish
+ token: ${{ secrets.GITHUB_TOKEN }}
+ status: ${{ matrix.scenario }}
+ deployment_id: ${{ steps.deployment.outputs.deployment_id }}
+ env: ${{ steps.deployment.outputs.env }}
+ desc: 'Deployment complete'
+ debug: true
+
+ - name: assert deployment complete
+ uses: actions/github-script@v6
+ env:
+ deployment_id: ${{ steps.deployment.outputs.deployment_id }}
+ status_id: ${{ steps.finish.outputs.status_id }}
+ expected_state: ${{ matrix.scenario }}
+ with:
+ script: |
+ const { deployment_id, status_id, expected_state } = process.env;
+ if (!deployment_id) {
+ throw new Error("deployment_id not set");
+ }
+ if (!status_id) {
+ throw new Error("status_id not set");
+ }
+ const res = await github.rest.repos.getDeploymentStatus({
+ owner: "${{ steps.parse_repo.outputs.owner }}",
+ repo: "${{ steps.parse_repo.outputs.name }}",
+ deployment_id: parseInt(deployment_id, 10),
+ status_id: parseInt(status_id, 10),
+ });
+ console.log(res)
+ if (res.data.state !== expected_state) {
+ throw new Error(`unexpected status ${res.data.state}`);
+ }
+
+ - name: mark environment as deactivated
+ uses: ./
+ with:
+ step: deactivate-env
+ token: ${{ secrets.GITHUB_TOKEN }}
+ env: ${{ steps.deployment.outputs.env }}
+ desc: Environment was pruned
+ debug: true
diff --git a/.github/workflows/publish_v1.yaml b/.github/workflows/publish_v1.yaml
new file mode 100644
index 00000000..06988f45
--- /dev/null
+++ b/.github/workflows/publish_v1.yaml
@@ -0,0 +1,18 @@
+name: publish@v1
+
+on:
+ push:
+ tags: [ 'v1.*' ]
+
+jobs:
+ publish:
+ runs-on: ubuntu-latest
+ steps:
+ - name: checkout
+ uses: actions/checkout@v2
+ - name: update tag
+ run: |
+ git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
+ git config --global user.name "${GITHUB_ACTOR}"
+ git tag -fa v1 -m "update v1 tag"
+ git push origin v1 --force
diff --git a/README.md b/README.md
index 53491079..81033973 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,17 @@
-# GitHub Deployments [](https://bobheadxi.dev/r/deployments/)
+# GitHub Deployments [](https://bobheadxi.dev/r/deployments/) [](https://github.com/bobheadxi/deployments/actions/workflows/pipeline.yaml)
-`bobheadxi/deployments` is a [GitHub Action](https://github.com/features/actions) for working painlessly with deployment statuses.
-Instead of exposing convoluted Action configuration that mirrors that of the [GitHub API](https://developer.github.com/v3/repos/deployments/) like some of the other available Actions do, this Action simply exposes a number of configurable, easy-to-use "steps" common to most deployment flows.
+`bobheadxi/deployments` is a [GitHub Action](https://github.com/features/actions) for working painlessly with [GitHub deployment statuses](https://docs.github.com/en/rest/reference/deployments).
+Instead of exposing convoluted Action configuration that mirrors that of the [GitHub API](https://developer.github.com/v3/repos/deployments/) like some of the other available Actions do, this Action simply exposes a number of configurable, easy-to-use "steps" common to most deployment lifecycles.
-- [Features](#features)
+> 📢 This project is in need of additional maintainers - if you are interested in helping out please [let me know](https://github.com/bobheadxi/deployments/discussions/103)!
+
+- [Configuration](#configuration)
- [`step: start`](#step-start)
- [`step: finish`](#step-finish)
- [`step: deactivate-env`](#step-deactivate-env)
+ - [`step: delete-env`](#step-delete-env)
- [Debugging](#debugging)
+- [Migrating to v1](#migrating-to-v1)
A simple example:
@@ -15,13 +19,14 @@ A simple example:
on:
push:
branches:
- - master
+ - main
jobs:
deploy:
+ runs-on: ubuntu-latest
steps:
- name: start deployment
- uses: bobheadxi/deployments@v0.6.2
+ uses: bobheadxi/deployments@v1
id: deployment
with:
step: start
@@ -32,27 +37,41 @@ jobs:
# ...
- name: update deployment status
- uses: bobheadxi/deployments@v0.6.2
+ uses: bobheadxi/deployments@v1
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
+ env: ${{ steps.deployment.outputs.env }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
```
-See [this blog post](https://dev.to/bobheadxi/branch-previews-with-google-app-engine-and-github-actions-3pco) for a bit of background and more practical example.
-You can also refer to other projects that also use this action:
+You can also refer to other projects that also use this action - you can find [more usages of this action on Sourcegraph](https://sourcegraph.com/search?q=context:global+uses:+bobheadxi/deployments%40.*+file:%5E%5C.github/workflows+-repo:bobheadxi+count:all&patternType=regexp), or check out the following examples:
- [`github/super-linter`](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/github/super-linter%24+file:%5E%5C.github/workflows+bobheadxi/deployments&patternType=literal) [](https://github.com/github/super-linter) - [GitHub's all-in-one linter Action](https://github.blog/2020-06-18-introducing-github-super-linter-one-linter-to-rule-them-all/)
- [`mxcl/PromiseKit`](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/mxcl/PromiseKit%24+file:%5E%5C.github/workflows+bobheadxi/deployments&patternType=literal) [](https://github.com/mxcl/PromiseKit) - promises for Swift and Objective-C
-- [`mirumee/saleor`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/mirumee/saleor%24+bobheadxi/deployments\&patternType=literal) [](https://github.com/mirumee/saleor) - modular, high performance, headless e-commerce storefront
+- [`saleor/saleor`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/saleor/saleor%24+bobheadxi/deployments\&patternType=literal) [](https://github.com/saleor/saleor) - modular, high performance, headless e-commerce storefront
- [`sharetribe/sharetribe`](https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/sharetribe/sharetribe%24+file:%5E%5C.github/workflows+bobheadxi/deployments&patternType=literal) [](https://github.com/sharetribe/sharetribe) - marketplace software
- [`skylines-project/skylines`](https://sourcegraph.com/search?q=repo:%5Egithub%5C.com/skylines-project/skylines%24+bobheadxi/deployments\&patternType=literal) [](https://github.com/skylines-project/skylines) - live tracking, flight database and competition web platform
-You can find [more usages of this action on Sourcegraph](https://sourcegraph.com/search?q=context:global+bobheadxi/deployments+file:%5E%5C.github/workflows+-repo:bobheadxi&patternType=literal)!
+Also feel free to chime in on the [show and tell discussion](https://github.com/bobheadxi/deployments/discussions/84) to share your usages of this Action!
+
+Check out [this blog post](https://dev.to/bobheadxi/branch-previews-with-google-app-engine-and-github-actions-3pco) for a bit of background on the origins of this project.
+
+## Configuration
-## Features
+The following [`inputs`](https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepswith) configuration options are for *all steps*:
+
+| Variable | Default | Purpose |
+| ------------ | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
+| `step` | | One of [`start`](#step-start), [`finish`](#step-finish), [`deactivate-env`](#step-deactivate-env), or [`delete-env`](#step-delete-env) |
+| `token` | `${{ github.token }}` | provide your `${{ github.token }}` or `${{ secrets.GITHUB_TOKEN }}` for API access |
+| `env` | | identifier for environment to deploy to (e.g. `staging`, `prod`, `main`) |
+| `repository` | Current repository | target a specific repository for updates, e.g. `owner/repo` |
+| `logs` | URL to GitHub commit checks | URL of your deployment logs |
+| `desc` | GitHub-generated description | description for this deployment |
+| `ref` | `github.ref` | Specify a particular git ref to use, (e.g. `${{ github.head_ref }}`) |
### `step: start`
@@ -61,26 +80,23 @@ This is best used on the `push: { branches: [ ... ] }` event, but you can also h

-The following [`inputs`](https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepswith) are available:
+In addition to the [core configuration](#configuration), the following [`inputs`](https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepswith) are available:
+
+| Variable | Default | Purpose |
+| --------------- | ------- | --------------------------------------------------------------------------------------------------- |
+| `deployment_id` | | Use an existing deployment instead of creating a new one (e.g. `${{ github.event.deployment.id }}`) |
+| `override` | `false` | whether to mark existing deployments of this environment as inactive |
+| `payload` | | JSON-formatted dictionary with extra information about the deployment |
+| `task` | `'deploy'` | change the task associated with this deployment, can be any string
-| Variable | Default | Purpose |
-| --------------- | --------------------------- | ------------------------------------------------------------------------------------------------------ |
-| `step` | | must be `start` for this step |
-| `token` | | provide your `${{ secrets.GITHUB_TOKEN }}` for API access |
-| `logs` | URL to GitHub commit checks | URL of your deployment logs |
-| `desc` | | description for this deployment |
-| `env` | | identifier for environment to deploy to (e.g. `staging`, `prod`, `master`) |
-| `no_override` | `true` | toggle whether to mark existing deployments of this environment as inactive once the deployment starts |
-| `transient` | `false` | Mark deployment as transient. Transient deployments are not automatically deactivated |
-| `deployment_id` | | Use an existing deployment instead of creating a new one (e.g. `${{ github.event.deployment.id }}`) |
-| `ref` | `github.ref` | Specify a particular git ref to use, (e.g. `${{ github.head_ref }}`) |
The following [`outputs`](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#steps-context) are available:
-| Variable | Purpose |
-| --------------- | ------------------------------- |
-| `deployment_id` | ID of created GitHub deployment |
-| `env` | name of configured environment |
+| Variable | Purpose |
+| --------------- | -------------------------------------- |
+| `deployment_id` | ID of created GitHub deployment |
+| `status_id` | ID of created GitHub deployment status |
+| `env` | name of configured environment |
Simple Push Example
@@ -90,17 +106,16 @@ The following [`outputs`](https://help.github.com/en/actions/automating-your-wor
on:
push:
branches:
- - master
+ - main
jobs:
deploy:
steps:
- name: start deployment
- uses: bobheadxi/deployments@v0.6.2
+ uses: bobheadxi/deployments@v1
id: deployment
with:
step: start
- token: ${{ secrets.GITHUB_TOKEN }}
env: release
- name: do my deploy
@@ -122,15 +137,14 @@ on:
jobs:
deploy:
+ runs-on: ubuntu-latest
steps:
- name: start deployment
- uses: bobheadxi/deployments@v0.6.2
+ uses: bobheadxi/deployments@v1
id: deployment
with:
step: start
- token: ${{ secrets.GITHUB_TOKEN }}
env: integration
- ref: ${{ github.head_ref }}
- name: do my deploy
# ...
@@ -148,18 +162,15 @@ This is best used after `step: start` and should follow whatever deployment task

-The following [`inputs`](https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepswith) are available:
+In addition to the [core configuration](#configuration), the following [`inputs`](https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepswith) are available:
-| Variable | Default | Purpose |
-| --------------- | --------------------------- | --------------------------------------------------------------------------------- |
-| `step` | | must be `finish` for this step |
-| `token` | | provide your `${{ secrets.GITHUB_TOKEN }}` for API access |
-| `logs` | URL to GitHub commit checks | URL of your deployment logs |
-| `desc` | | description for this deployment |
-| `status` | | provide the current deployment job status `${{ job.status }}` |
-| `deployment_id` | | identifier for deployment to update (see outputs of [`step: start`](#step-start)) |
-| `env_url` | | URL to view deployed environment |
-| `auto_inactive` | `true` | Mark previous non-transient deployments as `inactive` |
+| Variable | Default | Purpose |
+| --------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `status` | | provide the current deployment job status `${{ job.status }}` |
+| `deployment_id` | | identifier for deployment to update (see outputs of [`step: start`](#step-start)) |
+| `env_url` | | URL to view deployed environment |
+| `override` | `true` | whether to manually mark existing deployments of this environment as inactive |
+| `auto_inactive` | `false` | whether to let GitHub handle marking existing deployments of this environment as inactive ([if and only if a new deployment succeeds](https://docs.github.com/en/rest/reference/deployments#inactive-deployments)). |
Simple Example
@@ -178,12 +189,13 @@ jobs:
# ...
- name: update deployment status
- uses: bobheadxi/deployments@v0.6.2
+ uses: bobheadxi/deployments@v1
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
+ env: ${{ steps.deployment.outputs.env }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
```
@@ -199,15 +211,7 @@ This step can be used to automatically shut down deployments you create on pull

-The following [`inputs`](https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepswith) are available:
-
-| Variable | Default | Purpose |
-| -------- | --------------------------- | -------------------------------------------------------------------------- |
-| `step` | | must be `deactivate-env` for this step |
-| `token` | | provide your `${{ secrets.GITHUB_TOKEN }}` for API access |
-| `logs` | URL to GitHub commit checks | URL of your deployment logs |
-| `desc` | | description for this deployment |
-| `env` | | identifier for environment to deploy to (e.g. `staging`, `prod`, `master`) |
+Refer to the [core configuration](#configuration) for available [`inputs`](https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepswith).
Simple Example
@@ -233,21 +237,54 @@ jobs:
# ...
- name: mark environment as deactivated
- uses: bobheadxi/deployments@v0.6.2
+ uses: bobheadxi/deployments@v1
with:
step: deactivate-env
token: ${{ secrets.GITHUB_TOKEN }}
env: ${{ steps.get_branch.outputs.branch }}
- desc: Deployment was pruned
+ desc: Environment was pruned
```