Skip to content

Commit d8d3df7

Browse files
authored
Merge pull request #1 from LKedward/fetch-latest-version
Fetch latest version
2 parents 44bcc26 + 811e4ae commit d8d3df7

File tree

342 files changed

+144048
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

342 files changed

+144048
-7
lines changed

.github/workflows/test-workflow.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
matrix:
99
os: [ubuntu-latest, macos-latest, windows-latest]
1010
use-bootstrap: [false, true]
11-
fpm-version: ['v0.1.0']
11+
fpm-version: ['v0.1.0','v0.1.1','latest']
1212

1313
steps:
1414
- name: Checkout
@@ -17,6 +17,7 @@ jobs:
1717
- name: fpm-setup
1818
uses: ./ # Uses action in the root directory
1919
with:
20+
github-token: ${{ secrets.GITHUB_TOKEN }}
2021
fpm-version: ${{ matrix.fpm-version }}
2122
use-bootstrap: ${{ matrix.use-bootstrap }}
2223

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ __GitHub Action to setup the [Fortran Package Manager](https://github.com/fortra
99
## Usage
1010

1111
```yaml
12-
- uses: lkedward/setup-fpm@v1
12+
- uses: lkedward/setup-fpm@v2
13+
with:
14+
github-token: ${{ secrets.GITHUB_TOKEN }}
1315
```
1416
1517
This will download the latest `fpm` version to the CI machine and add it to the path.
@@ -23,9 +25,11 @@ __e.g.:__
2325

2426
## Options
2527

26-
__`use-bootstrap`__ (*optional,default:*`false`) whether to fetch and use the legacy 'bootstrap' implementation
28+
__`github-token`__ (*only needed if `fpm-version` is `'latest'` or not specified*), an access token used to query the latest version of `fpm`. Set to `${{ secrets.GITHUB_TOKEN }}` to use the existing github actions token.
29+
30+
__`fpm-version`__ (*optional,default:*`'latest'`) the tag corresponding a Github release from which to fetch the `fpm` binary.
31+
- If set to `'latest'` (_default_) then the latest `fpm` release at [fortran-lang/fpm](https://github.com/fortran-lang/fpm/releases/latest) will be substituted. `github-token` must be provided if `fpm-version` is `'latest'`.
2732

28-
__`fpm-version`__ (*optional*) the tag corresponding a Github release from which to fetch the `fpm` binary.
29-
If omitted, the latest `fpm` release at [fortran-lang/fpm](https://github.com/fortran-lang/fpm/releases/latest) will be substituted.
33+
__`use-bootstrap`__ (*optional,default:*`false`) whether to fetch and use the legacy 'bootstrap' implementation
3034

3135
__`fpm-repository`__ (*optional, default:* `https://github.com/fortran-lang/fpm`) which Github fork to fetch release binaries from.

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ branding:
44
color: purple
55
icon: package
66
inputs:
7+
github-token:
8+
description: 'API token needed to fetch latest fpm version'
9+
required: false
10+
default: 'none'
711
use-bootstrap:
812
description: 'Whether to use the bootstrap implementation of fpm'
913
required: false
1014
default: false
1115
fpm-version:
1216
description: 'The tag of an fpm release'
1317
required: false
14-
default: 'v0.1.0'
18+
default: 'latest'
1519
fpm-repository:
1620
description: 'Github repository (url) serving fpm releases'
1721
required: false

index.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const tc = require('@actions/tool-cache');
33
const io = require('@actions/io');
44
const exec = require('@actions/exec');
55
const path = require('path');
6+
const github = require('@actions/github');
67

78
// Main entry function
89
//
@@ -11,15 +12,36 @@ async function main(){
1112
try {
1213

1314
// Get inputs
15+
const token = core.getInput('github-token');
16+
1417
const useBootstrap = core.getInput('use-bootstrap').toLowerCase() === 'true';
1518
console.log(`use-boostrap: ${useBootstrap}`);
1619

17-
const fpmVersion = core.getInput('fpm-version');
20+
fpmVersion = core.getInput('fpm-version');
1821
console.log(`fpm-version: ${fpmVersion}`);
1922

2023
const fpmRepo = core.getInput('fpm-repository');
2124
console.log(`fpm-repository: ${fpmRepo}`);
2225

26+
// Get latest version if requested
27+
if (fpmVersion === 'latest'){
28+
29+
if (token === 'none') {
30+
core.setFailed('To fetch the latest fpm version, please supply a github token. Alternatively you can specify the fpm release version manually.');
31+
}
32+
33+
try {
34+
35+
fpmVersion = await getLatestReleaseVersion(token);
36+
37+
} catch (error) {
38+
39+
core.setFailed('Error while querying the latest fpm release version - please check your github token.');
40+
41+
}
42+
43+
}
44+
2345
// Build download path
2446
const fetchPath = fpmRepo + '/releases/download/' + fpmVersion + '/';
2547
const filename = getFPMFilename(useBootstrap,fpmVersion,process.platform);
@@ -112,6 +134,20 @@ function getFPMFilename(useBootstrap,fpmVersion,platform){
112134

113135
}
114136

137+
// Query github API to find the tag for the latest release
138+
//
139+
async function getLatestReleaseVersion(token){
140+
141+
const octokit = github.getOctokit(token);
142+
143+
const {data: releases} = await octokit.repos.listReleases({
144+
owner:'fortran-lang',
145+
repo:'fpm'});
146+
147+
return releases[0].tag_name;
148+
149+
}
150+
115151

116152
// Call entry function
117153
main();

node_modules/@actions/github/README.md

Lines changed: 97 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/github/lib/context.d.ts

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/github/lib/context.js

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/github/lib/context.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/github/lib/github.d.ts

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/github/lib/github.js

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)