Skip to content

Commit

Permalink
Merge pull request #1 from LKedward/fetch-latest-version
Browse files Browse the repository at this point in the history
Fetch latest version
  • Loading branch information
LKedward authored Dec 5, 2020
2 parents 44bcc26 + 811e4ae commit d8d3df7
Show file tree
Hide file tree
Showing 342 changed files with 144,048 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
use-bootstrap: [false, true]
fpm-version: ['v0.1.0']
fpm-version: ['v0.1.0','v0.1.1','latest']

steps:
- name: Checkout
Expand All @@ -17,6 +17,7 @@ jobs:
- name: fpm-setup
uses: ./ # Uses action in the root directory
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
fpm-version: ${{ matrix.fpm-version }}
use-bootstrap: ${{ matrix.use-bootstrap }}

Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ __GitHub Action to setup the [Fortran Package Manager](https://github.com/fortra
## Usage

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

## Options

__`use-bootstrap`__ (*optional,default:*`false`) whether to fetch and use the legacy 'bootstrap' implementation
__`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.

__`fpm-version`__ (*optional,default:*`'latest'`) the tag corresponding a Github release from which to fetch the `fpm` binary.
- 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'`.

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

__`fpm-repository`__ (*optional, default:* `https://github.com/fortran-lang/fpm`) which Github fork to fetch release binaries from.
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ branding:
color: purple
icon: package
inputs:
github-token:
description: 'API token needed to fetch latest fpm version'
required: false
default: 'none'
use-bootstrap:
description: 'Whether to use the bootstrap implementation of fpm'
required: false
default: false
fpm-version:
description: 'The tag of an fpm release'
required: false
default: 'v0.1.0'
default: 'latest'
fpm-repository:
description: 'Github repository (url) serving fpm releases'
required: false
Expand Down
38 changes: 37 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const tc = require('@actions/tool-cache');
const io = require('@actions/io');
const exec = require('@actions/exec');
const path = require('path');
const github = require('@actions/github');

// Main entry function
//
Expand All @@ -11,15 +12,36 @@ async function main(){
try {

// Get inputs
const token = core.getInput('github-token');

const useBootstrap = core.getInput('use-bootstrap').toLowerCase() === 'true';
console.log(`use-boostrap: ${useBootstrap}`);

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

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

// Get latest version if requested
if (fpmVersion === 'latest'){

if (token === 'none') {
core.setFailed('To fetch the latest fpm version, please supply a github token. Alternatively you can specify the fpm release version manually.');
}

try {

fpmVersion = await getLatestReleaseVersion(token);

} catch (error) {

core.setFailed('Error while querying the latest fpm release version - please check your github token.');

}

}

// Build download path
const fetchPath = fpmRepo + '/releases/download/' + fpmVersion + '/';
const filename = getFPMFilename(useBootstrap,fpmVersion,process.platform);
Expand Down Expand Up @@ -112,6 +134,20 @@ function getFPMFilename(useBootstrap,fpmVersion,platform){

}

// Query github API to find the tag for the latest release
//
async function getLatestReleaseVersion(token){

const octokit = github.getOctokit(token);

const {data: releases} = await octokit.repos.listReleases({
owner:'fortran-lang',
repo:'fpm'});

return releases[0].tag_name;

}


// Call entry function
main();
97 changes: 97 additions & 0 deletions node_modules/@actions/github/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions node_modules/@actions/github/lib/context.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions node_modules/@actions/github/lib/context.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/@actions/github/lib/context.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions node_modules/@actions/github/lib/github.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions node_modules/@actions/github/lib/github.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/@actions/github/lib/github.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d8d3df7

Please sign in to comment.