branch-names/.github/workflows/test.yml

89 lines
4.0 KiB
YAML
Raw Normal View History

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
release:
types: [published, created]
2020-12-11 21:15:40 +08:00
pull_request:
branches:
- main
jobs:
test:
2024-02-07 11:52:54 +08:00
name: Test branch-names
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
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
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
2024-02-07 11:52:54 +08:00
id: branch-names
2020-12-11 21:21:28 +08:00
uses: ./
- name: Show output
2020-12-11 22:12:15 +08:00
run: |
2024-02-07 11:52:54 +08:00
echo "Default Branch: ${{ steps.branch-names.outputs.default_branch }}"
echo "Current Branch: ${{ steps.branch-names.outputs.current_branch }}"
echo "Base Ref: ${{ steps.branch-names.outputs.base_ref_branch }}"
echo "Head Ref: ${{ steps.branch-names.outputs.head_ref_branch }}"
echo "Ref: ${{ steps.branch-names.outputs.ref_branch }}"
echo "Is Default: ${{ steps.branch-names.outputs.is_default }}"
echo "Is Tag: ${{ steps.branch-names.outputs.is_tag }}"
echo "Current tag: ${{ steps.branch-names.outputs.tag }}"
2021-05-27 20:31:09 +08:00
- name: Test is_default output for pull request
2024-02-07 11:52:54 +08:00
if: contains(github.event_name, 'pull_request') && steps.branch-names.outputs.is_tag == 'false' && steps.branch-names.outputs.is_default != 'false'
2021-02-13 18:39:40 +08:00
run: |
2024-02-07 11:52:54 +08:00
echo "Is default is invalid: ${{ steps.branch-names.outputs.is_default }}"
2021-02-13 18:39:40 +08:00
exit 1
2021-05-27 20:31:09 +08:00
- name: Test is_default output for non pull request
2024-02-07 11:52:54 +08:00
if: "!contains(github.event_name, 'pull_request') && steps.branch-names.outputs.is_tag == 'false' && steps.branch-names.outputs.is_default != 'true'"
2021-02-13 18:39:40 +08:00
run: |
2024-02-07 11:52:54 +08:00
echo "Is default is invalid: ${{ steps.branch-names.outputs.is_default }}"
2021-02-13 18:39:40 +08:00
exit 1
2021-05-27 20:31:09 +08:00
- name: Test base_ref_branch output
2024-02-07 11:52:54 +08:00
if: contains(github.event_name, 'pull_request') && steps.branch-names.outputs.is_tag == 'false' && !steps.branch-names.outputs.base_ref_branch
2020-12-11 21:48:51 +08:00
run: |
2024-02-07 11:52:54 +08:00
echo "Base ref unset: ${{ steps.branch-names.outputs.base_ref_branch }}"
2020-12-11 21:48:51 +08:00
exit 1
2021-05-27 20:31:09 +08:00
- name: Test head_ref output
2024-02-07 11:52:54 +08:00
if: contains(github.event_name, 'pull_request') && steps.branch-names.outputs.is_tag == 'false' && !steps.branch-names.outputs.head_ref_branch
2020-12-11 21:48:51 +08:00
run: |
2024-02-07 11:52:54 +08:00
echo "Head ref unset: ${{ steps.branch-names.outputs.head_ref_branch }}"
2020-12-11 21:48:51 +08:00
exit 1
2021-05-27 20:31:09 +08:00
- name: Test ref_branch output
2024-02-07 11:52:54 +08:00
if: "!steps.branch-names.outputs.ref_branch && steps.branch-names.outputs.is_tag == 'false'"
2020-12-11 21:48:51 +08:00
run: |
2024-02-07 11:52:54 +08:00
echo "Ref unset: ${{ steps.branch-names.outputs.ref_branch }}"
2020-12-11 21:48:51 +08:00
exit 1
2022-11-13 11:56:54 +08:00
- name: Test current_branch output for pull_request or pull_request_target event.
2024-02-07 11:52:54 +08:00
if: contains(github.event_name, 'pull_request') && steps.branch-names.outputs.is_tag == 'false' && !steps.branch-names.outputs.current_branch
2021-02-08 08:34:33 +08:00
run: |
2024-02-07 11:52:54 +08:00
echo "Current branch unset: ${{ steps.branch-names.outputs.current_branch }}"
2021-02-08 08:34:33 +08:00
exit 1
2021-05-27 20:31:09 +08:00
- name: Test current_branch output for push event.
2024-02-07 11:52:54 +08:00
if: github.event_name == 'push' && steps.branch-names.outputs.is_tag == 'false' && !steps.branch-names.outputs.current_branch
2021-02-08 08:34:33 +08:00
run: |
2024-02-07 11:52:54 +08:00
echo "Current branch unset: ${{ steps.branch-names.outputs.current_branch }}"
2021-02-08 08:34:33 +08:00
exit 1
2021-05-27 20:31:09 +08:00
- name: Test current_branch output for tag based push event.
2024-02-07 11:52:54 +08:00
if: github.event_name == 'push' && steps.branch-names.outputs.is_tag == 'true' && !steps.branch-names.outputs.base_ref_branch
2021-05-27 20:31:09 +08:00
run: |
2024-02-07 11:52:54 +08:00
echo "Base ref unset: ${{ steps.branch-names.outputs.base_ref_branch }}"
2021-05-27 20:31:09 +08:00
exit 1
- name: Test tag output for tag based push event.
2024-02-07 11:52:54 +08:00
if: github.event_name == 'push' && steps.branch-names.outputs.is_tag == 'true' && !steps.branch-names.outputs.tag
2021-04-24 18:46:27 +08:00
run: |
2024-02-07 11:52:54 +08:00
echo "Current tag unset: ${{ steps.branch-names.outputs.tag }}"
2021-04-24 18:46:27 +08:00
exit 1