Coder Social home page Coder Social logo

build-number's Introduction

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/

build-number's People

Contributors

fredeil avatar gzur avatar undin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

build-number's Issues

Error when use it in my github actions yaml.

Run einaregilsson/build-number@v2
events.js:187
throw er; // Unhandled 'error' event
^

Error: getaddrinfo EAI_AGAIN api.github.com
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26)
Emitted 'error' event on ClientRequest instance at:
at TLSSocket.socketErrorListener (_http_client.js:406:9)
at TLSSocket.emit (events.js:210:5)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
errno: 'EAI_AGAIN',
code: 'EAI_AGAIN',
syscall: 'getaddrinfo',
hostname: 'api.github.com'
}
##[error]Node run failed with exit code 1

Old build-number-x tags re-appear

Hi,
since couple of months (maybe since I upgraded to V3?) I have the following issue:
The script fails, because there are too many "build-number-xxx" tags.
Then I delete all tags, but the latest. I re-run GitHub actions and everything works fine.
But somehow after sometimes all old "build-number-xxx" tags re-appear and the script fails again.
Any idea what is the problem and from were the old tags are re-created?

error in readme example

The readme example should have a needs: job1 line in the definition for job2, otherwise job2 can start executing before the job1 artifact has been uploaded and fail

Provide option to leave repository clean

current plugin saves build number to BUILD_NUMBER/BUILD_NUMBER file. I would like to have it clean and pass between jobs with artefacts (it might be better option as default as well)

please add option for that

current workaround - add BUILD_NUMBER to git ignore

hardcoded `build-number` prefix isn't very flexible

We're considering using your action (great work, btw), but it would be useful if the build-number prefix wasn't hardcoded. Appreciate that you can add another prefix, but two seems unnecessary. We could either remove the build-number string altogether, or have the custom prefix override the build-number string? What are your thoughts?

Example does not work for "runs-on: windows-latest" ?

When using runs-on: windows-latest, and this code

echo Build number is $BUILD_NUMBER

I get this:
image

I could only solve this by using the id: buildnumber, like:

steps:
    - name: Generate build number
      uses: einaregilsson/build-number@v1
      id: buildnumber
      with:
        token: ${{secrets.github_token}}   
    
    - name: Print new build number
      run: echo "Build number is ${{ steps.buildnumber.outputs.build_number }}"

Is this a known issue? And maybe update your readme?

race condition

If two builds run at the same time they both can get the same build number. I've had this happen a few times.

Build number write into file

Hello. Thank you for your work and this script.
But how can i use this variable? I mean i want to put this build.version into file?

Thank you.

Set up initial build number through inputs

I need the default build number to start at 0, not 1. I think it's worth adding a separate input for this. I can prepare a PR if needed.
In addition, it will also simplify the Use case with a start number.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.