Skip to content

Commit

Permalink
introduce perl-version-file input (#1367)
Browse files Browse the repository at this point in the history
* introduce perl-version-file input

* add a workflow for testing version file

* fix error

* update README
  • Loading branch information
shogo82148 committed Dec 11, 2022
1 parent 073403f commit e4e81df
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,32 @@ jobs:
cpanm --help
cpm --help
test-version-file:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: npm

- run: npm ci
- run: npm run build
- run: npm run package
- run: echo "5.30.0" > .perl-version

- id: setup-perl
name: use the action
uses: ./
with:
perl-version-file: ".perl-version"
- name: show the version
run: |
perl -V
format:
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ The action uses the latest Perl version available that matches the specified val
This defaults to `5`, which results in the latest available version of Perl 5.
In addition, the value `latest` is available, the actions uses the latest available version of Perl including `5`, `7` or later major versions.

- Default: `5`
### `perl-version-file`

Specifies the path to the version file such as `.perl-version`.

### `distribution`

Expand Down
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ author: "Ichinose Shogo"
inputs:
perl-version:
description: "The Perl version to download (if necessary) and use. Example: 5.30.0"
default: "5"
required: false
perl-version-file:
description: "File containing the Perl version. Example: .perl-version"
required: false
distribution:
description: |
Expand Down
19 changes: 18 additions & 1 deletion src/setup-perl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as exec from "@actions/exec";
import * as installer from "./installer";
import * as path from "path";
import * as crypto from "crypto";
import * as fs from "fs/promises";
import * as strawberry from "./strawberry";
import * as cpan from "./cpan-installer";
import { getPackagePath, parseBoolean } from "./utils";
Expand All @@ -12,7 +13,7 @@ async function run() {
const platform = process.platform;
let dist = core.getInput("distribution");
const multiThread = core.getInput("multi-thread");
const version = core.getInput("perl-version");
const version = await resolveVersionInput();

let result: installer.Result;
let perlHash: string;
Expand Down Expand Up @@ -95,4 +96,20 @@ async function digestOfPerlVersion(toolPath: string): Promise<string> {
return hash.digest("hex");
}

async function resolveVersionInput(): Promise<string> {
let version = core.getInput("perl-version");
const versionFile = core.getInput("perl-version-file");
if (version && versionFile) {
core.warning("Both perl-version and perl-version-file inputs are specified, only perl-version will be used");
}
if (version) {
return version;
}

const versionFilePath = path.join(process.env.GITHUB_WORKSPACE || "", versionFile || ".python-version");
version = await fs.readFile(versionFilePath, "utf8");
core.info(`Resolved ${versionFile} as ${version}`);
return version;
}

run();

0 comments on commit e4e81df

Please sign in to comment.