2020-12-11 21:15:40 +08:00
|
|
|
name: CI
|
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
2021-04-24 18:46:27 +08:00
|
|
|
tags:
|
|
|
|
- '*'
|
2020-12-11 21:15:40 +08:00
|
|
|
branches:
|
|
|
|
- main
|
2022-11-13 06:46:07 +08:00
|
|
|
pull_request_target:
|
2020-12-11 21:15:40 +08:00
|
|
|
pull_request:
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
test:
|
|
|
|
name: Test branch-name
|
2021-12-19 09:08:16 +08:00
|
|
|
runs-on: ${{ matrix.platform }}
|
|
|
|
strategy:
|
|
|
|
fail-fast: false
|
|
|
|
matrix:
|
2022-12-16 09:31:33 +08:00
|
|
|
platform: [ubuntu-latest, windows-latest, macos-latest, macos-11, windows-2022]
|
2021-12-19 09:08:16 +08:00
|
|
|
|
2020-12-11 21:15:40 +08:00
|
|
|
steps:
|
|
|
|
- name: Checkout
|
2023-01-05 21:42:57 +08:00
|
|
|
uses: actions/checkout@v3.3.0
|
2022-11-13 06:52:34 +08:00
|
|
|
- name: Dump GitHub context
|
|
|
|
env:
|
|
|
|
GITHUB_CONTEXT: ${{ toJson(github) }}
|
2022-11-13 06:59:27 +08:00
|
|
|
run: echo "$GITHUB_CONTEXT"
|
2020-12-11 21:21:28 +08:00
|
|
|
- name: Run test
|
|
|
|
id: branch-name
|
|
|
|
uses: ./
|
|
|
|
- name: Show output
|
2020-12-11 22:12:15 +08:00
|
|
|
run: |
|
2022-03-23 05:07:29 +08:00
|
|
|
echo "Default Branch: ${{ steps.branch-name.outputs.default_branch }}"
|
2021-02-08 08:41:26 +08:00
|
|
|
echo "Current Branch: ${{ steps.branch-name.outputs.current_branch }}"
|
|
|
|
echo "Base Ref: ${{ steps.branch-name.outputs.base_ref_branch }}"
|
|
|
|
echo "Head Ref: ${{ steps.branch-name.outputs.head_ref_branch }}"
|
|
|
|
echo "Ref: ${{ steps.branch-name.outputs.ref_branch }}"
|
2021-02-13 18:39:40 +08:00
|
|
|
echo "Is Default: ${{ steps.branch-name.outputs.is_default }}"
|
2021-05-27 20:39:41 +08:00
|
|
|
echo "Is Tag: ${{ steps.branch-name.outputs.is_tag }}"
|
2021-04-25 08:14:12 +08:00
|
|
|
echo "Current tag: ${{ steps.branch-name.outputs.tag }}"
|
2021-05-27 20:31:09 +08:00
|
|
|
- name: Test is_default output for pull request
|
2022-11-13 11:56:54 +08:00
|
|
|
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && steps.branch-name.outputs.is_tag == 'false' && steps.branch-name.outputs.is_default != 'false'
|
2021-02-13 18:39:40 +08:00
|
|
|
run: |
|
|
|
|
echo "Is default is invalid: ${{ steps.branch-name.outputs.is_default }}"
|
|
|
|
exit 1
|
2021-05-27 20:31:09 +08:00
|
|
|
- name: Test is_default output for non pull request
|
2022-11-13 12:08:10 +08:00
|
|
|
if: github.event_name != 'pull_request' && github.event_name != 'pull_request_target' && steps.branch-name.outputs.is_tag == 'false' && steps.branch-name.outputs.is_default != 'true'
|
2021-02-13 18:39:40 +08:00
|
|
|
run: |
|
|
|
|
echo "Is default is invalid: ${{ steps.branch-name.outputs.is_default }}"
|
|
|
|
exit 1
|
2021-05-27 20:31:09 +08:00
|
|
|
- name: Test base_ref_branch output
|
2022-11-13 11:56:54 +08:00
|
|
|
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && steps.branch-name.outputs.is_tag == 'false' && !steps.branch-name.outputs.base_ref_branch
|
2020-12-11 21:48:51 +08:00
|
|
|
run: |
|
|
|
|
echo "Base ref unset: ${{ steps.branch-name.outputs.base_ref_branch }}"
|
|
|
|
exit 1
|
2021-05-27 20:31:09 +08:00
|
|
|
- name: Test head_ref output
|
2022-11-13 11:56:54 +08:00
|
|
|
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && steps.branch-name.outputs.is_tag == 'false' && !steps.branch-name.outputs.head_ref_branch
|
2020-12-11 21:48:51 +08:00
|
|
|
run: |
|
|
|
|
echo "Head ref unset: ${{ steps.branch-name.outputs.head_ref_branch }}"
|
|
|
|
exit 1
|
2021-05-27 20:31:09 +08:00
|
|
|
- name: Test ref_branch output
|
|
|
|
if: "!steps.branch-name.outputs.ref_branch && steps.branch-name.outputs.is_tag == 'false'"
|
2020-12-11 21:48:51 +08:00
|
|
|
run: |
|
|
|
|
echo "Ref unset: ${{ steps.branch-name.outputs.ref_branch }}"
|
|
|
|
exit 1
|
2022-11-13 11:56:54 +08:00
|
|
|
- name: Test current_branch output for pull_request or pull_request_target event.
|
|
|
|
if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && steps.branch-name.outputs.is_tag == 'false' && !steps.branch-name.outputs.current_branch
|
2021-02-08 08:34:33 +08:00
|
|
|
run: |
|
|
|
|
echo "Current branch unset: ${{ steps.branch-name.outputs.current_branch }}"
|
|
|
|
exit 1
|
2021-05-27 20:31:09 +08:00
|
|
|
- name: Test current_branch output for push event.
|
|
|
|
if: github.event_name == 'push' && steps.branch-name.outputs.is_tag == 'false' && !steps.branch-name.outputs.current_branch
|
2021-02-08 08:34:33 +08:00
|
|
|
run: |
|
|
|
|
echo "Current branch unset: ${{ steps.branch-name.outputs.current_branch }}"
|
|
|
|
exit 1
|
2021-05-27 20:31:09 +08:00
|
|
|
- name: Test current_branch output for tag based push event.
|
2022-08-27 23:33:02 +08:00
|
|
|
if: github.event_name == 'push' && steps.branch-name.outputs.is_tag == 'true' && !steps.branch-name.outputs.base_ref_branch
|
2021-05-27 20:31:09 +08:00
|
|
|
run: |
|
2022-08-27 23:33:02 +08:00
|
|
|
echo "Base ref unset: ${{ steps.branch-name.outputs.base_ref_branch }}"
|
2021-05-27 20:31:09 +08:00
|
|
|
exit 1
|
|
|
|
- name: Test tag output for tag based push event.
|
|
|
|
if: github.event_name == 'push' && steps.branch-name.outputs.is_tag == 'true' && !steps.branch-name.outputs.tag
|
2021-04-24 18:46:27 +08:00
|
|
|
run: |
|
|
|
|
echo "Current tag unset: ${{ steps.branch-name.outputs.tag }}"
|
|
|
|
exit 1
|