This GitHub Action generates and increments build numbers based on a unique identifier. The build numbers are stored in a JSON file within a specified branch of your repository, allowing you to track independent build numbers for different projects or components.
- Unique Build Numbers: Generates unique build numbers for each identifier, ensuring different projects or components can maintain independent versioning.
- Branch Customization: Allows specifying the branch where the build numbers are stored.
- Thread Safety: Implements file locking to prevent race conditions when multiple instances of the action run concurrently.
token
(required): A GitHub token with write access to the repository.branch
(optional): The branch where the build numbers are stored. Defaults tobuild-numbers
if not specified.identifier
(required): A unique identifier for the build number. Each identifier maintains its own sequence of build numbers.increment
(optional): A boolean flag to control whether the build number should be incremented or just retrieved. Defaults totrue
.
build-number
: The newly generated build number for the specified identifier.
BUILD_NUMBER
: The newly generated build number is also set as an environment variable, making it easy to access in later steps.
Here's an example of how to use the action in a workflow:
name: Generate Build Number
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate Build Number
uses: BetonQuest/build-number-generator@main
id: generate
with:
token: ${{ secrets.GITHUB_TOKEN }}
identifier: 'projectA'
- name: Output Build Number (Output)
run: |
echo "Build Number: ${{ steps.generate.outputs.build-number }}"
- name: Output Build Number (Environment)
run: |
echo "Build Number: ${{ env.BUILD_NUMBER }}"
Detailed Configuration:
- name: Generate Build Number
uses: BetonQuest/build-number-generator@main
id: generate
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: 'build-numbers'
identifier: 'projectA'
increment: true
This action uses proper-lockfile
to ensure that the build_numbers.json
file is not accessed by multiple processes
simultaneously.
This prevents race conditions when the action runs concurrently.
The action checks out the specified branch (and build-numbers
by default).
If the branch does not exist, it is created and set to track the remote branch.
The build_numbers.json
file is structured as follows:
{
"identifier1": 123,
"identifier2": 45,
"projectA": 10
}
Each key corresponds to an identifier, and the value is the current build number.
- GitHub Token: Ensure that the GitHub token used has sufficient permissions to push to the specified branch.
- Checkout Action: The action requires the
actions/checkout
to fetch all branches with thefetch-depth: 0
option. - File Locking: The file locking mechanism is critical for ensuring that build numbers are not corrupted by concurrent writes.
Feel free to open issues or submit pull requests for improvements and bug fixes.
This project is licensed under the GPL3 License. See the LICENSE file for details.