我们这里举个例子,此处的需求是:当一个用户提出pr后,会自动在评论区回复 Welcome to the repository!
Text Only
1 2 3 4 5 6 7 8 91011121314151617
# (main branch) under .github/workflows
# create a new file named `welcome.yml`
name: Post welcome comment # workflow name
on: # trigger event
pull_request:
types: [opened] # when we open a new pr, this welcome workflow is triggered
permissions:
pull-requests: write # we need to write into pr, so permission is needed
jobs:
build:
name: Post welcome comment # job name
runs-on: ubuntu-latest # this job(task) is running on ubuntu-latest remote machine
steps: # if there are many commands, we can use steps to organize them, they will be executed in order
- run: gh pr comment $PR_URL --body "Welcome to the repository!" # this is the command we want to run
env: # ENVIRONMENT VARIABLES for the command above
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_URL: ${{ github.event.pull_request.html_url }}
jobs:
# Get the current step to only run the main job when the learner is on the same step.
get_current_step:
name: Check current step number
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- id: get_step
run: |
echo "current_step=$(cat ./.github/steps/-step.txt)" >> $GITHUB_OUTPUT
outputs:
current_step: ${{ steps.get_step.outputs.current_step }}
on_trigger:
name: On trigger
needs: get_current_step
# We will only run this action when:
# 1. This repository isn't the template repository.
# 2. The step is currently 5.
# Reference: https://docs.github.com/en/actions/learn-github-actions/contexts
# Reference: https://docs.github.com/en/actions/learn-github-actions/expressions
if: >-
${{ !github.event.repository.is_template
&& needs.get_current_step.outputs.current_step == 5 }}
# We'll run Ubuntu for performance instead of Mac or Windows.
runs-on: ubuntu-latest
steps:
# We'll need to check out the repository so that we can edit the README.
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Let's get all the branches.
# In README.md, switch step 5 for step X.
- name: Update to step X
uses: skills/action-update-step@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
from_step: 5
to_step: X
branch_name: test-workflow
这里我们在ci分支中进行了build这个job,但是构建失败,报错信息:Process completed with exit code 1.
Text Only
1 2 3 4 5 6 7 8 910111213141516171819202122232425
# 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@v4
# # 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.
- name: Run markdown lint
run: |
npm install remark-cli remark-preset-lint-consistent
npx remark . --use remark-preset-lint-consistent --frail