Giter Club home page Giter Club logo

event-utilities's Introduction

Utils action

This action calculates several handy fields/outputs to use in other jobs.

Inputs

artifact_prefix

Optional The prefix that formatted_name should start with. By default there is no prefix. If a prefix is given, a trailing dash will be added if missing. E.g. both "test" and "test-" will result in formatted_name starting with "test-"

artifact_extension

Optional The extension that formatted_name should end with. By default, there is no extension. Similar to artifact_prefix, a leading dot is automatically added. E.g. both "txt" and ".txt" will result in formatted_name ending with ".txt"

append_sha

Optional Whether to make sure the first 8 characters of the commit SHA are included in formatted_name. This will make sure the formatted_name will end with e.g. -ab1cd3ef. See the section about formatted_name on the specific logic of this.

Outputs

formatted_name

A nicely formatted name based on the ref and sha in the current workflow context. ref is for example refs/tags/v1.0.0 when this workflow run is for pushing the v1.0.0 tag, while refs/heads/wip/stuff would be for the wip/stuff branch. The algorithm looks more or less like this:

  • Calculate the base name
    • If ref represents a semver tag (starts with vX.Y.Z where X/Y/Z are numbers): => Use the tag name without the leading v, e.g. 1.0.0 for v1.0.0
    • If ref represents another tag, use the (whole) tag name
    • If ref represents a branch, use the branch name, e.g. wip/stuff
    • If ref represents a pull request, use pr-123 with the correct number
    • Any other ref should never be pushed, but if so: => If it starts with refs/, use everything after the /
    • Otherwise use the first 8 characters of the commit SHA
  • Include commit SHA if append_sha is set
    • In case the base name already is the first 8 characters, do nothing
    • Otherwise, append e.g. -ab1cd3ef to the base name
  • Convert all slashes (/) to dashes (-), e.g. wip/stuff becomes wip-stuff
  • Remove all non-alphanumeric characters apart from dashes/dots/underscores

Examples:

  • Pushing commit ab1cd3ef... to the branch wip/stuff:
    • With append_sha results in wip-stuff-ab1cd3ef otherwise wip-stuff
  • Pushing commit ab1cd3ef... to pull request 123 or merging it:
    • With append_sha results in pr-123-ab1cd3ef otherwise pr-123
  • Pushing tag v1.2.3 pointing at commit ab1cd3ef...:
    • With append_sha results in 1.2.3-ab1cd3ef otherwise 1.2.3
  • Pushing tag verdict pointing at commit ab1cd3ef...:
    • With append_sha results in verdict-ab1cd3ef otherwise verdict

artifact_name

Basically appending everything together into [artifact_prefix-]formatted_name[.artifact_extension].

Missing inputs won't be included. The prefix will have a trailing dash added if missing, while for the extension it's a leading dot.

Example for formatted_name being master:

  • Without artifact_prefix and artifact_extension:
  • With artifact_prefix set to bundled => bundled-master
  • With artifact_prefix set to bundled- => bundled-master
  • With artifact_extension set to js => master.js
  • With artifact_extension set to .js => master.js
  • With prefix/extension set to bundled-/js => bundled-master.js
  • With prefix/extension set to bundled/.js => bundled-master.js

tag_version

If this push is for a semver tag (e.g. vX.Y.Z), this will be set to X.Y.Z.

For example, pushing the tag v1.2.3 results in tag_version being 1.2.3.

pr_number

If this push is towards a pull request, this will be set to its number.

Example usage

- name: Run utilities
  id: utils
  uses: SchoofsKelvin/event-utilities@v1
  with:
    artifact_prefix: "my-extension"
    artifact_extension: "vsix"
    append_sha: true
- name: Build extension
  run: vsce package -o ${{ steps.utils.outputs.artifact_name }}
- name: Upload a Build Artifact
  uses: actions/[email protected]
  with:
    name: ${{ steps.utils.outputs.artifact_name }}
    path: ${{ steps.utils.outputs.artifact_name }}
    if-no-files-found: error

Pushing commit ab1cd3ef... to the branch master would result in the workflow run having an artifact named my-extension-master-ab1cd3ef.vsix.

event-utilities's People

Contributors

schoofskelvin avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

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.