This action will read a chosen source file and extract the current version from it. It will then compare it to the project's known tags and, if a corresponding tag does not exist, it will be created.
Forked from Autotag, which worked specifically with Node projects. This approach is more flexible and works with different programming languages.
The following is an example .github/main.workflow
that will execute when a push
to the main
branch occurs. It will extract the current version number from package.json
:
name: My Workflow
on:
push:
paths:
- package.json
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- uses: onemedical/[email protected]
with:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
source_file: "package.json"
extraction_regex: "\\s*\"version\"s*:\\s*\"([\\d\\.]+)\""
To make this work, the workflow must have the checkout action before the tagging action.
This order is important!
- uses: actions/checkout@main
- uses: onemedical/[email protected]
If the repository is not checked out first, the action cannot find the chosen source file.
The GITHUB_TOKEN
, a source_file
and an extraction_regex
must be passed in. Without this, it is not possible to create a new tag. Make sure the autotag action looks like the following example:
- uses: onemedical/[email protected]
with:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
source_file: # the file in your repository that contains the version name
extraction_regex: # some regex pattern
The action will automatically extract the github token at runtime. DO NOT MANUALLY ENTER YOUR TOKEN. If you put the actual token in your workflow file, you're make it accessible in plaintext to anyone who ever views the repository (it will be in your git history).
There are a few options to customize how the tag is created.
-
tag_format
By default, the action will tag versions exactly as matched in the source file. Prefixes and suffixes can be used to add text around the tag name. For example, if the current version is
1.0.0
and thetag_format
is set tov{version} (beta)
, then the tag would be labeled asv1.0.0 (beta)
.- uses: onemedical/[email protected] with: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" source_file: "package.json" extraction_regex: "(\\d+\\.\\d+\\.\\d+)" tag_format: "v{version} (beta)"
-
tag_message
This is the annotated commit message associated with the tag. By default, a changelog will be generated from the commits between the latest tag and the new tag (HEAD). This will override that with a hard-coded message.
- uses: onemedical/[email protected] with: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" source_file: "project.toc" extraction_regex: "Version:\\s*(\\d+)" tag_message: "Custom message goes here."
If you are building an action that runs after this one, be aware this action produces several outputs:
tagname
will be empty if no tag was created, or it will be the value of the new tag.tagsha
: The SHA of the new tag.taguri
: The URI/URL of the new tag reference.tagmessage
: The message applied to the tag reference (this is what shows up on the tag screen on GitHub).version
will be the version attribute found in the chosen source file.