File tree Expand file tree Collapse file tree 5 files changed +134
-0
lines changed
Expand file tree Collapse file tree 5 files changed +134
-0
lines changed Original file line number Diff line number Diff line change 1+ FROM cloudposse/github-status-updater:0.2.0-98
2+ # https://github.com/cloudposse/github-status-updater
3+
4+ RUN apk add bash jq git && rm -rf /var/cache/apk/*
5+ ADD update-status.sh /usr/bin/update-commit-status.sh
6+
7+ ENTRYPOINT [ "/usr/bin/update-commit-status.sh" ]
Original file line number Diff line number Diff line change 1+ .PHONY : build
2+ build :
3+ chmod +x update-status.sh
4+ docker build -t commit-status-updater .
5+
6+ .PHONY : shellcheck
7+ shellcheck :
8+ docker run --rm -v " $( CURDIR) :/mnt" koalaman/shellcheck:stable update-status.sh
Original file line number Diff line number Diff line change 1+ # Github Action commit-status-updater
2+
3+ ## Overview
4+
5+ A simple Github Action that allows us to update the status of a given commit.
6+
7+ GitHub does not update the status of a commit when running workflow and therefore tools that rely on the context/status of a given commit are not compatible with it.
8+ An example is [ Prow] ( https://github.com/kubernetes/test-infra/tree/master/prow ) which uses the Github Status API to read the status of a given commit.
9+
10+ ## Integration with Prow
11+
12+ If using [ Prow] ( https://github.com/kubernetes/test-infra/tree/master/prow ) you can now add GitHub Workflows as required checks.
13+
14+ ### Example with Branch Protection and Tide
15+ branch-protection:
16+ ```
17+ branch-protection:
18+ orgs:
19+ {MY_ORG}:
20+ repos:
21+ {MY_REPO}:
22+ branches:
23+ master:
24+ protect: true # enable protection
25+ enforce_admins: true # rules apply to admins
26+ required_status_checks:
27+ contexts:
28+ - "GithubActions - {WORKFLOW_NAME}"
29+ restrictions: # restrict who can push to the repo
30+ users:
31+ - ouzibot
32+ ```
33+ tide:
34+ ```
35+ tide:
36+ context_options:
37+ from-branch-protection: true
38+ ```
39+
40+ ## Example action
41+
42+ ```
43+ name: Test
44+
45+ on: [pull_request]
46+
47+ jobs:
48+ build:
49+ runs-on: ubuntu-latest
50+ steps:
51+ - uses: actions/checkout@v1
52+ - uses: ouzi-dev/github-action-commit-status-updater@master
53+ env:
54+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+ - name: Test
56+ run: |
57+ echo this should always pass after 2 minutes
58+ sleep 2m
59+ echo pass
60+ - if: success()
61+ - uses: ouzi-dev/github-action-commit-status-updater@master
62+ with:
63+ state: success
64+ env:
65+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+ - if: failure()
67+ - uses: ouzi-dev/github-action-commit-status-updater@master
68+ with:
69+ state: failure
70+ env:
71+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+ ```
Original file line number Diff line number Diff line change 1+ name : ' commit-status-updater'
2+ description : ' Updates the current commit status'
3+
4+ inputs :
5+ context :
6+ description : ' The context for the status. Default is GithubActions - ${GITHUB_WORKFLOW}'
7+ state :
8+ description : " Commit state. Possible values are 'pending', 'success', 'error' or 'failure'"
9+ default : ' pending'
10+ token :
11+ description : " The Github token"
12+
13+ runs :
14+ using : ' docker'
15+ image : ' Dockerfile'
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ set -eo pipefail
3+
4+ # Set Defaults if non provided
5+ INPUT_CONTEXT=${INPUT_CONTEXT:- GithubActions - ${GITHUB_WORKFLOW} }
6+
7+ # Chech all inputs have been provided
8+ [[ -z " ${INPUT_STATE} " ]] && { echo " Error: INPUT_STATE not found" ; exit 1; }
9+ [[ -z " ${GITHUB_REPOSITORY} " ]] && { echo " Error: GITHUB_ORG not found" ; exit 1; }
10+ [[ -z " ${GITHUB_TOKEN} " ]] && { echo " Error: GITHUB_TOKEN not found" ; exit 1; }
11+
12+ # Extract the org, repo and get the sha1
13+ GITHUB_ORG=$( echo " ${GITHUB_REPOSITORY} " | awk -F/ ' {print $1}' )
14+ GITHUB_REPO=$( echo " ${GITHUB_REPOSITORY} " | awk -F/ ' {print $2}' )
15+ LAST_COMMIT_SHA=$( git rev-list --no-merges -n 1 HEAD) # get latest non merge commit as github checks out refs/remotes/pull/X/merge instead of the branch
16+
17+ # Check that everything is as expected
18+ [[ -z " ${GITHUB_ORG} " ]] && { echo " Error: GITHUB_ORG is empty" ; exit 1; }
19+ [[ -z " ${GITHUB_REPO} " ]] && { echo " Error: GITHUB_REPO is empty" ; exit 1; }
20+ [[ -z " ${LAST_COMMIT_SHA} " ]] && { echo " Error: LAST_COMMIT_SHA is empty" ; exit 1; }
21+
22+ echo " ** Setting status ${INPUT_STATE} for ${LAST_COMMIT_SHA} in ${GITHUB_ORG} /${GITHUB_REPO} "
23+
24+ # set the status
25+ # https://github.com/cloudposse/github-status-updater
26+ exec github-status-updater -action update_state \
27+ -context " ${INPUT_CONTEXT} " \
28+ -owner " ${GITHUB_ORG} " \
29+ -repo " ${GITHUB_REPO} " \
30+ -state " ${INPUT_STATE} " \
31+ -token " ${GITHUB_TOKEN} " \
32+ -ref " ${LAST_COMMIT_SHA} "
You can’t perform that action at this time.
0 commit comments