• This repository has been archived on 16/Jan/2023
  • Stars
    star
    137
  • Rank 257,444 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

GitHub action for generating sequential build numbers.

NOTICE: This action is no longer being maintained

Due the maintainer passing away, this action is no longer being maintained as of Janyary 2023.

Development has moved to onyxmueller/build-tag-number and the action is available on the Marketplace here: https://github.com/marketplace/actions/build-tag-number

Updating your existing Github Actions workflows should be as simple as replacing einaregilsson/build-number@v3 with onyxmueller/build-tag-number@v1

See the repo linked above for more information.

Update 2020-02-12

GitHub has just introduced new environment variables, GITHUB_RUN_ID and GITHUB_RUN_NUMBER which are unique numbers for each workflow run, so you're probably better off using those than this GitHub action. 🙂 See https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables

build-number

GitHub action for generating sequential build numbers for GitHub actions. The build number is stored in your GitHub repository as a ref, it doesn't add any extra commits to your repository. Use in your workflow like so:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Generate build number
      uses: einaregilsson/build-number@v3
      with:
        token: ${{secrets.github_token}}        
    - name: Print new build number
      run: echo "Build number is $BUILD_NUMBER"
      # Or, if you're on Windows: echo "Build number is ${env:BUILD_NUMBER}"

After that runs the subsequent steps in your job will have the environment variable BUILD_NUMBER available. If you prefer to be more explicit you can use the output of the step, like so:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Generate build number
      id: buildnumber
      uses: einaregilsson/build-number@v3 
      with:
        token: ${{secrets.github_token}}        
    
    # Now you can pass ${{ steps.buildnumber.outputs.build_number }} to the next steps.
    - name: Another step as an example
      uses: actions/hello-world-docker-action@v1
      with:
        who-to-greet: ${{ steps.buildnumber.outputs.build_number }}

The GITHUB_TOKEN environment variable is defined by GitHub already for you. See virtual environments for GitHub actions for more information.

Getting the build number in other jobs

For other steps in the same job you can use the methods above, to actually get the build number in other jobs you need to use job outputs mechanism:

jobs:
  job1:
    runs-on: ubuntu-latest
    outputs:
      build_number: ${{ steps.buildnumber.outputs.build_number }}
    steps:
    - name: Generate build number
      id: buildnumber
      uses: einaregilsson/build-number@v3 
      with:
        token: ${{secrets.github_token}}
          
  job2:
    needs: job1
    runs-on: ubuntu-latest
    steps:
    - name: Another step as an example
      uses: actions/hello-world-docker-action@v1
      with:
        who-to-greet: ${{needs.job1.outputs.build_number}}

Setting the initial build number.

If you're moving from another build system, you might want to start from some specific number. The build-number action simply uses a special tag name to store the build number, build-number-x, so you can just create and push a tag with the number you want to start on. E.g. do

git tag build-number-500
git push origin build-number-500

and then your next build number will be 501. The action will always delete older refs that start with build-number-, e.g. when it runs and finds build-number-500 it will create a new tag, build-number-501 and then delete build-number-500.

Generating multiple independent build numbers

Sometimes you may have more than one project to build in one repository. For example you may have a client and a server in the same github repository that you would like to generate independent build numbers for. Another example is you have two Dockerfiles in one repo and you'd like to version each of the built images with their own numbers.
To do this, use the prefix key, like so:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Generate build number
      id: buildnumber
      uses: einaregilsson/build-number@v3 
      with:
        token: ${{ secrets.github_token }}
        prefix: client

This will generate a git tag like client-build-number-1.

If you then do the same in another workflow and use prefix: server then you'll get a second build-number tag called server-build-number-1.

Branches and build numbers

The build number generator is global, there's no concept of special build numbers for special branches unless handled manually with the prefix property. It's probably something you would just use on builds from your master branch. It's just one number that gets increased every time the action is run.

So, that's it. Hope you can use it. You can read more about how it works in this blog post: http://einaregilsson.com/a-github-action-for-generating-sequential-build-numbers/

More Repositories

1

Redirector

Browser extension (Firefox, Chrome, Opera, Edge) to redirect urls based on regex patterns, like a client side mod_rewrite.
JavaScript
1,394
star
2

beanstalk-deploy

GitHub action (and command line script) to deploy apps to Elastic Beanstalk
JavaScript
582
star
3

cards.js

Javascript library for card games.
JavaScript
256
star
4

ChordImageGenerator

A .NET library to generate images of guitar chords.
C#
69
star
5

InsertIcons

Simple tool to add multiple win32 icons to .NET assemblies
C#
62
star
6

chord.js

Javascript library to render images of guitar and ukulele chords
JavaScript
54
star
7

StopOnFirstBuildError

Visual Studio extension to stop solution build immediately after a projects fails to build.
C#
49
star
8

sudoku.js

Sudoku Javascript library, based on Peter Norvig's solver
JavaScript
26
star
9

MyLife

MyLife: A single-user OhLife alternative
Python
25
star
10

photo16x9

Simple website to pad out images so they fit an aspect ratio of 16x9
HTML
17
star
11

While-Language

A .NET compiler for the While Language, a programming language used in Program Analysis courses
C#
11
star
12

ClipboardDiff

VS extension to diff the selected text against the clipboard
C#
10
star
13

s3-list-all-objects

NPM package to list all objects in a S3 bucket.
JavaScript
5
star
14

printmysongs

Create beautiful looking song sheets with chord diagrams and tablature.
JavaScript
5
star
15

save-svg-as-png

Adds button and right click menu to Chrome to scale and save SVG images as PNG
JavaScript
5
star
16

Scroll-Search-Engines

Firefox extension to scroll through the available search engines
JavaScript
4
star
17

EventHandlerNaming

Visual Studio 2010 extension to control naming conventions for event handlers in C#.
C#
3
star
18

update-lambda-edge-function

Updates the version nr of a Lambda@Edge function to use in a Cloudfront distribution.
JavaScript
2
star
19

print-environment

Simple GitHub Action to print environment variables.
Shell
1
star
20

Process-Language-Runtime

A Process Language Runtime for the .NET Platform
C#
1
star
21

hradbankar

Source for hradbankar.is
HTML
1
star
22

roundedcorners

Tool to add rounded corners to images.
HTML
1
star
23

einaregilsson.com

Source for einaregilsson.com
HTML
1
star
24

gulp-global-exclude

Global exclude patterns for gulp.src and gulp.watch.
JavaScript
1
star