Skip to content

Commit

Permalink
ci: update action
Browse files Browse the repository at this point in the history
  • Loading branch information
Ray93 committed Oct 16, 2024
1 parent 32682a7 commit 76f7862
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions .github/workflows/answer.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# .github/workflows/answer.yml
name: Daily Answer Script

on:
Expand All @@ -15,40 +14,52 @@ on:
date:
description: "日期"
required: false

env:
ACCOUNT: ${{ github.event.inputs.account || secrets.ACCOUNT }}
PASSWORD: ${{ github.event.inputs.password || secrets.PASSWORD }}
KEY: ${{ secrets.KEY }}
IV: ${{ secrets.IV }}
DATE: ${{ github.event.inputs.date }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}

jobs:
run-script:
runs-on: ubuntu-latest

env:
ACCOUNT: ${{ github.event.inputs.account || secrets.ACCOUNT }}
PASSWORD: ${{ github.event.inputs.password || secrets.PASSWORD }}
KEY: ${{ secrets.KEY }}
IV: ${{ secrets.IV }}
DATE: ${{ github.event.inputs.date }}

steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Cache Bun environment
id: cache-bun
uses: actions/cache@v3
with:
path: ~/.bun
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lockb') }}
restore-keys: |
${{ runner.os }}-bun-
- name: Setup Bun
if: steps.cache-bun.outputs.cache-hit != 'true'
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Install dependencies
run: bun install
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/bun.lockb') }}
restore-keys: |
${{ runner.os }}-node-modules-
- name: Run Answer Script
run: bun run index.ts
continue-on-error: true
- name: Install dependencies if needed
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: bun install

- name: Read output from file
- name: Run Answer Script and Send Telegram Message
run: |
bun run index.ts || true
output=$(cat output.txt)
echo "script_output=$output" >> $GITHUB_ENV
- name: Send message to Telegram
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
run: curl -s -X POST https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage -d chat_id=${TELEGRAM_CHAT_ID} -d text="${{ env.script_output }}"
curl -s -X POST https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage -d chat_id=${TELEGRAM_CHAT_ID} -d text="$output"

0 comments on commit 76f7862

Please sign in to comment.