diff --git a/CHANGELOG.md b/CHANGELOG.md index d3ba6bc..f02a153 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,6 @@ +## [1.1.0](https://github.com/ReasonSoftware/action-github-deployment/releases/tag/v1.1.0) - 2021-02-14 +### Added +- Failure trap which enable to use only one action for either success/failure status instead of two actions + ## [1.0.0](https://github.com/ReasonSoftware/action-github-deployment/releases/tag/v1.0.0) - 2021-02-14 - First release \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b4ba916..58b9aef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o /opt/action-github-deployment FROM scratch LABEL "repository"="https://github.com/ReasonSoftware/action-github-deployment" -LABEL "version"="1.0.0" +LABEL "version"="1.1.0" COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=build /etc/passwd /etc/passwd COPY LICENSE.md /LICENSE.md diff --git a/README.md b/README.md index 849e7b8..38bb688 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,20 @@ Just to add an action to your CD flow STATUS: success ``` +You may also update the deployment to either `success` or `failure` in one step by providing an overall status as `FAIL` environmental variable: + +```yaml + [...] + + - name: Update Status + uses: docker://reasonsoftware/action-github-deployment:v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DEPLOYMENT: ${{steps.deployment.outputs.id}} + STATUS: success + FAIL: "${{ failure() }}" +``` +
:information_source: Create a deployment with non-default status @@ -65,6 +79,7 @@ Just to add an action to your CD flow - `DEPLOYMENT` - existing deployment ID, required when updating status - `STATUS` - status of a deployment, must be one of the following: `[ error, failure, inactive, in_progress, queued, pending, success ]` - `ENVIRONMENT` - GitHub Environment, default `production` +- `FAIL`: failure trap which will tweak the status to be **failure** on value `"true"`. Used to reduce overal workflow code by configuring one action for both successful or failed deployments with `FAIL: "${{ failure() }}"` ## Notes diff --git a/main.go b/main.go index e9f151b..91b3368 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ import ( ) // Version of an application -const Version string = "1.0.0" +const Version string = "1.1.0" func init() { log.SetReportCaller(false) @@ -88,8 +88,25 @@ func main() { if os.Getenv("STATUS") != "" { log.Infof("updating status of a deployment %v in %v environment", id, env) - if err := app.UpdateStatus(cli.Repositories, id, os.Getenv("STATUS")); err != nil { - log.Fatal(errors.Wrap(err, "error updating deployment status")) + failed := false + if os.Getenv("FAIL") != "" { + var err error + failed, err = strconv.ParseBool(os.Getenv("FAIL")) + if err != nil { + log.Fatal(errors.Wrap(err, "error parsing env.var 'FAIL'")) + } + } + + if failed { + log.Warnf("FAIL=%v, updating deployment status to 'failure'", failed) + + if err := app.UpdateStatus(cli.Repositories, id, "failure"); err != nil { + log.Fatal(errors.Wrap(err, "error updating deployment status")) + } + } else { + if err := app.UpdateStatus(cli.Repositories, id, os.Getenv("STATUS")); err != nil { + log.Fatal(errors.Wrap(err, "error updating deployment status")) + } } log.Info("deployment status set to ", os.Getenv("STATUS"))