|
| 1 | +############################################################################################## |
| 2 | +# |
| 3 | +# Workflow Description: |
| 4 | +# Build a git tag on a specific commit in every git branch. And create GitHub release if current git branch is 'master'. |
| 5 | +# |
| 6 | +# Workflow input parameters: |
| 7 | +# * General arguments: |
| 8 | +# * project_type: Different project type would get the software version info in different way. |
| 9 | +# * debug_mode: It would run the tasks as log message, doesn't essentially run feature if this option is true. |
| 10 | +# * project_name: The project name. |
| 11 | +# * software_version_format: The format of software version. |
| 12 | +# |
| 13 | +# Workflow running output: |
| 14 | +# Yes, it has running result output. The output is the release version. |
| 15 | +# |
| 16 | +# * Workflow output: |
| 17 | +# It would output the version which would be build as git tag and create GitHub release version title. |
| 18 | +# * python_release_version: Python project release version info. |
| 19 | +# * github-action_reusable_workflow_release_version: GitHub Action reusable workflow project release version info. |
| 20 | +# |
| 21 | +############################################################################################## |
| 22 | + |
| 23 | +name: Build git tag and create GitHub release with software version |
| 24 | + |
| 25 | +on: |
| 26 | + workflow_call: |
| 27 | + inputs: |
| 28 | + project_type: |
| 29 | + description: "Different project type would get the software version info in different way." |
| 30 | + required: true |
| 31 | + type: string # Option: python, github-action_reusable-workflow |
| 32 | +# activate_git_event: |
| 33 | +# description: "Which git event should activate the workflow." |
| 34 | +# type: string |
| 35 | +# required: false |
| 36 | +# default: push |
| 37 | + debug_mode: |
| 38 | + description: "It would run the tasks as log message, doesn't essentially run feature if this option is true." |
| 39 | + type: boolean |
| 40 | + required: false |
| 41 | + default: false |
| 42 | + project_name: |
| 43 | + description: "The project name." |
| 44 | + type: string |
| 45 | + required: false |
| 46 | + software_version_format: |
| 47 | + description: "The format of software version." |
| 48 | + type: string |
| 49 | + required: false |
| 50 | + |
| 51 | + outputs: |
| 52 | + python_release_version: |
| 53 | + description: "The version which would be build as git tag and create GitHub release version title." |
| 54 | + value: ${{ jobs.build_git-tag_and_create_github-release.outputs.matrix_python }} |
| 55 | + github-action_reusable_workflow_release_version: |
| 56 | + description: "The version which would be build as git tag and create GitHub release version title." |
| 57 | + value: ${{ jobs.build_git-tag_and_create_github-release.outputs.matrix_github_action_reusable_workflow }} |
| 58 | + |
| 59 | + |
| 60 | +jobs: |
| 61 | + build_git-tag_and_create_github-release: |
| 62 | +# name: Build git tag and GitHub release if it needs |
| 63 | + if: github.event_name == 'push' |
| 64 | + runs-on: ubuntu-latest |
| 65 | + outputs: |
| 66 | + matrix_python: ${{ steps.python_release.outputs.release_type }} |
| 67 | + matrix_github_action_reusable_workflow: ${{ steps.github_action_reusable_workflow_release.outputs.release_version }} |
| 68 | + steps: |
| 69 | + - name: Checkout |
| 70 | + uses: actions/checkout@v2 |
| 71 | + |
| 72 | + - name: Download shell script for checking input parameters |
| 73 | + run: curl https://raw.githubusercontent.com/Chisanan232/GitHub-Action_Workflow-Template-Python/develop/scripts/ci/build_git-tag_or_create_github-release.sh --output ./scripts/ci/build_git-tag_or_create_github-release.sh |
| 74 | + |
| 75 | + # This flow for the project type is Python project |
| 76 | + - name: Build git tag and create GitHub release for Python project |
| 77 | + if: ${{ inputs.project_type == 'python-package' }} |
| 78 | + id: python_release |
| 79 | + run: | |
| 80 | + release=$(bash ./scripts/ci/build_git-tag_or_create_github-release.sh ${{ inputs.project_type }} ${{ inputs.debug_mode }} ${{ inputs.project_name }} ${{ inputs.software_version_format }}) |
| 81 | + echo "📄 Release log: $release" |
| 82 | +
|
| 83 | + release_type=$(echo "$release" | grep -E "\[Python\] \[Final Running Result\] ((Official\-Release)|(Pre\-Release))" | grep -E -o "((Official\-Release)|(Pre\-Release))") |
| 84 | + echo "🐍 Release Type: $release_type" |
| 85 | +
|
| 86 | + echo "::set-output name=release_type::$(echo $release_type)" |
| 87 | +
|
| 88 | + # This flow for the project type is GitHub Action reusable workflow |
| 89 | + - name: Build git tag and create GitHub release for GitHub Action reusable workflow project |
| 90 | + if: ${{ inputs.project_type == 'github-action-reusable-workflow' }} |
| 91 | + id: github_action_reusable_workflow_release |
| 92 | + run: | |
| 93 | + release=$(bash ./scripts/ci/build_git-tag_or_create_github-release.sh ${{ inputs.project_type }} ${{ inputs.debug_mode }}) |
| 94 | + echo "📄 Release log: $release" |
| 95 | +
|
| 96 | + release_version=$(echo "$release" | grep -E "\[GitHub Action - Reusable workflow\] \[Final Running Result\] Official-Release and version: ([0-9]{1,})" | grep -E -o "([0-9]{1,})") |
| 97 | + echo "🤖 Release Version: $release_version" |
| 98 | +
|
| 99 | + echo "::set-output name=release_version::$(echo $release_version)" |
| 100 | +
|
0 commit comments