diff --git a/README.md b/README.md index 24d203c..27ff429 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,10 @@ jobs: - `working_dir` AWS CDK working directory. (default: '.') - `actions_comment` Whether or not to comment on pull requests. (default: true) +## Outputs + +- `status_code` Returned status code. + ## ENV - `AWS_ACCESS_KEY_ID` **Required** diff --git a/action.yml b/action.yml index 3fe70a5..a7e55b7 100644 --- a/action.yml +++ b/action.yml @@ -20,6 +20,9 @@ inputs: actions_comment: description: 'Whether or not to comment on pull requests.' default: true +outputs: + status_code: + description: 'Returned status code.' runs: using: 'docker' image: './Dockerfile' diff --git a/entrypoint.sh b/entrypoint.sh index c7772ad..d2554f8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -45,6 +45,7 @@ function runCdk(){ echo "Run cdk ${INPUT_CDK_SUBCOMMAND} ${*} \"${INPUT_CDK_STACK}\"" output=$(cdk ${INPUT_CDK_SUBCOMMAND} ${*} "${INPUT_CDK_STACK}" 2>&1) exitCode=${?} + echo ::set-output name=status_code::${exitCode} echo "${output}" commentStatus="Failed" diff --git a/examples/notify_difference_to_slack.yaml b/examples/notify_difference_to_slack.yaml new file mode 100644 index 0000000..cd444c1 --- /dev/null +++ b/examples/notify_difference_to_slack.yaml @@ -0,0 +1,29 @@ +# If Stack has difference, notify to slack + +on: [pull_request] + +jobs: + aws_cdk: + runs-on: ubuntu-latest + steps: + - name: cdk diff + id: diff + uses: youyo/aws-cdk-github-actions@master + with: + cdk_subcommand: 'diff' + actions_comment: true + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: 'ap-northeast-1' + + # https://github.com/marketplace/actions/action-slack + - name: notify slack + uses: 8398a7/action-slack@v2 + with: + status: ${{ job.status }} + author_name: GitHubActions + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + if: ${{ steps.diff.outputs.status_code }} == 1