Skip to content

Use ubuntu-latest instead of fixed version #47

Use ubuntu-latest instead of fixed version

Use ubuntu-latest instead of fixed version #47

# Summary:
# Automatically tag and release when changes land on the "main" branch.
# It uses "semantic-version" to resolve the next version to use, and then we use GitHub CLI to create or update the releases.
#
# See https://github.com/PaulHatch/semantic-version https://github.com/PaulHatch/semantic-version/tree/v5.0.2
# See https://github.com/softprops/action-gh-release https://github.com/softprops/action-gh-release/tree/v1
name: 'Auto release (release candidate)'
on:
push:
branches-ignore:
- main
jobs:
tag-and-release:
runs-on: ubuntu-latest
steps:
- name: Fetching all commits for the current branch
uses: actions/checkout@v3
with:
fetch-depth: 0 # Force fetch all commits - See https://github.com/PaulHatch/semantic-version#important-note-regarding-the-checkout-action
- run: "echo \"GITHUB_SHA: ${{ github.sha }}\""
# Outputs documentation: https://github.com/PaulHatch/semantic-version/blob/master/src/main.ts#L22-L33
- name: Resolving next Release Candidate version using semantic-version
uses: paulhatch/[email protected]
id: next_semantic_version
with: # See https://github.com/PaulHatch/semantic-version#usage
tag_prefix: "v" # The prefix to use to identify tags
major_pattern: "(MAJOR)" # A string which, if present in a git commit, indicates that a change represents a major (breaking) change
minor_pattern: "(MINOR)" # Same as above except indicating a minor change
version_format: "${major}.${minor}.${patch}-rc.${increment}" # A string to determine the format of the version output
bump_each_commit: false # If this input is set to true, every commit will be treated as a new version, bumping the patch, minor, or major version based on the commit message.
- name: Printing semantic-version outputs (for debugging)
run: |
echo "Most useful outputs:"
echo "Next version: ${{steps.next_semantic_version.outputs.version}}"
echo "Next version tag: ${{steps.next_semantic_version.outputs.version_tag}}"
echo -e "\n All outputs:"
echo "version: ${{steps.next_semantic_version.outputs.version}}"
echo "major: ${{steps.next_semantic_version.outputs.major}}"
echo "minor: ${{steps.next_semantic_version.outputs.minor}}"
echo "patch: ${{steps.next_semantic_version.outputs.patch}}"
echo "increment: ${{steps.next_semantic_version.outputs.increment}}"
echo "version_type: ${{steps.next_semantic_version.outputs.version_type}}"
echo "changed: ${{steps.next_semantic_version.outputs.changed}}"
echo "authors: ${{steps.next_semantic_version.outputs.authors}}"
echo "version_tag: ${{steps.next_semantic_version.outputs.version_tag}}"
echo "previous_commit: ${{steps.next_semantic_version.outputs.previous_commit}}"
echo "current_commit: ${{steps.next_semantic_version.outputs.current_commit}}"
# Check if the major version already exists (if it doesn't, we'll create it - if it does, we'll update it)
- name: Check if tag "v${{steps.next_semantic_version.outputs.major}}-rc" exists
uses: mukunku/[email protected]
id: majorTagExists
with: # See https://github.com/mukunku/tag-exists-action#inputs
tag: "v${{steps.next_semantic_version.outputs.major}}-rc"
- run: "echo \"Check if majorTagExists: ${{ steps.majorTagExists.outputs.exists }}\""
# See https://cli.github.com/manual/gh_release_create
- name: Creating new release for the major "v${{steps.next_semantic_version.outputs.major}}-rc" version
if: ${{ steps.majorTagExists.outputs.exists == 'false' }}
run: |
gh release create v${{steps.next_semantic_version.outputs.major}}-rc \
--title "v${{steps.next_semantic_version.outputs.major}}-rc MAJOR release (auto-updated)" \
--generate-notes \
--prerelease \
--target "${{github.sha}}"
env:
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
# See https://cli.github.com/manual/gh_release_edit
- name: Recreating existing release for the major "v${{steps.next_semantic_version.outputs.major}}-rc" version
if: ${{ steps.majorTagExists.outputs.exists == 'true' }}
run: |
# Delete and create the release again
gh release delete v${{steps.next_semantic_version.outputs.major}}-rc --cleanup-tag --yes
gh release create v${{steps.next_semantic_version.outputs.major}}-rc \
--title "v${{steps.next_semantic_version.outputs.major}}-rc MAJOR release (auto-updated)" \
--generate-notes \
--prerelease \
--target "${{github.sha}}"
env:
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
# Check if the minor version already exists (if it doesn't, we'll create it - if it does, we'll update it)
- name: Check if tag "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}-rc" exists
uses: mukunku/[email protected]
id: minorTagExists
with: # See https://github.com/mukunku/tag-exists-action#inputs
tag: "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}-rc"
- run: "echo \"Check if minorTagExists: ${{ steps.minorTagExists.outputs.exists }}\""
# See https://cli.github.com/manual/gh_release_create
- name: Creating new release for the minor "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}-rc" version
if: ${{ steps.minorTagExists.outputs.exists == 'false' }}
run: |
gh release create v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}-rc \
--title "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}-rc MINOR release (auto-updated)" \
--generate-notes \
--prerelease \
--target "${{github.sha}}"
env:
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
# See https://cli.github.com/manual/gh_release_edit
- name: Recreating existing release for the minor "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}-rc" version
if: ${{ steps.minorTagExists.outputs.exists == 'true' }}
run: |
# Delete and create the release again
gh release delete v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}-rc --cleanup-tag --yes
gh release create v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}-rc \
--title "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}-rc MINOR release (auto-updated)" \
--generate-notes \
--prerelease \
--target "${{github.sha}}"
env:
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"