@@ -6,45 +6,166 @@ This command line client is based on Github API V3.
66
77You can manipulate following Github resources:
88
9- - deployment
10- - deployment_status
9+ - [ deployments ] ( https://developer.github.com/v3/repos/deployments/ )
10+ - [ deployment_status] ( https://developer.github.com/v3/repos/deployments/#list-deployment-statuses )
1111
1212## What it will (probably) never do
1313
14- Managing resources like pull requests, issues or repositories life cycle and settings for example.
14+ Managing resources like pull requests, issues or repositories life cycle and
15+ settings for example.
1516
16- Some very good tools like [ hub] ( https://github.com/github/hub ) or [ terraform's github provider] ( https://www.terraform.io/docs/providers/github/index.html ) are already great at doing that.
17+ Some very good tools like [ hub] ( https://github.com/github/hub ) or
18+ [ terraform provider] ( https://www.terraform.io/docs/providers/github/index.html )
19+ are already great at doing that.
20+
21+ ## How to install it?
22+
23+ ``` shell
24+ go get github.com/inextensodigital/github
25+ ```
26+
27+ or... (feel free to replace ` linux ` by either ` windows ` or ` darwin ` )
28+
29+ ``` shell
30+ curl -s https://api.github.com/repos/inextensodigital/github/releases/latest |
31+ jq -r ' .assets[] | select(.name | test("linux-amd64$")) | .browser_download_url' |
32+ wget -qi - -O github && chmod +x github
33+ ```
1734
1835## Why another Github client?
1936
20- The goal is to have a convenient, lightweight tool to use inside github [ actions v2] ( https://github.com/features/actions ) workflows.
37+ The goal is to have a convenient, lightweight tool to use inside github
38+ [ actions v2] ( https://github.com/features/actions ) workflows.
2139
2240Some use cases that motivated the creation of this tool were:
2341
24- ``` shell
25- # Create a production deployment and corresponding status, long syntax
26- DEPLOYMENT_ID=$(
27- github deployment create \
28- --environment production \
29- --task deploy:migration \
30- $GITHUB_REF
31- )
32- github deployment_status create $DEPLOYMENT_ID in_progress
33- # Create a production deployment and corresponding status, short syntax
34- github ds c $( github d c -e production -t deploy:migration) in_progress
42+ ### How it can help you in github actions v2?
43+
44+ #### Continuous deployment on staging
45+
46+ ``` yaml
47+ name : trigger staging deployment on pull request merged
48+ on :
49+ push :
50+ branches : [master, dev]
51+ jobs :
52+ deploy :
53+ runs-on : ubuntu-latest
54+ steps :
55+ - run : echo build app
56+ - run : |
57+ sudo wget -q -O /usr/local/bin/github $(
58+ curl -s https://api.github.com/repos/inextensodigital/github/releases/latest |
59+ jq -r '.assets[] | select(.name | test("linux-amd64$")) | .browser_download_url'
60+ )
61+ sudo chmod +x /usr/local/bin/github
62+ - id : deployment
63+ env :
64+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
65+ run : |
66+ id=$(github deployment create --autoMerge=false --productionEnvironment=false --environment staging $GITHUB_REF)
67+ github deployment_status create $id in_progress
68+ echo "##[set-output name=deployment_id;]$id"
69+ - env :
70+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
71+ ID : ${{ steps.deployment.outputs.deployment_id }}
72+ run : |
73+ echo deploy app
74+ github deployment_status create $ID success
75+ - if : failure()
76+ env :
77+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
78+ ID : ${{ steps.deployment.outputs.deployment_id }}
79+ run : github deployment_status create $ID failure
3580` ` `
3681
37- ## How to install it?
82+ #### Continuous delivery on production
3883
39- ``` shell
40- go get github.com/inextensodigital/github
84+ ` ` ` yaml
85+ name : create production deployment on release published
86+ on : release
87+ jobs :
88+ is-published :
89+ runs-on : ubuntu-latest
90+ steps :
91+ - if : github.event.action != 'published'
92+ run : exit 1
93+ build :
94+ runs-on : ubuntu-latest
95+ needs : is-published
96+ steps :
97+ - run : echo build app
98+ create-deployment :
99+ runs-on : ubuntu-latest
100+ needs : build
101+ steps :
102+ # # optional: install hub
103+ # - run: |
104+ # curl -s https://api.github.com/repos/github/hub/releases/latest |
105+ # jq -r '.assets[] | select(.name | contains("linux-amd64")) | .browser_download_url' |
106+ # wget -qi - -O - | sudo tar xzpf - -C / --strip-components=1
107+ # - uses: actions/checkout@master
108+ - run : |
109+ sudo wget -q -O /usr/local/bin/github $(
110+ curl -s https://api.github.com/repos/inextensodigital/github/releases/latest |
111+ jq -r '.assets[] | select(.name | test("linux-amd64$")) | .browser_download_url'
112+ )
113+ sudo chmod +x /usr/local/bin/github
114+ - id : deployment
115+ env :
116+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
117+ run : |
118+ id=$(github deployment create --autoMerge=false $GITHUB_REF)
119+ echo "##[set-output name=deployment_id;]$id"
120+ # #-----------------------------8<----------------------------------------
121+ # # here: some job(s) to add for example a deploy button/process
122+ # - uses: some-deploy-button-action
123+ # id: button
124+ # with:
125+ # deployment_id: ${{ steps.deployment.outputs.deployment_id }}
126+ # - name: append button to release note
127+ # env:
128+ # DEPLOY_BUTTON: ${{ steps.button.outputs.release-button }}
129+ # TAG_NAME: ${{ github.event.release.tag_name }}
130+ # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
131+ # GITHUB_USER: ${{ github.actor }}
132+ # run: |
133+ # button=$(printf '\n## Deploy to production :rocket:\n%s\n' "$DEPLOY_BUTTON")
134+ # hub release edit -m "" -m "$(hub release show $TAG_NAME -f %b)" -m "$button" $TAG_NAME
135+ # #-----------------------------8<----------------------------------------
41136```
42137
43- or... (feel free to replace ` linux ` by either ` windows ` or ` darwin ` )
138+ Then, some external approbation process put the deployment status to ` in_progress `
139+ and you effectively deploy on production :tada :
44140
45- ``` shell
46- curl -s https://api.github.com/repos/inextensodigital/github/releases/latest | \
47- jq -r ' .assets[] | select(.name | contains("linux-amd64")) | .browser_download_url' | \
48- grep -v sha256 | \
49- wget -qi - -O github && sudo chmod +x github
141+ ``` yaml
142+ name : deploy on production
143+ on : deployment_status
144+ jobs :
145+ should-deploy :
146+ runs-on : ubuntu-latest
147+ steps :
148+ - if : github.event.deployment.original_environment != 'production' || github.event.deployment_status.state != 'in_progress'
149+ run : exit 1
150+ deploy :
151+ needs : should-deploy
152+ runs-on : ubuntu-latest
153+ steps :
154+ - run : |
155+ sudo wget -q -O /usr/local/bin/github $(
156+ curl -s https://api.github.com/repos/inextensodigital/github/releases/latest |
157+ jq -r '.assets[] | select(.name | test("linux-amd64$")) | .browser_download_url'
158+ )
159+ sudo chmod +x /usr/local/bin/github
160+ - env :
161+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
162+ ID : ${{ github.event.deployment.id }}
163+ run : |
164+ echo deploy app
165+ github deployment_status create $ID success
166+ - if : failure()
167+ env :
168+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
169+ ID : ${{ github.event.deployment.id }}
170+ run : github deployment_status create $ID failure
50171` ` `
0 commit comments