Typescript에서 수행한 내용을 Github Actions에 전달하여 사용
6758 단어 GitHubActionsTypeScript
TL;DR
예
매일 아침 10시에 aws의 비용을 취득하고, aws의 비용은 달러이므로, 원에 고쳐서 slack에 통지
※세세한 취득 방법은 테마가 아니기 때문에 생략하고 있습니다
get-aws-cost.tsconst awsCost = 100; // ドル
const rate = 106.1 // ドル円
const awsJpyBill = awsCost * JPY
※ awsCost 나 rate 는 aws-sdk의 CostExplorer 등으로 취득해 주세요
위의 계산 (거의 거의 없지만)을 Github Actions에서 사용하려면 @actions/core
를 사용하여 전달합니다.
방법
@actions/core
사용
절차
const awsCost = 100; // ドル
const rate = 106.1 // ドル円
const awsJpyBill = awsCost * JPY
@actions/core
사용절차
@actions/core를 package.json에 추가
npm i @actions/core -D
코드 내에서 전달
get-aws-cost.tsimport { setOutput } from '@actions/core'; // 追加
const awsCost = 100; // ドル
const rate = 106.1 // ドル円
const awsJpyBill = awsCost * JPY
setOutput("awsCost", awsCost) // 追加
setOutput("rate", rate) // 追加
setOutput("awsJpyBill", awsJpyBill) // 追加
Github Actions에서 사용
create-aws-bill.ymlname: Create AWS Bill
on:
schedule:
- cron: '0 1 * * *' # 毎日 am10時
workflow_dispatch:
branches: [master] # Githubの画面から手動でも実行できるように
env:
SLACK_ICON: https://raw.githubusercontent.com/quintessence/slack-icons/master/images/octocat-spock-slack-icon.png
jobs:
notify-aws-cost:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '14'
- name: Install Dependency
run: npm ci
- name: Get AWS Cost
id: get-bill
run: npx ts-node get-aws-cost.ts
- name: Slack notification
uses: rtCamp/action-slack-notify@master
env:
SLACK_ICON: ${{ env.SLACK_ICON }}
SLACK_MESSAGE: AWSのコストは ${{ steps.get-bill.outputs.awsCost }}ドル で ${{ steps.get-bill.outputs.awsJpyBill }} レートは(${{steps.get-bill.outputs.rate}})円
포인트
import { setOutput } from '@actions/core'; // 追加
const awsCost = 100; // ドル
const rate = 106.1 // ドル円
const awsJpyBill = awsCost * JPY
setOutput("awsCost", awsCost) // 追加
setOutput("rate", rate) // 追加
setOutput("awsJpyBill", awsJpyBill) // 追加
create-aws-bill.yml
name: Create AWS Bill
on:
schedule:
- cron: '0 1 * * *' # 毎日 am10時
workflow_dispatch:
branches: [master] # Githubの画面から手動でも実行できるように
env:
SLACK_ICON: https://raw.githubusercontent.com/quintessence/slack-icons/master/images/octocat-spock-slack-icon.png
jobs:
notify-aws-cost:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '14'
- name: Install Dependency
run: npm ci
- name: Get AWS Cost
id: get-bill
run: npx ts-node get-aws-cost.ts
- name: Slack notification
uses: rtCamp/action-slack-notify@master
env:
SLACK_ICON: ${{ env.SLACK_ICON }}
SLACK_MESSAGE: AWSのコストは ${{ steps.get-bill.outputs.awsCost }}ドル で ${{ steps.get-bill.outputs.awsJpyBill }} レートは(${{steps.get-bill.outputs.rate}})円
포인트
${{ steps.<steps_id>.outputs.<setOutputで設定した名称>}}
에서 ts에서 설정 한 값을 사용할 수 있습니다 참조
Reference
이 문제에 관하여(Typescript에서 수행한 내용을 Github Actions에 전달하여 사용), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/k_bobchin/items/8d43218061c1adb5d86f텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)