Skip to content

Auto Release for Last Month #7

Auto Release for Last Month

Auto Release for Last Month #7

Workflow file for this run

name: Auto Release for Last Month
on:
schedule:
- cron: '0 0 1 * *' # 每月 1 号运行
workflow_dispatch: # 允许手动触发 workflow
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Get current year and last month
id: date
run: |
# 获取当前年份和上个月份
current_month=$(date +'%m')
if [ "$current_month" == "01" ]; then
# 如果是1月,则上个月是去年12月
current_year=$(date +'%Y' --date="last year")
last_month="12"
else
# 其他月份直接使用当前年份和上个月份
current_year=$(date +'%Y')
last_month=$(date --date='1 month ago' +'%m')
fi
echo "current_year=${current_year}" >> $GITHUB_ENV
echo "last_month=${last_month}" >> $GITHUB_ENV
- name: Show current year and last month
run: |
echo "Current year: ${current_year}"
echo "Last month: ${last_month}"
- name: Create zip file
run: |
# 创建一个 zip 文件,包含当前年份和上个月份的文件夹内容
mkdir -p release
zip -r release/${current_year}-${last_month}.zip ${current_year}/${last_month}/
# 列出 release 目录,确保文件已生成
ls -lh release/
- name: Generate Git tag
id: tag
run: |
# 创建一个唯一的 Git tag,基于年份和月份
tag="${current_year}-${last_month}"
echo "Generated tag: $tag"
echo "TAG=${tag}" >> $GITHUB_ENV
- name: Upload Release Asset
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.TAG }}
files: release/${{ env.current_year }}-${{ env.last_month }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}