xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

GitHub Actions In Action All In One

GitHub Actions In Action All In One

https://lab.github.com/githubtraining/github-actions:-hello-world

https://github.com/xgqfrms/hello-github-actions/issues/1

https://github.com/xgqfrms/hello-github-actions/issues/3

https://github.com/xgqfrms/webpack-plugin/actions/new

https://github.com/xgqfrms/webpack-plugin/new/master?filename=.github%2Fworkflows%2Fmain.yml&workflow_template=blank


# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

# 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"
  build:
    # 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!

    # Runs a set of commands using the runners shell
    - name: Run a multi-line script
      run: |
        echo Add other actions to build,
        echo test, and deploy your project.


https://github.com/xgqfrms/webpack-plugin/new/master?filename=.github%2Fworkflows%2Fnodejs.yml&workflow_template=nodejs

# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [10.x, 12.x]

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - run: npm ci
    - run: npm run build --if-present
    - run: npm test

https://github.com/xgqfrms/webpack-plugin/new/master?filename=.github%2Fworkflows%2Fnpmpublish.yml&workflow_template=npmpublish


# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: Node.js Package

on:
  release:
    types: [created]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 12
      - run: npm ci
      - run: npm test

  publish-npm:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 12
          registry-url: https://registry.npmjs.org/
      - run: npm ci
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.npm_token}}

  publish-gpr:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 12
          registry-url: https://npm.pkg.github.com/
      - run: npm ci
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}


https://github.com/xgqfrms/webpack-plugin/new/master?filename=.github%2Fworkflows%2Fgreetings.yml&workflow_template=greetings

name: Greetings

on: [pull_request, issues]

jobs:
  greeting:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/first-interaction@v1
      with:
        repo-token: ${{ secrets.GITHUB_TOKEN }}
        issue-message: 'Message that will be displayed on users'' first issue'
        pr-message: 'Message that will be displayed on users'' first pr'

https://github.com/xgqfrms/webpack-plugin/new/master?filename=.github%2Fworkflows%2Flabel.yml&workflow_template=label

# This workflow will triage pull requests and apply a label based on the
# paths that are modified in the pull request.
#
# To use this workflow, you will need to set up a .github/labeler.yml
# file with configuration.  For more information, see:
# https://github.com/actions/labeler/blob/master/README.md

name: Labeler
on: [pull_request]

jobs:
  label:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/labeler@v2
      with:
        repo-token: "${{ secrets.GITHUB_TOKEN }}"

https://github.com/xgqfrms/webpack-plugin/new/master?filename=.github%2Fworkflows%2Fstale.yml&workflow_template=stale

name: Mark stale issues and pull requests

on:
  schedule:
  - cron: "0 0 * * *"

jobs:
  stale:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/stale@v1
      with:
        repo-token: ${{ secrets.GITHUB_TOKEN }}
        stale-issue-message: 'Stale issue message'
        stale-pr-message: 'Stale pull request message'
        stale-issue-label: 'no-issue-activity'
        stale-pr-label: 'no-pr-activity'

demo

https://github.com/xgqfrms/webpack-plugin/runs/639001801?check_suite_focus=true

githib action

https://github.com/actions

https://github.com/actions/virtual-environments/

https://github.com/actions/typescript-action

https://github.com/actions/javascript-action

.github/workflows

  1. main.yml
name: A workflow for my Hello World file
on: push

jobs:
  build:
    name: Hello world action
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: ./action-a
        with:
          MY_NAME: "Mona"


action

  1. Dockerfile

https://github.com/xgqfrms/hello-github-actions/new/xgqfrms-patch-1?filename=action-a/Dockerfile

FROM debian:9.5-slim

ADD entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

  1. action.yml

https://github.com/xgqfrms/hello-github-actions/new/xgqfrms-patch-1?filename=action-a/action.yml


name: "Hello Actions"
description: "Greet someone"
author: "octocat@github.com"

inputs:
  MY_NAME:
    description: "Who to greet"
    required: true
    default: "World"

runs:
  using: "docker"
  image: "Dockerfile"

branding:
  icon: "mic"
  color: "purple"

  1. entrypoint.sh

https://github.com/xgqfrms/hello-github-actions/new/xgqfrms-patch-1?filename=action-a/entrypoint.sh

#!/bin/sh -l

sh -c "echo Hello world my name is $INPUT_MY_NAME"

example

https://github.com/xgqfrms/hello-github-actions/tree/master/action-a

https://github.com/xgqfrms/hello-github-actions/actions

create file by URL

https://github.com/xgqfrms/repo-name/new/master?filename=src/folder_name/filename

demos

https://github.com/xgqfrms/wcui/new/main?filename=.github%2Fworkflows%2Fmain.yml&workflow_template=blank

https://github.com/xgqfrms/hello-github-actions/actions

https://github.com/xgqfrms/wx-robot-notice/blob/main/.github/workflows/robot.yml

微信机器人


# This is a basic workflow to help you get started with Actions

name: WX_ROBOT

# 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,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!
  # notice job
  wx-robot:
    runs-on: ubuntu-latest
    steps:
      - name: 'Checkout codes'
        uses: actions/checkout@v1
      # 自定义 env, $GITHUB_ENV => ${{env.REPORT_DATE}}
      - name: 'Get Date'
        run: echo "REPORT_DATE=$(TZ=':Asia/Shanghai' date '+%Y-%m-%d %T')" >> $GITHUB_ENV
      # 自定义 env, $GITHUB_ENV => ${{env.WEBHOOK_KEY}}
      - name: 'set webhook key'
        run: echo "WEBHOOK_KEY=${{secrets.WX_ROBOT_KEY}}" >> $GITHUB_ENV
      # 自动发送打开通知
      - name: 'Send Notice'
        run: bash ./src/robot.sh
      # set env
      # - name: 'set env'
      #   run: export WX_ROBOT_KEY=${{secrets.WX_ROBOT_KEY}}
      # - name: 'get env'
      #   run: echo $WX_ROBOT_KEY
      # 自动发送打开通知
      # - name: 'Send Notice'
      #   run: bash ./src/robot.sh $WX_ROBOT_KEY
      # 自动发送打开通知
      # - name: 'Send Notice'
        # run: bash ./src/robot.sh env.WEBHOOK_KEY env.REPORT_DATE

https://github.com/xgqfrms/wx-robot-notice/blob/main/src/robot.sh#L9

#!/bin/sh

set -eux

# 设置 env
LANGUAGE="zh-CN"
UA="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4343.0 Safari/537.36"

SH_DATE=$(TZ=':Asia/Shanghai' date '+%Y-%m-%d %T');
echo "✅ SH_DATE = ${SH_DATE}"

# 打印参数
# echo $1
# echo $2

# echo "✅$1 = ${1}"
# echo "✅$2 = ${2}"

# github env {REPORT_DATE, WEBHOOK_KEY}
echo "✅REPORT_DATE = ${REPORT_DATE}"
echo "✅WEBHOOK_KEY = ${WEBHOOK_KEY}"

# 读书会机器人🤖️ features:
# 1. 大大简化进入打卡的流程,跳过 3s 首页的推荐;
# 2. 每天早晚两次打卡提醒(08:00 和 20:00) ⏰,降低忘记打卡的风险;

MARKDOWN='
{
    "msgtype": "markdown",
    "markdown": {
        "content": "⏰ '$SH_DATE'\n\n🎉<font color=\"warning\">读书会快捷链接</font>\n\n📘[<font color=\"info\">阅读打卡链接</font>](https://library.xgqfrms.xyz/#/club/share)\n\n👨🏻‍💻[<font color=\"info\">我的链接</font>](https://library.xgqfrms.xyz/#/my)\n\n💰[<font color=\"info\">积分链接</font>](https://library.xgqfrms.xyz/#/mall)\n\n<font color=\"warning\">读书会机器人🤖️ features:</font>\n\n<font color=\"comment\">1. 大大简化进入打卡的流程,跳过 3s 首页的推荐;</font>\n\n<font color=\"comment\">2. 每天早晚两次打卡提醒(08:00 和 20:00) ⏰,降低忘记打卡的风险;</font>\n\n",
        "mentioned_list":["凌晨"],
    }
}'

# MARKDOWN='
# {
#     "msgtype": "markdown",
#     "markdown": {
#         "content": "🎉<font color=\"info\">[阅读打卡链接](https://library.xgqfrms.xyz/#/club/share)</font>\n\n👨🏻‍💻<font color=\"info\">[我的链接](https://library.xgqfrms.xyz/#/my)</font>\n\n💰<font color=\"info\">[积分链接](https://library.xgqfrms.xyz/#/mall)</font>\n\n",
#         "mentioned_list":["凌晨","@all"],
#     }
# }'

# 不支持 ![]() 图片
# MARKDOWN='
# {
#     "msgtype": "markdown",
#     "markdown": {
#         "content": "🎉<font color=\"info\">[阅读打卡链接](https://library.xgqfrms.xyz/#/club/share)</font>\n🎉<font color=\"info\">[我的链接](https://library.xgqfrms.xyz/#/my)</font>\n![yoona](https://user-images.githubusercontent.com/7291672/143517029-7993a3a8-3983-405a-b146-50fcd47a0f25.png)"
#     }
# }'

# JSON='
#   {
#       "msgtype": "text",
#       "text": {
#           "content": "📘 阅读打卡了 ${SH_DATE}",
#       }
#   }';

# echo $JSON;

# 只有双引号中才可以包含变量,单引号不可以包含变量
curl "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${WEBHOOK_KEY}" \
  -H 'Content-Type: application/json' \
  -H "Accept-Language: $LANGUAGE" \
  -H "User-Agent: $UA" \
  -d "$MARKDOWN"


# curl "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${WEBHOOK_KEY}" \
#   -H 'Content-Type: application/json' \
#   -H "Accept-Language: $LANGUAGE" \
#   -H "User-Agent: $UA" \
#   -d "$JSON"


# curl "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${WEBHOOK_KEY}" \
#   -H 'Content-Type: application/json' \
#   -H "Accept-Language: $LANGUAGE" \
#   -H "User-Agent: $UA" \
#   -d '
#   {
#       "msgtype": "text",
#       "text": {
#           "content": "📘 阅读打卡了 ${SH_DATE}",
#       }
#   }'

echo "finished 🎉"

refs



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2020-05-02 14:40  xgqfrms  阅读(396)  评论(21编辑  收藏  举报