GitHub workflows env All In One
$GITHUB_ENV
docs
GITHUB_ENV
environment file
# 把变量和值 `>>` 追加到 GITHUB_ENV 环境变量文件中
echo "{environment_variable_name}={value}" >> "$GITHUB_ENV"
steps:
- name: Set the value
id: step_one
run: |
echo "action_state=yellow" >> "$GITHUB_ENV"
- name: Use the value
id: step_two
run: |
printf '%s\n' "$action_state" # This will output 'yellow'
env
vs github.env
# ✅
${{ env.VARIABLE_NAME }}
# ✅ namespcae ❓
${{github.env.VARIABLE_NAME}}}
https://docs.github.com/en/actions/learn-github-actions/contexts#env-context
demos
# This is a basic workflow to help you get started with Actions
name: Tesla_Crawler
# Controls when the action will run.
on:
# Triggers the workflow on push events but only for the main branch
push:
branches: [ main ]
schedule:
- cron: '00 08 * * *'
# https://crontab.guru/#00_08_*_*_*
# Runs at 08:00 on everyday
# 分、时、日、月、周
# https://www.cnblogs.com/xgqfrms/p/15384401.html
# - cron: '00 08,20 * * *'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
# hello-job:
# # The type of runner that the job will run on
# runs-on: ubuntu-latest
# # Steps represent a sequence of tasks that will be executed as part of the job
# steps:
# # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
# - uses: actions/checkout@v2
# # Runs a single command using the runners shell
# - name: Run a one-line script
# run: echo Hello, world!
# crawler job
tesla-job:
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
runs-on: ubuntu-latest
steps:
- name: 'Checkout codes'
uses: actions/checkout@v3
# 自定义 env, 并且 >> 追加到 GITHUB_ENV file 中 ✅
# https://www.cnblogs.com/xgqfrms/p/17685587.html
# 自定义 env, $GITHUB_ENV => ${{env.REPORT_DATE}} ✅
# 自定义 env, $GITHUB_ENV => ${{github.env.REPORT_DATE}} ✅
- name: 'set Date'
run: echo "REPORT_DATE=$(TZ=':Asia/Shanghai' date '+%Y-%m-%d %T')" >> $GITHUB_ENV
- name: 'print Date'
run: echo ${{env.REPORT_DATE}}
# vscode warning: Context access might be invalid: REPORT_DATE
# https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
- name: 'Get Date'
run: echo ${{github.env.REPORT_DATE}}
# vscode not warning
- name: 'install package'
run: npm i
- name: 'begin'
run: echo "crawling ...✅"
- name: '自动爬取'
run: node ./auto-update.js
- name: 'end'
run: echo "finshed
标签:GitHub,run,env,github,GITHUB,ENV,workflows,name
From: https://www.cnblogs.com/xgqfrms/p/17685587.html