mirror of
https://github.com/tj-actions/branch-names.git
synced 2024-11-24 08:03:51 +08:00
89 lines
4.0 KiB
YAML
89 lines
4.0 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- '*'
|
|
branches:
|
|
- main
|
|
release:
|
|
types: [published, created]
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
test:
|
|
name: Test branch-name
|
|
runs-on: ${{ matrix.platform }}
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
platform: [ubuntu-latest, windows-latest, macos-latest, macos-11, windows-2022]
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
|
- name: Dump GitHub context
|
|
env:
|
|
GITHUB_CONTEXT: ${{ toJson(github) }}
|
|
run: echo "$GITHUB_CONTEXT"
|
|
- name: Run test
|
|
id: branch-name
|
|
uses: ./
|
|
- name: Show output
|
|
run: |
|
|
echo "Default Branch: ${{ steps.branch-name.outputs.default_branch }}"
|
|
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 }}"
|
|
echo "Is Default: ${{ steps.branch-name.outputs.is_default }}"
|
|
echo "Is Tag: ${{ steps.branch-name.outputs.is_tag }}"
|
|
echo "Current tag: ${{ steps.branch-name.outputs.tag }}"
|
|
- name: Test is_default output for pull request
|
|
if: contains(github.event_name, 'pull_request') && steps.branch-name.outputs.is_tag == 'false' && steps.branch-name.outputs.is_default != 'false'
|
|
run: |
|
|
echo "Is default is invalid: ${{ steps.branch-name.outputs.is_default }}"
|
|
exit 1
|
|
- name: Test is_default output for non pull request
|
|
if: "!contains(github.event_name, 'pull_request') && steps.branch-name.outputs.is_tag == 'false' && steps.branch-name.outputs.is_default != 'true'"
|
|
run: |
|
|
echo "Is default is invalid: ${{ steps.branch-name.outputs.is_default }}"
|
|
exit 1
|
|
- name: Test base_ref_branch output
|
|
if: contains(github.event_name, 'pull_request') && steps.branch-name.outputs.is_tag == 'false' && !steps.branch-name.outputs.base_ref_branch
|
|
run: |
|
|
echo "Base ref unset: ${{ steps.branch-name.outputs.base_ref_branch }}"
|
|
exit 1
|
|
- name: Test head_ref output
|
|
if: contains(github.event_name, 'pull_request') && steps.branch-name.outputs.is_tag == 'false' && !steps.branch-name.outputs.head_ref_branch
|
|
run: |
|
|
echo "Head ref unset: ${{ steps.branch-name.outputs.head_ref_branch }}"
|
|
exit 1
|
|
- name: Test ref_branch output
|
|
if: "!steps.branch-name.outputs.ref_branch && steps.branch-name.outputs.is_tag == 'false'"
|
|
run: |
|
|
echo "Ref unset: ${{ steps.branch-name.outputs.ref_branch }}"
|
|
exit 1
|
|
- name: Test current_branch output for pull_request or pull_request_target event.
|
|
if: contains(github.event_name, 'pull_request') && steps.branch-name.outputs.is_tag == 'false' && !steps.branch-name.outputs.current_branch
|
|
run: |
|
|
echo "Current branch unset: ${{ steps.branch-name.outputs.current_branch }}"
|
|
exit 1
|
|
- 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
|
|
run: |
|
|
echo "Current branch unset: ${{ steps.branch-name.outputs.current_branch }}"
|
|
exit 1
|
|
- name: Test current_branch output for tag based push event.
|
|
if: github.event_name == 'push' && steps.branch-name.outputs.is_tag == 'true' && !steps.branch-name.outputs.base_ref_branch
|
|
run: |
|
|
echo "Base ref unset: ${{ steps.branch-name.outputs.base_ref_branch }}"
|
|
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
|
|
run: |
|
|
echo "Current tag unset: ${{ steps.branch-name.outputs.tag }}"
|
|
exit 1
|