BASE BANK æ ªå¼ä¼ç¤¾ Dev Division ã§Software Developer ããã¦ããæ¸ æ°´ï¼ @budougumi0617 ï¼ã§ãã
ã¿ãªããã®éçºç¾å ´ã§ã社å
ã©ã¤ãã©ãªã»ã¢ã¸ã¥ã¼ã«ã¨ãã¦éçºãã¦ããã³ã¼ãã»GitHubãªãã¸ããªãããã¨æãã¾ãã
ãã®ãããªãªãã¸ããªã¯ããã±ã¼ã¸ç®¡çã·ã¹ãã ãçµç±ãã¦å©ç¨ãããã¨ãã»ã¨ãã©ã§ããããã®ããã«ã¯ãªãªã¼ã¹ä½æ¥ãè¡ãå¿
è¦ããããã¨æãã¾ãã
ç§ã®ãã¼ã ã§ã¯å æ¥GitHubãªãã¸ããªã®ãªãªã¼ã¹ä½æ¥ãGitHub Actionsã§èªååããã®ã§ãæ¬è¨äºã§ã¯ãã®å 容ãå ±æãããã¨æãã¾ãã
TL;DR
ä»åã¯GitHub Actionsã¨release-it npmã使ã£ã¦ãã¾ãã
ä¸è¨ã®æè¡ãçµã¿åããããã¨ã§æ¬¡ã®ãããªèªåãªãªã¼ã¹ã®ã¯ã¼ã¯ããã¼ãæ§ç¯ãã¾ããã
- ï¼Pull Requestããã¼ã¸ããããªã©ã§ï¼mainãã©ã³ãã«ã³ããããããã·ã¥ããããã¿ã°ãæã¡ãGitHubãªãªã¼ã¹ãä½æããã
- ååãªãªã¼ã¹ã¨ã®å·®åã§ã³ãããã¡ãã»ã¼ã¸ã®ãªãªã¼ã¹ãã¼ããä½æãã
- ç¹å®ã®ãã¡ã¤ã«ã¾ãã¯ãã£ã¬ã¯ããªãæ´æ°ããã¦ããã¨ãã ããªãªã¼ã¹ãã
- ã³ãããã¡ãã»ã¼ã¸ã«å¿ãã¦ã»ãã³ãã£ãã¯ãã¼ã¸ã§ã³ã®ããã/ãã¤ãã¼/ã¡ã¸ã£ã¼ã¢ãããã¼ããåãæ¿ãã
- Actionsä¸ã§ãã使ããªãnpmããã±ã¼ã¸ãªã®ã§ããªãã¸ããªã«package.jsonãç½®ããªã
GitHub Actionsã使ã£ã¦èªååãè¡ãªãã¨ãã³ãããå
容ã«å¿ããæä½ãç°¡åã«å®ç¾ã§ãã¾ãã
ãã ãã次ã®å¶ç´ãããã¾ããã
- ãããã¯ããã©ã³ããå©ç¨ãã¦ããå ´åã¯GitHub Actionsä¸ããã³ããããããã·ã¥ãããã¨ã¯ã§ããªã
- ãªãªã¼ã¹ç¨ã®PRãã¤ããã¨ãã£ãè¿åçãå¿ è¦
ãã®ãããä»åã®èªåãªãªã¼ã¹ã§ã¯ããªãã¸ããªå
ã®version
å¤æ°ã®å¤ãæ´æ°ãã¦ã³ããããã¦ãããã®ãããªæä½ã¯å«ãã§ãã¾ããã
ãªããä»ãã試ãã¦ã¿ããæ¹ã¯ä»¥ä¸ã®2ã¤ã®ãã¡ã¤ã«ãç¨æããã ãã§å®ç¾ã§ãã¾ãã
- .release-it.json
- .github/workflows/release.yml
.release-it.json
ã®å
容ã¯æ¬¡ã®ã¨ããã§ããGitHubãªãã¸ããªã®ã«ã¼ããã£ã¬ã¯ããªã«é
ç½®ãã¾ãã
{ "requireUpstream": false, "requireCleanWorkingDir": false, "github": { "release": true }, "git": { "commit": false, "push": false, "requireUpstream": false, "requireCleanWorkingDir": false }, "npm": { "publish": false, "ignoreVersion": true } }
.github/workflows/release.yml
ã®å
容ã¯æ¬¡ã®ã¨ããã§ãã
name: auto release demo on: push: # mainãã©ã³ãã«ã³ããããpushãããã¨ãã«éå® branches: - main # ä¸è¨æ¡ä»¶ã«å ãã¦genãã£ã¬ã¯ããªé ä¸ãå¤æ´ãããã¨ãã®ã¿ã¨ããæ¡ä»¶ã追å paths: - gen/** jobs: auto-release: runs-on: ubuntu-latest env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} RELEASE_IT_VERSION: 14.2.1 steps: - name: Check out codes uses: actions/checkout@v2 with: fetch-depth: 0 - name: Setup Node uses: actions/setup-node@v1 with: node-version: '12' - name: Set releaser settings run: | git config --global user.name release-machine git config --global user.email [email protected] - name: Major release id: major if: contains(toJSON(github.event.commits.*.message), 'bump up version major') run: npx release-it@${RELEASE_IT_VERSION} -- major --ci - name: Minor release id: minor # ã¡ã¸ã£ã¼ãã¼ã¸ã§ã³ã¢ããããã¦ããªãã¨ããã¤ãã¼ãã¼ã¸ã§ã³ã¢ãããè¡ãªãã if: steps.major.conclusion == 'skipped' && contains(toJSON(github.event.commits.*.message), 'bump up version minor') run: npx release-it@${RELEASE_IT_VERSION} -- minor --ci - name: Patch release # ã³ãããã¡ãã»ã¼ã¸ã«ç¹ã«æå®ããªãå ´åã¯ãã¤ãã¼ãã¼ã¸ã§ã³ãæ´æ°ãã if: "!(steps.major.conclusion == 'success' || steps.minor.conclusion == 'success')" run: npx release-it@${RELEASE_IT_VERSION} -- patch --ci
ä»åã®ãµã³ãã«YAMLã®å ´åã¯main ãã©ã³ãã«gen
ãã£ã¬ã¯ããªå
ã¸ã®å¤æ´ãå«ãã PRããã¼ã¸ããã¨èªåã§ãªãªã¼ã¹ãè¡ãªããã¾ãã
ã¾ããbump up version major
ã¨ãã£ãã¡ãã»ã¼ã¸ãå«ã¾ãã¦ããå ´åã¯ã¡ã¸ã£ã¼ãã¼ã¸ã§ã³ã¢ãããè¡ãªããã¾ãã
ãªããæ¬è¨äºã§å©ç¨ãã¦ããåãã¼ã«ã®ãã¼ã¸ã§ã³ã¯ä»¥ä¸ã®ã¨ããã§ãã
ãã¼ã«å | ãã¼ã¸ã§ã³ |
---|---|
GitHub Actions | v2 |
release-it npm | 14.2.1 |
Node.js | 12.Xç³» |
以ä¸ã®URLã¯å®éã«GitHub Actionsã§ä½åãèªåãªãªã¼ã¹ããã¦ã¿ããµã³ãã«ãªãã¸ããªã§ãã
ãªãªã¼ã¹ä½æ¥ãèªååããã
ã©ããªè¨èªã使ã£ã¦ãã¦ããæ¥åã§éçºãè¡ãªã£ã¦ããã¨ç¤¾å
ã©ã¤ãã©ãªãä½æãããã¨ãããã¨æãã¾ãã
ä½æããã©ã¤ãã©ãªã¯npmãComposerãGo Modulesãªã©ã®ããã±ã¼ã¸ç®¡çã·ã¹ãã ãçµç±ãã¦ä½¿ããã¨ã«ãªãã®ã大åã ã¨æãã¾ãã
ãããªãã¨ä¸å®ã®æ´æ°ãã¨ã«ã¿ã°ãè¨å®ãããã¼ã¸ã§ã³ç®¡çããå¿
è¦ãåºã¦ãã¾ãã
ã¨ã¯ãã ãPRããã¼ã¸ãããgit tag
ã³ãã³ããæã£ã¦â¦ãã¨åéçºè
ãè¡ãªãã®ã¯åå«ã§ãã
ãã®ãããmainãã©ã³ãã«PRããã¼ã¸ããããï¼ã³ããããããã·ã¥ããããï¼èªåã§ã¿ã°æã¡ããªãªã¼ã¹ããã¨ããèªååã試ã¿ã¾ããã
ãã¡ããã¿ã°ã¯ãªãªã¼ã¹ã®ãã³ã«ã»ãã³ãã£ãã¯ãã¼ã¸ã§ã³ãã¤ã³ã¯ãªã¡ã³ããããããã«ãã¾ãã
GitHub Actionsä¸ã§release-it npmãå®è¡ãã¦ãªãªã¼ã¹ããã
release-it npmã¯ãããªã«ã»ãã³ãã£ãã¯ãã¼ã¸ã§ã³ãã¤ã³ã¯ãªã¡ã³ãããªãããªãªã¼ã¹ãã¼ããä½ã£ã¦GitHubãªãªã¼ã¹ãä½æãã¦ãããã³ãã³ãã§ãã
ãã¨ãã°ãç¾æç¹ã®ãã¼ã¸ã§ã³ã0.1.2
ã ã£ãã¨ãã次ã®ããã«å®è¡ããã¨ãã¤ãã¼ãã¼ã¸ã§ã³ãã¤ã³ã¯ãªã¡ã³ããã0.2.0
ãã¼ã¸ã§ã³ã®ãªãªã¼ã¹ãä½æãã¦ããã¾ãã
$ npm run release -- minor --ci
次ã®ãªã³ã¯ã¯release-it npmã§ä½æããããªãªã¼ã¹ãã¼ãã§ãã
GitHub Actionsä¸ã§Node.jsç°å¢ãç¨æãã¦å®è¡ããã ãã§çµãããã¨æããããããããè¨å®ããå¿ è¦ããã£ãã®ã§ããã¤ã³ãã解説ãã¦ããã¾ãã
GitHub Actionså®è¡æã«ã¿ã°ãåå¾ãã¦ãã
Set fetch-depth: 0 to fetch all history for all branches and tags.
ä»åæ§ç¯ããèªåãªãªã¼ã¹ã®ã¯ã¼ã¯ããã¼ã§ã¯æ¢åã®ã¿ã°ãããªãªã¼ã¹ããã»ãã³ãã£ãã¯ãã¼ã¸ã§ã³ã決å®ãã¾ãã
ãã®ãããGitHub Actionså®è¡æã«ã¿ã°ãä¸ç·ã«ãã§ãã¯ã¢ã¦ããã¦ããå¿
è¦ãããã¾ããã¿ã°ã¯GitHub Actionsãå©ç¨æã«ã»ã¼100%use
ããã¦ããã§ãããactions/checkout
ã«å¯¾ãã¦fetch-depth: 0
ãªãã·ã§ã³ã渡ãã ãã§åå¾å¯è½ã§ãã
- name: Checkout codes uses: actions/checkout@v2 with: fetch-depth: 0
ç¹å®ã®ãã¹é ä¸ãæ´æ°ãããã¨ãã®ã¿ãªãªã¼ã¹ãã
ä»åèªåãªãªã¼ã¹ããããªãã¸ããªã¯ã³ã¼ãã®èªåçæãè¡ãªã£ã¦ãã¾ããããã®ããã次ã®ãããªäºæ ãããã¾ããã
- PRããã¼ã¸ããããã³ã®ãªãªã¼ã¹ã¯ ï¼ã©ãã©ããã¼ã¸ã§ã³ãä¸ãã£ã¦ãã¾ãã®ã§ï¼ãã¦ã»ãããªã
- èªåçæããã³ã¼ããé
ç½®ããã¦ãã
gen/
ãã£ã¬ã¯ããªã®å 容ãå¤æ´ãããã¨ãã ããªãªã¼ã¹ããã
OpenAPIãgRPCãªã©ãå©ç¨ãã¦åãªãã¸ããªå ã§ã¯ã©ã¤ã¢ã³ãã³ã¼ããèªåçæããããã¦ããã¨ãåæ§ã®ãã¼ãºãçã¾ããã¨æãã¾ãã
æåã¯CircleCIãå©ç¨ãã¦èªåãªãªã¼ã¹ãå®ç¾ãããã¨æã£ãã®ã§ããããã¹ã使ã£ã¦CIãå¶å¾¡ããã®ã¯GitHub Actionsã®ã»ããç°¡åã ã£ãã®ã§ãGitHub Actionsã§èªåãªãªã¼ã¹ä½æ¥ãè¡ãªããã¨ã«ãã¾ããã
GitHub Actionsã®ã¯ã¼ã¯ããã¼ã§ã¯æ¬¡ã®ãããªå¶å¾¡ããããã¨ãã§ãã¾ãã
ã³ãããå 容ã確èªãã¦ç¹å®ãã£ã¬ã¯ããªã«æ´æ°ããã£ãã確èªãã
GitHub Actionsã§ã¯ãon.<push|pull_request>.paths
ã使ããã¨ã§ãç¹å®ãã£ã¬ã¯ããªã«æ´æ°ããã£ãã¨ãã ãã«ã¸ã§ãã®å®è¡ãå¶éã§ãã¾ã 1 ã
次ã®ãµã³ãã«ã³ã¼ãã¯ä»¥ä¸ã®2ã¤ã®æ¡ä»¶ãæºãããã¨ãã®ã¿å®è¡ãããè¨å®ã§ãã
- mainãã©ã³ãã«ã³ããããããã·ã¥ããã
- ããã·ã¥ãããã³ãããã®ä¸ã«
gen/
ãã£ã¬ã¯ããªå ã®æ´æ°ãå«ã¾ãã¦ãã
on: push: branches: - main paths: - gen/**
ã¯ã¼ã¯ããã¼ã®å¶å¾¡ã«ã³ãããã¡ãã»ã¼ã¸ãå©ç¨ãã
ãã®ãã¼ã¿æ§é ã¯ããããå
¬å¼ããã¥ã¡ã³ãã«æ示çã«è¼ã£ã¦ããªãã®ã§ãããGitHub Actionsã§ãã©ã³ãã«pushãããä¸é£ã®ã³ãããã®æ
å ±ãã¸ã§ãå®è¡ä¸ã«å©ç¨å¯è½ã§ãã
ã¯ã¼ã¯ããã¼å®è¡æã®æ
å ±ã¯github context
ã¨ãã¦åç
§ã§ããã®ã§ããããã®ä¸ã®github.event
ã§pushãããã³ãããã®æ
å ±ãæã£ã¦ãã¾ã2ã
ãã®æ
å ±ããã¼ã¹ããã¨ã³ãããã®å
容ãã¯ã¼ã¯ããã¼ä¸ã«ä½¿ããã¨ãã§ãã¾ãã
次ã®ã³ã¼ãã¯ãã³ãããã®ã¡ãã»ã¼ã¸ã«'bump up version major'
ããã£ããtrue
ã«ãªããå¼ã§ãã
contains(toJSON(github.event.commits.*.message), 'bump up version major')
ããã¨ãjobs.<job_id>.steps.if
ãã使ããã¨ã§ããã³ãããã¡ãã»ã¼ã¸ã«ãã£ã¦å®è¡ãããstepããã¯ã¼ã¯ããã¼ã«ç¨æãããã¨ãã§ãã¾ãã
jobs: sample: runs-on: ubuntu-latest steps: - name: teststep if: contains(toJSON(github.event.commits.*.message), 'ã³ãããã¡ãã»ã¼ã¸ã確èª') run: echo 'executed!!'
ã¾ããcontextã®steps.<step id>.conclusion
ãç¨ãããã¨ã§åã¹ãããã®å®è¡çµæãå©ç¨ã㦠else if
ã®ãããªå¶å¾¡ãè¡ãªããã¨ãå¯è½ã§ãã
jobs: ifelse-pattern: steps: - name: foo id: foo if: contains(toJSON(github.event.commits.*.message), 'foo') run: echo 'if step!' - name: bar id: bar # fooã¹ããããã¹ãããããã && ã³ãããã¡ãã»ã¼ã¸ã«barãå«ãå ´åã«å®è¡ãã if: steps.foo.conclusion == 'skipped' && contains(toJSON(github.event.commits.*.message), 'bar') run: echo 'elseif step!'
次ã®ãªã³ã¯ã¯å®éã«ã¹ããããããã¤ãã¹ããããã¦ããActionsã®å®è¡çµæã§ãã
ããã¾ã§ã¯GitHub Actionsã®è¨å®æ¹æ³ã§ãããã次ã¯release-it npmãGitHub Actionsä¸ã§ä½¿ãã³ãã§ãã
ã¿ã°ã®è¨å®ã¨ãªãªã¼ã¹ã¯ããããã³ãããã¯ããªã
release-it npmã¯GitHub Actionsä¸ã§npx
ã³ãã³ãã§å®è¡ãã¦ããã®ã§package.json
ã¯ä¸è¦ã§ãã
ããrelease-it npmç¨ã®è¨å®ãç¨æããå¿
è¦ãããã¾ãã
ä»åå©ç¨ãã¦ããè¨å®ã¯æ¬¡ã®ã¨ããã§ãã
{ "requireUpstream": false, "requireCleanWorkingDir": false, "github": { "release": true }, "git": { "commit": false, "push": false, "requireUpstream": false, "requireCleanWorkingDir": false }, "npm": { "publish": false, "ignoreVersion": true } }
ãã£ãã説æããã¨ã次ã®ãããªè¨å®ã§ãã
- GitHubãªãªã¼ã¹ãä½æãã
- gitã®ã³ãããã¯ä½æããªã
- gitã®pushã¯ããªã
- npmã®å ¬éã¯ããªã
- ãã¼ã¸ã§ã³ã決å®ããããã«
package.json
å ã®ãã¼ã¸ã§ã³ãåç §ããªã
éãæ¹ã¯ãâpushããªãâã£ã¦ãã¨ã¯ã¿ã°ãå ¬éãããªãããããªãã®ï¼ãã¨æãããããã¾ããããããã®ãæªãã®ãããªãªã¼ã¹ãè¡ãªãã¨ãã«ã¿ã°ã¯ããã·ã¥ãããããã§ãã
Actionsãããããã¯ããã©ã³ãã«ã¯ã³ããããpushã§ããªã
ããã¾ã§ä¾¿å©ãªGitHub Actionsã§ããããã²ã¨ã¤å¶ç´ãããã¾ããããã¯ãããã¯ããã©ã³ãã«ã³ããããããã·ã¥ãããã¨ãã§ããªãç¹ã§ããæãéããªããæ¢ãã¦ããã®ã§ãããªããããªã®ã§è«¦ãã¾ããã
ãªã®ã§ãå
ã»ã©ã®release-it npmç¨ã®è¨å®ãã¡ã¤ã«ã¯ãã¿ã°ã®è¨å®ã¨ãªãªã¼ã¹ã¯ãããã©ã³ãããã¯ããã·ã¥ããªããã¨ããå
容ã«ãªãã¾ãã
ãèªåãªãªã¼ã¹ããã¨ãã¯package.json
ã®ä¸ã«ããversion
ãæ´æ°ãããï¼ã³ãããããã·ã¥ãããï¼ãã ãã©ï¼ãã¨ãããããªãã¼ãºããã¡ããããã¨æãã¾ãã
ããããä»åã®ã¦ã¼ã¹ã±ã¼ã¹ã§ã¯ãªãªã¼ã¹ã¿ã°ã§ãã¼ã¸ã§ã³ã管çããã¦ããã°ãã¡ã¤ã«ã¨ãã¦ãã¼ã¸ã§ã³ãåç
§ã§ããå¿
è¦ã¯ãªãã£ãã®ã§ããã¡ãã妥åãã¾ããã
ãã¨ã¯éçºããã ãï¼
以ä¸ã®è¨å®ãè¡ãã¨ãç¹å®æ¡ä»¶ã®ã³ããããä½ãã ãã§èªåã§ãªãªã¼ã¹ãããããã«ãªãã¾ãã
ããããã®è¨å®ã¯ç¬ç«ãã¦ããã®ã§ãã好ã¿ã§ã«ã¹ã¿ãã¤ãºãã¦ããã ãã°ã¨æãã¾ãã
- ç¹å®ã®ãã£ã¬ã¯ããªã«éå®ããå¿
è¦ã¯ãªãã®ã§
on.<push|pull_request>.paths
ã®è¨å®ã¯åé¤ãã - ãããããã³ãããã¡ãã»ã¼ã¸ãå¤æ´ãã etc...
name: auto release demo on: push: # mainãã©ã³ãã«ã³ããããpushãããã¨ãã«éå® branches: - main # ä¸è¨æ¡ä»¶ã«å ãã¦genãã£ã¬ã¯ããªé ä¸ãå¤æ´ãããã¨ãã®ã¿ã¨ããæ¡ä»¶ã追å paths: - gen/** jobs: auto-release: runs-on: ubuntu-latest env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} RELEASE_IT_VERSION: 14.2.1 steps: - name: Check out codes uses: actions/checkout@v2 with: fetch-depth: 0 - name: Setup Node uses: actions/setup-node@v1 with: node-version: '12' - name: Set releaser settings run: | git config --global user.name release-machine git config --global user.email [email protected] - name: Major release id: major if: contains(toJSON(github.event.commits.*.message), 'bump up version major') run: npx release-it@${RELEASE_IT_VERSION} -- major --ci - name: Minor release id: minor # ã¡ã¸ã£ã¼ãã¼ã¸ã§ã³ã¢ããããã¦ããªãã¨ããã¤ãã¼ãã¼ã¸ã§ã³ã¢ãããè¡ãªãã if: steps.major.conclusion == 'skipped' && contains(toJSON(github.event.commits.*.message), 'bump up version minor') run: npx release-it@${RELEASE_IT_VERSION} -- minor --ci - name: Patch release # ã³ãããã¡ãã»ã¼ã¸ã«ç¹ã«æå®ããªãå ´åã¯ãã¤ãã¼ãã¼ã¸ã§ã³ãæ´æ°ãã if: "!(steps.major.conclusion == 'success' || steps.minor.conclusion == 'success')" run: npx release-it@${RELEASE_IT_VERSION} -- patch --ci
çµããã«
ãPRãã¼ã¸ãããã¼ï¼ãã¨æã£ã¦ãããã®ãã¨ã«ãããããªãªã¼ã¹ä½æ¥ãããã®ã¯åå«ã§ããã
ããã§å°ãã§ãçç£æ§ããããã¨ãããªã¨æã£ã¦ãã¾ãã
ãªããGitHub Actionsãããããã¯ããã©ã³ãã¸ã®ç´æ¥ã³ãããããã·ã¥ã¯ã§ããªãã®ã§ãããrenovateã¯PRãä½æãAppã§èªåæ¿èªãèªåãã¼ã¸ã¨ããè¿åããã¦ãããã¯ããã©ã³ãã¸ã®ããã·ã¥ãå®ç¾ãã¦ããããã§ãã
GitHub Apps - renovate-approve · GitHub
ãã£ã¨çªãè©°ããããªã£ããåæ§ã®æä½ãå®è£ ãã¦ãã¡ã¤ã«æ´æ°ãå«ããèªåãªãªã¼ã¹ãå®ç¾ããããªã¨æãã¾ãã
æå¾ã«ãBASE BANKã§ã¯æ°ãããã¶ã¤ãã¼ã¨ã«ã¹ã¿ãã¼ãµã¯ã»ã¹ã®åéãéå§ããã®ã§ããã²ãå¿åãå¾ ã¡ãã¦ãã¾ãã
åèãªã³ã¯
- https://github.com/budougumi0617/autorelease-by-release-it-on-actions
- https://www.npmjs.com/package/release-it
- https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions
- https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions
- https://github.community/t/how-to-push-to-protected-branches-in-a-github-action/16101/5
-
ãç¹å®ã®ãã£ã¬ã¯ããªã«æ´æ°ããã£ãã¨ãã¯ç¡è¦ãããã¨ããéå¶å¾¡ãã§ãã¾ãã↩