-
Notifications
You must be signed in to change notification settings - Fork 0
/
costchecker-agent.yml
74 lines (61 loc) · 2.48 KB
/
costchecker-agent.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
name: costchecker-agent
on:
workflow_dispatch:
schedule:
# 毎週月曜
- cron: '0 0 * * 1'
jobs:
run_and_report:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Login to GHCR
env:
GHCR_PAT: ${{ secrets.GHCR_PAT }}
run: |
if [ ! -z "$GHCR_PAT" ]; then
echo "$GHCR_PAT" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
fi
- name: Pull Docker Image
run: docker pull ghcr.io/3-shake/costchecker-agent/costchecker-agent:latest
- name: Run Docker Image
continue-on-error: true
run: |
docker run --env GCP_SA_JSON_KEY='${{ secrets.GCP_SA_JSON_KEY }}' \
--env GCP_PROJECT_NAME="${{ secrets.GCP_PROJECT_NAME }}" \
--env GCP_TABLE_NAME="${{ secrets.GCP_TABLE_NAME }}" \
--env GCP_DATASET="${{ secrets.GCP_DATASET }}" \
--env OPENAI_API_KEY="${{ secrets.OPENAI_API_KEY }}" \
--env OPENAI_ORGANIZATION_ID="${{ secrets.OPENAI_ORGANIZATION_ID }}" \
--env LANGUAGE="${{ secrets.LANGUAGE }}" \
--env LLM_MODEL="${{ secrets.LLM_MODEL }}" \
ghcr.io/3-shake/costchecker-agent/costchecker-agent:latest > output.txt 2>error.txt
- name: Create issue
run: |
REPO_OWNER=$(echo ${{ github.repository }} | cut -d'/' -f1)
REPO_NAME=$(echo ${{ github.repository }} | cut -d'/' -f2)
API_URL="https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/issues"
if [[ ! -s error.txt ]]; then
ISSUE_TITLE="Weekly Report for Week $(date +'%U') of $(date +'%B %Y')"
ISSUE_BODY=$(<output.txt)
else
ISSUE_TITLE="ERROR: $(sed '2!d' error.txt)"
ISSUE_BODY=$(<error.txt)
fi
ISSUE_DATA=$(jq -n \
--arg title "$ISSUE_TITLE" \
--arg body "$ISSUE_BODY" \
'{title: $title, body: $body}')
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
$API_URL \
-d "$ISSUE_DATA"
- name: Check for Errors
run: |
if [[ -s error.txt ]]; then
echo "Error detected in costchecker-agent."
cat error.txt
exit 1
fi