Browse Source

add: send email

Yaavi 1 year ago
parent
commit
2e277f0b30

+ 2 - 1
.github/workflows/deploy-docs.yml

@@ -6,7 +6,8 @@ name: Deploy GitHub Pages
 on:
 on:
   # Triggers the workflow on push or pull request events but only for the "main" branch
   # Triggers the workflow on push or pull request events but only for the "main" branch
   push:
   push:
-    branches: main
+    tags:
+      - "docs*"
 
 
 # A workflow run is made up of one or more jobs that can run sequentially or in parallel
 # A workflow run is made up of one or more jobs that can run sequentially or in parallel
 jobs:
 jobs:

+ 42 - 0
.github/workflows/send-email.yml

@@ -0,0 +1,42 @@
+name: Notify on Result
+
+on:
+  push:
+    branches:
+      - main  # 或者你想要的其他分支
+
+jobs:
+  notify:
+    runs-on: ubuntu-latest
+
+    steps:
+    - name: Checkout code
+      uses: actions/checkout@v4
+
+    - name: Setup Node.js
+      uses: actions/setup-node@v4
+      with:
+        node-version: "20"
+        registry-url: "https://registry.npmjs.org"
+
+    - name: Install dependencies
+      run: npm install
+
+    - name: Run script
+      id: run-script
+      run: npm run fetch 2024  # 假设你的脚本文件名为 your-script.js,且需要传入一个年份参数
+
+    - name: Send notification if holidays has value
+      if: ${{ steps.run-script.outputs.holidays != '' }}
+      uses: dawidd6/action-send-mail@v3
+      with:
+        server_address: smtp.gmail.com
+        server_port: 587
+        username: ${{ secrets.EMAIL_USERNAME }}
+        password: ${{ secrets.EMAIL_PASSWORD }}
+        subject: "2024 Holidays Result has value - GitHub Actions"
+        to: hi@yaavi.me
+        from: ${{ secrets.EMAIL_USERNAME }}
+        body: |
+          Result has value:
+          $(cat holidays.txt)

+ 14 - 1
scripts/fetch.ts

@@ -1,3 +1,5 @@
+import fs from "fs";
+import path from 'path';
 import axios from "axios";
 import axios from "axios";
 import cheerio from "cheerio";
 import cheerio from "cheerio";
 import { ArgumentParser } from "argparse";
 import { ArgumentParser } from "argparse";
@@ -100,7 +102,18 @@ const main = async () => {
   console.log(`Fetching holiday for ${year}...`);
   console.log(`Fetching holiday for ${year}...`);
 
 
   const result = await fetchHoliday(year);
   const result = await fetchHoliday(year);
-  console.log(result, result.length);
+
+  if (result && result.length > 0) {
+    console.log(result)
+    const outputPath = process.env.GITHUB_OUTPUT;
+    const holidaysFile = path.join(__dirname, 'holidays.txt');
+    fs.writeFileSync(holidaysFile, result);
+    if (outputPath) {
+      fs.appendFileSync(outputPath, `holidays=${holidaysFile}\n`);
+    }
+  } else {
+    console.log('No holidays found.');
+  }
 };
 };
 
 
 main().catch((error) => {
 main().catch((error) => {

+ 0 - 37
src/holidays/constants/2024.ts

@@ -1,37 +0,0 @@
-/**
- * 国务院办公厅关于2024年
- * 部分节假日安排的通知
- * 国办发明电〔2023〕7号
- *
- * 各省、自治区、直辖市人民政府,国务院各部委、各直属机构:
- * 经国务院批准,现将2024年元旦、春节、清明节、劳动节、端午节、中秋节和国庆节放假调休日期的具体安排通知如下。
- * 一、元旦:1月1日放假,与周末连休。
- * 二、春节:2月10日至17日放假调休,共8天。2月4日(星期日)、2月18日(星期日)上班。鼓励各单位结合带薪年休假等制度落实,安排职工在除夕(2月9日)休息。
- * 三、清明节:4月4日至6日放假调休,共3天。4月7日(星期日)上班。
- * 四、劳动节:5月1日至5日放假调休,共5天。4月28日(星期日)、5月11日(星期六)上班。
- * 五、端午节:6月10日放假,与周末连休。
- * 六、中秋节:9月15日至17日放假调休,共3天。9月14日(星期六)上班。
- * 七、国庆节:10月1日至7日放假调休,共7天。9月29日(星期日)、10月12日(星期六)上班。
- * 节假日期间,各地区、各部门要妥善安排好值班和安全、保卫、疫情防控等工作,遇有重大突发事件,要按规定及时报告并妥善处置,确保人民群众祥和平安度过节日假期。
- * 国务院办公厅
- * 2023年10月25日
- */
-import Arrangement from "../arrangement.ts"
-
-export default () => {
-  const arrangement = new Arrangement()
-  arrangement.y(2024)
-    .ny().r(1, 1)
-    .s().r(2, 10).to(2, 17).w(2, 4).w(2, 18).i(2, 15).to(2, 16)
-    .t().r(4, 4).to(4, 6).w(4, 7).i(4, 5)
-    .l().r(5, 1).to(5, 5).w(4, 28).w(5, 11).i(5, 2).to(5, 3)
-    .d().r(6, 10)
-    .m().r(9, 15).to(9, 17).w(9, 14).i(9, 16)
-    .n().r(10, 1).to(10, 7).w(9, 29).w(10, 12).i(10, 4).i(10, 7)
-
-  return {
-    holidays: arrangement.holidays,
-    workdays: arrangement.workdays,
-    inLieuDays: arrangement.inLieuDays,
-  }
-}