From f0d674c6e93496a7402966f4b799e267aebad976 Mon Sep 17 00:00:00 2001 From: Naka Masato Date: Tue, 28 May 2024 07:11:36 +0900 Subject: [PATCH] Update branch-and-tag.yml (#1351) * Update branch-and-tag.yml * Update branch-and-tag.yml * Update context.yml * Update README.md * Update context.yml * Update README.md --- .github/workflows/branch-and-tag.yml | 2 +- .github/workflows/context.yml | 10 ++++++++++ README.md | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/branch-and-tag.yml b/.github/workflows/branch-and-tag.yml index 848f8c59..a2d5c65d 100644 --- a/.github/workflows/branch-and-tag.yml +++ b/.github/workflows/branch-and-tag.yml @@ -8,7 +8,7 @@ on: - v1.* jobs: - merge-branch: + check: runs-on: ubuntu-latest steps: - uses: actions/checkout@master diff --git a/.github/workflows/context.yml b/.github/workflows/context.yml index ff100435..42ea4d37 100644 --- a/.github/workflows/context.yml +++ b/.github/workflows/context.yml @@ -38,6 +38,16 @@ jobs: run: | echo "$BRANCH" + push-and-pull-request: + if: github.event_name == 'pull_request' || github.event_name == 'push' + runs-on: ubuntu-latest + steps: + - name: get tag + env: + TAG: ${{ github.event_name == 'push' && github.ref_name || format('pr-{0}', github.event.number) }} # branch for push and pr-xx for pull request + run: | + echo "event_name: ${{ github.event_name }}, tag: $TAG" + label: if: github.event_name == 'pull_request' runs-on: ubuntu-latest diff --git a/README.md b/README.md index 9b3c51a4..7507478e 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ - `github.sha` is not the latest commit sha [ref](https://sue445.hatenablog.com/entry/2021/01/07/004835) <- you can use this sha for the `closed` type to get the latest commit on the `main` branch. - `github.event.pull_request.head.sha` is the sha of the lastest commit on the pr branch [ref](https://github.com/orgs/community/discussions/26676) +- `github.event.pull_request.head.ref`: pr branch name. e.g. `BRANCH: ${{ github.event_name == 'push' && github.ref_name || github.event.pull_request.head.ref }}`: branch name for `push` and `pull_request` event (need to set in `env`) +- `github.event.number`: pull request number. e.g. `${{ github.event_name == 'push' && github.ref_name || format('pr-{0}', github.event.number) }}` get tag name (branch name for push and `pr-xxx` for pr) |GitHub Actions|Trigger|Description| |---|---|---| @@ -44,6 +46,8 @@ ### 3. push +- `BRANCH: ${{ github.event_name == 'push' && github.ref_name || github.event.pull_request.head.ref }}`: branch name for `push` and `pull_request` event (need to set in `env`) + |GitHub Actions|Trigger|Description| |---|---|---| |~~**branch-and-tag**~~|push| If change is pushed to `merge` branch or tagged as `v1.*`, the branch will be merged to `main` branch. disabled due to branch protection in [#1348](https://github.com/nakamasato/github-actions-practice/pull/1348)❌|