Skip to content

Dynamic language version matrix or value for your Github Actions workflows.

License

Notifications You must be signed in to change notification settings

ActionsToolbox/get-language-versions

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

ActionsToolbox logo
Github Build Status Release Commits since release

Overview

This action was inspired by latest-python-versions

Latest Language Version(s)

This action will fetch up-to-date data on the latest version(s) available on Github Actions for a given set of languages. It does this by first identifying the latest release (if the version source is in GitHub), and then extracting the information from the versions file of that latest release.

The reason behind this, if that most people will pin their action to the latest release instead of main or master, but developers can push new code into master which causes the action to fail.

If you wish to continue using the head of main or master, then we have added a new option 'use-head' which will do this instead.

Language GitHub Action Version Source
Go setup-go go-versions
Node / NodeJS setup-node node-versions
Perl setup-perl perl-versions
PHP setup-php php-versions
Python setup-python python-versions
Ruby setup-ruby ruby-versions
Terraform setup-terraform terraform-versions

If you're already running tests on multiple versions of a language, this action will allow you to replace your static matrix definitions with dynamic ones. It will also allow you to define a specific version if you are running a single version of a language.

Usage

To use the action, simply throw this into one of your workflows

- uses: ActionsToolbox/get-language-versions@master
  id: get-versions
  with:
    language: "python"
    min-version: 3.7            # not required - defaults to "EOL"
    max-version: 3.10           # not required - defaults to latest
    max-versions: 0             # not required - defaults to latest
    include-prereleases: true   # not required - defaults to false
    highest-only: true          # not required - defaults to false
    remove-patch-version: true  # not required - defaults to false

The action produces an output that can be accessed using:

${{ steps.get-versions.outputs.latest-versions }}

All Parameters

Parameters Required Default Options
language Yes Go, Node, Perl, PHP, Python, Ruby or Terraform.
min-version No "EOL" semver, "EOL" or "ALL"
max-version No "latest" semver or "latest"
max-versions No 0 0-N (N is number of versions to return.
include-prereleases No false true or false
highest-only No false true or false
remove-patch-version No false true or false
use-head No false true or false

See examples below for recommended usage.

Example

Matrix Example

This example will return a list of versions of Python from 3.8 up to and including the latest pre-release version. This is then converted into a matrix using fromJson.

name: Test

on: pull_request

jobs:
  linting:
    ...

  # Define the job to run before your matrix job
  get-versions:
    runs-on: ubuntu-latest
    outputs:
      version-matrix: ${{ steps.get-language-versions.outputs.latest-versions }}
    steps:
    - uses: ActionsToolbox/get-language-versions-action@master
      id: get-language-versions
      with:
        language: "python"
        min-version: 3.8
        include-prereleases: true

  # Then use the output from the previous job in the matrix definition
  test:
    needs: [linting, get-versions]
    runs-on: ubuntu-latest
    strategy:
      matrix:
        version: ${{ fromJson(needs.get-versions.outputs.version-matrix) }}
    steps:
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.version }}

Single Value Example

This example will return the highest non pre-release version of Python as a string which is then used in setup python for a single job.

name: Test

on: pull_request

jobs:
  linting:
    ...

  # Define the job to run before your matrix job
  get-versions:
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.get-language-versions.outputs.latest-versions }}
    steps:
    - uses: ActionsToolbox/get-language-versions-action@master
      id: get-language-versions
      with:
        language: "python"
        highest-only: true

  # Then use the output from the previous job in the matrix definition
  test:
    needs: [linting, get-versions]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ needs.get-versions.outputs.version }}

About

Dynamic language version matrix or value for your Github Actions workflows.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published