生成天气预报m3u文件 #2886
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 生成天气预报m3u文件 | |
on: | |
schedule: | |
- cron: "*/30 * * * *" # runs every 30 minutes | |
workflow_dispatch: # 添加手动触发选项 | |
jobs: | |
run-script: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
# - name: Install dependencies | |
# run: npm install | |
- name: Run Node.js script | |
run: | | |
node app.js > cctv_weather_forecasting.m3u | |
# - name: Upload output file | |
# uses: actions/upload-artifact@v4 | |
# with: | |
# name: cctv_weather_forecasting.m3u | |
# path: cctv_weather_forecasting.m3u | |
- name: Get latest release ID | |
id: get_latest_release | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const { data } = await github.rest.repos.getLatestRelease({ | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}); | |
core.setOutput('release_id', data.id); | |
- name: Check if asset exists | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
RELEASE_ID: ${{ steps.get_latest_release.outputs.release_id }} | |
run: | | |
ASSET_ID=$(curl -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github+json" \ | |
https://api.github.com/repos/${{ github.repository }}/releases/${{ env.RELEASE_ID }}/assets \ | |
| jq -r '.[] | select(.name=="cctv_weather_forecasting.m3u") | .id') | |
echo "ASSET_ID=$ASSET_ID" >> $GITHUB_ENV | |
if [ -n "$ASSET_ID" ]; then | |
curl -X DELETE \ | |
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github+json" \ | |
https://api.github.com/repos/${{ github.repository }}/releases/assets/$ASSET_ID | |
fi | |
- name: Upload output file to GitHub Release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
RELEASE_ID: ${{ steps.get_latest_release.outputs.release_id }} | |
run: | | |
curl -L -X POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer $GITHUB_TOKEN" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
-H "Content-Type: application/octet-stream" \ | |
--data-binary @cctv_weather_forecasting.m3u \ | |
"https://uploads.github.com/repos/${{ github.repository }}/releases/${{ env.RELEASE_ID }}/assets?name=cctv_weather_forecasting.m3u" |