GitHub Actionsã§workflowãçµãã§ããã¨ãå¤é¨ãã¼ã«ã¨çµåãããããã«ãJSONãçµã¿ç«ã¦ãªããã°ãªããªããã¨ããããActionã«ç´æ¥æ¸¡ãã ãã ã¨JSONã®åºãå¹ã¯ãã¾ããªãããå¤é¨ãµã¼ãã¹ã«ãªããããã¨ãã£ãæã«ã¯ããJSONãå¿ è¦ã«ãªããã¡ã
äºéã®è¦å´
å¾æ¥ã¯é å¼µã£ã¦JSON="{\"foo\": \"$BAR\"}"
ã¿ããã«ç´ æ´ã«æååãçµã¿ç«ã¦ã¦ããããã©ãããããããªããã訳ããªãã大æµ3åã¯å¤æ°ã®å±éã«å¤±æãããbashã§ã¯å¤æ°å±éãããããã°double quotationã§ãããå¿
è¦ãããããã©ãJSONã®ãªãã¸ã§ã¯ã表è¨ã«ããããã£ã¼ã«ãåãdouble quotationã§ãããå¿
è¦ãããã®ã§ããã¹ãå°çãçºçãããã¾ããããã渡ãã¨ãã大å¤ã§ããã¡ã¤ã«ã§æ¸¡ããããã°<(cat $JSON)
ã¨æ¸ãã¦file substitutionã使ãå¿
è¦ãããã
- äºéã®è¦å´
- çµã¿ç«ã¦ãã®ã«è¦å´
- å¤æ°å±éã大å¤
- double quotationããã¹ããã
- 渡ãã¨ãã«è¦å´
- ãã¡ã¤ã«ã§æ¸¡ãããã¨ãã©ããã
- ã¡ãªã¿ã«node.jsã¯file substitutionã«é対å¿ãªã®ã§ä¸æ¦ãã¡ã¤ã«ã«ç½®ãå¿ è¦ããã
- çµã¿ç«ã¦ãã®ã«è¦å´
ã¡ãªã¿ã«cat <<EOF > data.json
ãªã©ã®ããã«ãã¦ä¸æ¦ãã¡ã¤ã«ã«ç½®ãã¨node.jsã®ãããªfile substitutionã«é対å¿ã®ã³ãã³ããªã©ã§ã使ããããã©ããã£ããä¸æ¯ãªæãã«ãªã£ã¦ãã¾ãã
渡ãã¨ãã®è¦å´ã¯ãã¡ã¤ã«ã«ç½®ããã¨ã§(ãªããä¸æ¯ã ãã©)大æµã®å ´åã¯ãªãã¨ããªãã®ã§ããã§ç´å¾ãã¦ããã
actions/github-script
ã§çµã¿ç«ã¦ãç°¡åã«ãã
JSONãçµã¿ç«ã¦ãã¨ãã¯ãè²ã
試ããçµæãactions/github-script@v6
ã§ãªãã¸ã§ã¯ããçµã¿ç«ã¦ã¦ãJSON.stringify()
ãç¨ãã¦æååãã²ããããããããã®ã¹ãããã®outputã¨ãã¦åºåããã¨ä¾¿å©ã
ä¾ãã°ã次ã«ç¤ºãã®ã¯CIã®å®è¡æéãMackerelã«ãã¹ãããã¨ãã£ãä¾ã
- uses: actions/github-script@v6 id: create-body with: result-encoding: string // æååã§åãåãã script: | const time = Date.now() / 1000 // ${{}} ã«ããå¤æ°å±éãå¯è½ const start = ${{ needs.recordstarttime.outputs.ci_start_epoch }} const end = ${{ needs.recordendtime.outputs.ci_end_epoch }} const body = [ { name: 'ci.ciyaml.elapsed_sec.sec', time: time, value: end - start } ] return JSON.stringify(body) - name: Post Mackerel uses: yutailang0119/action-mackerel-api@v3 with: api-key: ${{ secrets.MACKEREL_API_KEY }} http-method: POST path: services/ãããããããã/tsdb body: ${{ steps.create-body.outputs.result }}
è¦è¡ãã解æ¾ãããã便å©ã