Skip to content
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

gh-project-context

GitHub tag (latest SemVer)

Build project context and correct Project version in any language version before release.

This action is build a Project context depends on GitHub event to make decision in further step, e.g: do build, do test, do analysis, do tag, do release based on your workflow model.

It also verifies and corrects automatically Project version in metadata file in release pull request or tag:

  • NodeJS: package.json
  • Java: Gradle with gradle.properties
  • Python: Poetry with pyproject.toml or version.py
  • Plain text: VERSION.txt
  • Or any version metadata file if you know some magical regex skill

Usage

Trigger precondition

The usual example

on:
create:
branches: [ 'release/**' ] ## To create a release PRpush:
branches: ## On main branch, hotfix branch and/or all release branches (optional) 
- main
- hotfix/**
- release/**tags: [ 'v*' ] ## Release tag versionpaths-ignore:
- '.github/ISSUE_TEMPLATE/**'
- '.github/*.yml'
- 'LICENSE'pull_request:
types: [ opened, synchronize, reopened, closed ]branches:
- main
- hotfix/**paths-ignore:
- '.github/ISSUE_TEMPLATE/**'
- '.github/*.yml'
- 'LICENSE'

More detailed at GitHub docs

Integrate the action in your workflow

You can use this action in 2 ways:

  1. Add it as first job in your workflow
jobs:
context:
runs-on: ubuntu-latestoutputs:
branch: ${{ steps.context.outputs.branch }}shouldBuild: ${{ steps.context.outputs.decision_build }}shouldPublish: ${{ steps.context.outputs.decision_publish }}isRelease: ${{ steps.context.outputs.isTag && steps.context.outputs.isRelease }}version: ${{ steps.context.outputs.version }}commitId: ${{ steps.context.outputs.commitShortId }}semanticVersion: ${{ steps.semantic.outputs.semanticVersion }}steps:
- uses: actions/checkout@v3
- name: Project contextid: contextuses: zero88/gh-project-context@v2build:
runs-on: ubuntu-latestneeds: contextif: needs.context.outputs.shouldBuild == 'true' # condition to build
  1. Add it as step in your job
jobs:
matrix:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v2
- name: Project contextuses: zero88/gh-project-context@v1id: project_context
- name: Build projectif: steps.project_context.outputs.decision_build == 'true' # condition to buildshell: bashruns: | npm ci npm run build - name: Build projectif: steps.project_context.outputs.decision_publish == 'true' # condition to publishshell: bashruns: | npm publish

Action output

Run zero88/gh-project-context@v1.2
Loading...
[CI::Process] Evaluate context on main
Searching version in file...
Current Version: 0.0.3
Project context
Version context
{
"branch": "main",
"current": "0.0.3",
"version": "0.0.3"
}
CI context
{
"isPushed": false
}
CI decision
{
"build": true,
"publish": true
}
Action Output
{
"branch": "main",
"onDefaultBranch": true,
"isBranch": true,
"isPR": false,
"isTag": false,
"isSchedule": false,
"isDispatch": false,
"isAfterMergedReleasePR": false,
"isClosed": false,
"isMerged": false,
"isOpened": false,
"isRelease": false,
"commitId": "c1c69ba9f41eeffaf260b7a6174fc37493c8fb42",
"commitMsg": "chore: bump to next version",
"commitShortId": "c1c69ba",
"ci_isPushed": false,
"decision_build": true,
"decision_publish": true,
"version": "0.0.3",
"versions_branch": "main",
"versions_current": "0.0.3"
}

Input and Output

Input

NameDescriptionRequiredDefault value
defaultBranchProject default branchfalsemain
tagPrefixTag Prefixfalsev
releaseBranchPrefixGit Release Branch Prefixfalserelease/
hotfixPrefixGit Hotfix Prefixfalsehotfix/
mergedReleaseMsgRegexMerged release message regexfalse^Merge pull request #[0-9]+ from .+/release/.+$
patternsThe patterns to search/replace a version.
E.g: <glob_pattern_with_ext>::<regex_group>::<version_regex>
falseSee below
shaLengthCreate output short commit id within lengthfalse7
allowCommitCI: Allow git commit to fix version if not matchfalsetrue
allowTagCI: Allow git tag if merged release branchfalsetrue
userNameCI: Username to commitfalseci-bot
userEmailCI: User email to commitfalseactions@github.com
mustSignCI: Required GPG sign when git commit/tagfalsefalse
prefixCiMsgCI: Prefix bot messagefalse<ci-auto-commit>
correctVerMsgCI: Correct version message templatefalseCorrect version
releaseVerMsgCI: Release version message templatefalseRelease version
nextVerMsgCI: Next version message templatefalseNext version
nextVerModeCI: Next version mode to choose for upgrading version after merged release PR. One of: MAJOR,MINOR,PATCH,NONEfalseNONE
tokenCI: GitHub token to create a new Release Pull Requestfalse``
dryCI: Dry run. If true, action will run without do modify files or git push or git tagfalsefalse
changelogEnable generate CHANGELOGfalsefalse
changelogImageCHANGELOG docker image tag: https://github.com/github-changelog-generator/docker-github-changelog-generatorfalsegithubchangeloggenerator/github-changelog-generator:1.16.2
changelogConfigFileCHANGELOG config file: https://github.com/github-changelog-generator/github-changelog-generator#params-filefalse.github_changelog_generator
changelogTokenCHANGELOG token to query GitHub API: https://github.com/github-changelog-generator/github-changelog-generator#github-tokenfalse
changelogMsgCI: Changelog generator commit message templatefalseGenerated CHANGELOG

Default Pattern Input

pyproject.toml::(version\s?=\s?)(")([^"]+)(")::2
package?(-lock).json::("version"\s?:\s?)(")([^"]+)(")::2
@(gradle|maven|pom|project).properties::(version\s?=\s?)(.+)::1
@(application|version).yml::(version:\s)(.+)::1
@(VERSION|version)?(.txt)::.+::0

Output

Project context based on current GitHub event

NameDescription
branchCurrent branch name or tag name
onDefaultBranchCheck whether current event is on default branch or not
onReleaseCheck whether current event is on release or not, that means isRelease && isTag
isBranchCheck whether current event is on branch or not
isPRCheck whether current event is on pull request or not
isTagCheck whether current event is on ref tag
isScheduleCheck whether current event is by schedule or not
isDispatchCheck whether current event is by manual or dispatch from another workflow or event from repository
isReleaseCheck whether current event is release event on regardless of branch, pull-request or tag
isHotfixCheck whether current event is hotfix event on regardless of branch, pull-request or tag
isAfterMergedReleasePRCheck whether current event is a merged commit after merged release pull request into default branch or not
isMergedCheck whether current event is merged PR
isClosedCheck whether current event is close PR but not merged into target branch
isOpenedCheck whether current event is open PR or create branch
prBaseBranchBase branch in pull request
commitMsgThe latest commit message
commitIdThe latest commit id
commitShortIdThe latest short commit id
versionCurrent tag version or release version
ci_mustFixVersionCI: Need to fix version to match with release name
ci_needPullRequestCI: Need to open new pull request for release or merge hotfix into default branch
ci_needTagCI: Need to tag new version if release branch is merged
ci_needUpgradeCI: Need to upgrade next version after release branch is merged into default branch
ci_isPushedCI: Check whether if auto commit is pushed to remote
ci_commitIdCI: auto commit id
ci_commitMsgCI: auto commit message
ci_changelog_generatedCI: changelog is generated
ci_changelog_releaseTagCI: changelog generated for release tag
ci_changelog_sinceTagCI: changelog generated since tag
ci_changelog_isCommittedCI: changelog is committed
ci_changelog_commitIdCI: changelog auto commit id
ci_changelog_commitMsgCI: changelog auto commit message
decision_buildDecision: Should run the next step: such as build & test.
Default value: !(ciPushed || isClosed || isMerged || (isBranch && (isRelease || isOpened)) || isAfterMergedReleasePR)
decision_publishShould publish artifact: such as push artifact to any registry.
Default value: decision.build && (onDefaultBranch || (isRelease && isTag))
ver_currentCurrent version in config file
ver_bumpedBumped version
ver_nextMajorSuggest next major version if after release and ver_current is compatible with semver
ver_nextMinorSuggest next minor version if after release and ver_current is compatible with semver
ver_nextPatchSuggest next patch version if after release and ver_current is compatible with semver

Note

Latest commit message

commitMsg is not available by default when synchronize/open pull-request. In case, you want to use the latest commit message in pull-request, need to tweak your build as below:

- uses: actions/checkout@v2with:
token: ${{ secrets.YOUR_GITHUB_TOKEN }}fetch-depth: 2
- uses: zero88/gh-project-context@v2

Use Cases

TBD

About

Query and update Project context

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages