doc: update docs/github-actions.md

This commit is contained in:
jaywcjlove 2024-07-28 23:33:57 +08:00
parent eea1a03da8
commit 58991c482e

View File

@ -958,6 +958,47 @@ steps:
version: 1.22.21
```
### 传递环境变量
<!--rehype:wrap-class=col-span-2-->
`ci.yml` 上保存环境变量
```yml
- name: Save commit message to environment variable
run: echo "COMMIT_MESSAGE=${{ github.event.head_commit.message }}" >> $GITHUB_ENV
```
`tag.yml` 上获取环境变量
```yml
- name: Read commit message
run: |
echo "Commit: ${{ github.event.workflow_run.head_commit.message }}"
```
### 触发下一个工作流
`tag.yml` 上添加判断 `tag` 创建成功触发 `tag-creation-success` 的工作流
```yml
- name: Trigger next workflow if successful
if: steps.check_success.outputs.success == 'true'
run: |
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-d '{"event_type": "tag-creation-success"}' \
https://api.github.com/repos/${{ github.repository }}/dispatches
```
`success.yml` 上监听
```yml
on:
repository_dispatch:
types: [tag-creation-success]
```
GitLab CI/CD 迁移到 GitHub Actions
---