|
| 1 | +# Generate semver - Github action |
| 2 | + |
| 3 | +A [GitHub Action](https://github.com/features/actions) to generate semantic version number. |
| 4 | +and commit messages. |
| 5 | + |
| 6 | +## Usage |
| 7 | + |
| 8 | +1. Create a `.github/workflows/generate-version.yml` file in your GitHub repo. |
| 9 | +2. Add the following code to the `generate-version.yml` file. |
| 10 | + |
| 11 | +```yml |
| 12 | +on: |
| 13 | + pull_request: |
| 14 | + types: |
| 15 | + - opened |
| 16 | + - synchronize |
| 17 | + - reopened |
| 18 | + - ready_for_review |
| 19 | + branches: |
| 20 | + - master |
| 21 | + |
| 22 | +jobs: |
| 23 | + attach: |
| 24 | + runs-on: ubuntu-18.04 |
| 25 | + timeout-minutes: 10 |
| 26 | + if: github.event.pull_request.draft == false |
| 27 | + |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v2 |
| 30 | + with: |
| 31 | + fetch-depth: 0 |
| 32 | + |
| 33 | + - name: Generate branch diff file |
| 34 | + if: success() |
| 35 | + run: | |
| 36 | + echo "Head branch: ${GITHUB_HEAD_REF}" |
| 37 | + echo "Base branch: ${GITHUB_BASE_REF}" |
| 38 | + git log origin/${GITHUB_BASE_REF}..origin/${GITHUB_HEAD_REF} > ./branch-diff.txt |
| 39 | +
|
| 40 | + - name: Extract previous version |
| 41 | + if: success() |
| 42 | + run: | |
| 43 | + export PREVIOUS_VERSION=$(git describe --tags --abbrev=0) |
| 44 | + echo "Previous version: ${PREVIOUS_VERSION}" |
| 45 | + echo "PREVIOUS_VERSION=${TAG}" > ${GITHUB_ENV} |
| 46 | +
|
| 47 | + - name: Generate version number |
| 48 | + id: generate |
| 49 | + if: success() |
| 50 | + uses: juztcode/generate-semver@1.0.0 |
| 51 | + with: |
| 52 | + branch-diff-file: ./branch-diff.txt |
| 53 | + previous-version: ${{ env.PREVIOUS_VERSION }} |
| 54 | + |
| 55 | + - name: Print version |
| 56 | + - if: success() |
| 57 | + run: echo ${{ steps.generate.outputs.generated-version }} |
| 58 | +``` |
| 59 | +
|
| 60 | +> Note: This will be triggered when there are pull requests from release branches to master branch and update pull request body with jira ticket ids. |
| 61 | +
|
| 62 | +## Inputs |
| 63 | +
|
| 64 | +Input | Purpose |
| 65 | +------------------|--------------------------------------------------------------------------------------------------------------------------------------- |
| 66 | +branch-diff-file | File contains commit message difference between head and base branches. |
| 67 | +previous-version | Previous (latest) version number. |
| 68 | +
|
| 69 | +## Outputs |
| 70 | +
|
| 71 | +Output | Purpose |
| 72 | +------------------|--------------------------------------------------------------------------------------------------------------------------------------- |
| 73 | +generated-version | Generated semver version number. |
0 commit comments