Skip to content

Commit

Permalink
fix: cron中变量的默认值
Browse files Browse the repository at this point in the history
  • Loading branch information
14790897 committed Aug 16, 2024
1 parent 09fd9bd commit 9d0302a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 63 deletions.
63 changes: 52 additions & 11 deletions .github/workflows/cron_bypassCF.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: read cron (use this)
name: bypassCF cron (use this)

on:
schedule:
# 每天 UTC 时间 18:00 运行
- cron: "0 18 * * *"
workflow_dispatch: # 添加这行以允许手动触发
workflow_dispatch: # 允许手动触发

jobs:
build:
Expand All @@ -13,22 +13,63 @@ jobs:

strategy:
matrix:
node-version: [20.x] # 选择你需要的 Node.js 版本
env:
# 在作业级别设置环境变量
USERNAMES: ${{ secrets.USERNAMES }}
PASSWORDS: ${{ secrets.PASSWORDS }}
WEBSITE: ${{secrets.WEBSITE}}
node-version: [20.x]

steps:
- uses: actions/checkout@v3 # 检出你的仓库
- uses: actions/checkout@v3 # 检出仓库

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: |
npm install
sudo apt install -y xvfb
- name: Run auto read
run: node bypasscf.js # 替换为你想运行的脚本的实际名称
- name: Load environment variables
run: |
echo "Debug: Checking if .env file exists..."
# 检查 .env 文件是否存在
if [ -f .env ]; then
echo ".env file found. Loading environment variables from .env file"
# 加载 .env 文件中的默认值
set -a
source .env
set +a
echo "Loaded .env variables:"
cat .env
else
echo ".env file not found. Skipping loading."
fi
# 如果 GitHub Secrets 中设置了环境变量,则覆盖默认值
if [ -n "${{ secrets.USERNAMES }}" ] && [ ! -z "${{ secrets.USERNAMES }}" ]; then
echo "Using GitHub Secret for USERNAMES"
echo "USERNAMES=${{ secrets.USERNAMES }}" >> $GITHUB_ENV
else
echo "USERNAMES=${USERNAMES}" >> $GITHUB_ENV
fi
if [ -n "${{ secrets.PASSWORDS }}" ] && [ ! -z "${{ secrets.PASSWORDS }}" ]; then
echo "Using GitHub Secret for PASSWORDS"
echo "PASSWORDS=\"${{ secrets.PASSWORDS }}\"" >> $GITHUB_ENV
else
echo "PASSWORDS=\"${PASSWORDS}\"" >> $GITHUB_ENV
fi
if [ -n "${{ secrets.WEBSITE }}" ] && [ ! -z "${{ secrets.WEBSITE }}" ]; then
echo "Using GitHub Secret for WEBSITE"
echo "WEBSITE=${{ secrets.WEBSITE }}" >> $GITHUB_ENV
else
echo "WEBSITE=${WEBSITE}" >> $GITHUB_ENV
fi
shell: bash

- name: Run a script
run: xvfb-run node bypasscf.js
63 changes: 11 additions & 52 deletions .github/workflows/cron_read.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: bypassCF cron old(don't use)
name: read cron (don't use)

on:
schedule:
# 每天 UTC 时间 18:00 运行
- cron: "0 18 * * *"
workflow_dispatch: # 允许手动触发
workflow_dispatch: # 添加这行以允许手动触发

jobs:
build:
Expand All @@ -13,63 +13,22 @@ jobs:

strategy:
matrix:
node-version: [20.x]
node-version: [20.x] # 选择你需要的 Node.js 版本
env:
# 在作业级别设置环境变量
USERNAMES: ${{ secrets.USERNAMES }}
PASSWORDS: ${{ secrets.PASSWORDS }}
WEBSITE: ${{secrets.WEBSITE}}

steps:
- uses: actions/checkout@v3 # 检出仓库

- uses: actions/checkout@v3 # 检出你的仓库
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: |
npm install
sudo apt install -y xvfb
- name: Load environment variables
run: |
echo "Debug: Checking if .env file exists..."
# 检查 .env 文件是否存在
if [ -f .env ]; then
echo ".env file found. Loading environment variables from .env file"
# 加载 .env 文件中的默认值
set -a
source .env
set +a
echo "Loaded .env variables:"
cat .env
else
echo ".env file not found. Skipping loading."
fi
# 如果 GitHub Secrets 中设置了环境变量,则覆盖默认值
if [ -n "${{ secrets.USERNAMES }}" ] && [ ! -z "${{ secrets.USERNAMES }}" ]; then
echo "Using GitHub Secret for USERNAMES"
echo "USERNAMES=${{ secrets.USERNAMES }}" >> $GITHUB_ENV
else
echo "USERNAMES=${USERNAMES}" >> $GITHUB_ENV
fi
if [ -n "${{ secrets.PASSWORDS }}" ] && [ ! -z "${{ secrets.PASSWORDS }}" ]; then
echo "Using GitHub Secret for PASSWORDS"
echo "PASSWORDS=${{ secrets.PASSWORDS }}" >> $GITHUB_ENV
else
echo "PASSWORDS=${PASSWORDS}" >> $GITHUB_ENV
fi
if [ -n "${{ secrets.WEBSITE }}" ] && [ ! -z "${{ secrets.WEBSITE }}" ]; then
echo "Using GitHub Secret for WEBSITE"
echo "WEBSITE=${{ secrets.WEBSITE }}" >> $GITHUB_ENV
else
echo "WEBSITE=${WEBSITE}" >> $GITHUB_ENV
fi
shell: bash

- name: Run a script
run: xvfb-run node bypasscf.js
- name: Run auto read
run: node bypasscf.js # 替换为你想运行的脚本的实际名称

0 comments on commit 9d0302a

Please sign in to comment.