Skip to content

Commit 597c61f

Browse files
authored
Search compiler-specific fpm builds (#38)
2 parents 213b4d8 + 34b409b commit 597c61f

File tree

3 files changed

+66
-24
lines changed

3 files changed

+66
-24
lines changed

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,26 @@ __e.g.:__
2626

2727
__`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.
2828

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

3232
__`fpm-repository`__ (*optional, default:* `https://github.com/fortran-lang/fpm`) which Github fork to fetch release binaries from.
33+
34+
### Default `fpm-version` for Each Release
35+
36+
Starting with `v7`, `setup-fpm` is pinpointed to `fpm` version `v0.11.0` to ensure compatibility with newer features and changes.
37+
Previous versions default to the latest stable release, which is fetched automatically when `fpm-version` is set to `'latest'`.
38+
39+
| Release Version | Default `fpm-version` |
40+
|-----------------|-----------------------|
41+
| v1 | latest |
42+
| v2 | latest |
43+
| v3 | latest |
44+
| v4 | latest |
45+
| v5 | latest |
46+
| v6.0.1 | latest |
47+
| v6 | latest |
48+
| v6.1.0 | latest |
49+
| v7 | 0.11.0 |
50+
51+
Note: `fpm` changed asset naming convention starting version `v0.11.0`. So, the `latest` option will not work anymore with versions of `setup-fpm` prior to `v7`.

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ inputs:
1111
fpm-version:
1212
description: 'The tag of an fpm release'
1313
required: false
14-
default: 'latest'
14+
default: 'v0.11.0'
1515
fpm-repository:
1616
description: 'Github repository (url) serving fpm releases'
1717
required: false

index.js

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,43 @@ async function main(){
4343
const fetchPath = fpmRepo + '/releases/download/' + fpmVersion + '/';
4444
const filename = getFPMFilename(fpmVersion,process.platform);
4545

46-
console.log(`This platform is ${process.platform}`);
46+
console.log(`This platform is ${process.platform}`);
4747
console.log(`Fetching fpm from ${fetchPath}${filename}`);
4848

4949
// Download release
5050
var fpmPath;
5151
try {
52-
53-
fpmPath = await tc.downloadTool(fetchPath+filename);
52+
53+
// Try downloading the file without the compiler suffix
54+
const filename = getFPMFilename(fpmVersion, process.platform);
55+
fpmPath = await tc.downloadTool(fetchPath + filename);
5456

5557
} catch (error) {
58+
59+
// If download fails, try adding compiler suffixes
60+
const compilers = ['gcc-10', 'gcc-11', 'gcc-12', 'gcc-13', 'gcc-14'];
61+
62+
let success = false;
63+
64+
for (const compiler of compilers) {
65+
66+
// Generate the filename with the compiler suffix
67+
const filenameWithSuffix = getFPMFilename(fpmVersion, process.platform, compiler);
68+
console.log(`Trying to fetch compiler-built fpm: ${filenameWithSuffix}`);
69+
70+
try {
71+
fpmPath = await tc.downloadTool(fetchPath + filenameWithSuffix);
72+
success = true;
73+
break; // If download is successful, break out of the loop
74+
} catch (error) {
75+
console.log(` -> Failed to download ${filenameWithSuffix}`);
76+
}
77+
78+
}
5679

57-
core.setFailed(`Error while trying to fetch fpm - please check that a version exists at the above release url.`);
58-
80+
if (!success) {
81+
core.setFailed(`Error while trying to fetch fpm - please check that a version exists at the above release url.`);
82+
}
5983
}
6084

6185
console.log(fpmPath);
@@ -90,43 +114,42 @@ async function main(){
90114
}
91115
};
92116

93-
94117
// Construct the filename for an fpm release
95118
//
96-
// fpm-<version>-<os>-<arch>[.exe]
119+
// fpm-<version>-<os>-<arch>[-<compiler>][.exe]
97120
//
98121
// <version> is a string of form X.Y.Z corresponding to a release of fpm
99122
// <os> is either 'linux', 'macos', or 'windows'
100123
// <arch> here is always 'x86_64'
124+
// <compiler> is an optional string like '-gcc-12'
101125
//
102-
function getFPMFilename(fpmVersion,platform){
103-
126+
function getFPMFilename(fpmVersion, platform, compiler = '') {
104127
var filename = 'fpm-';
128+
129+
// Remove the leading 'v' if it exists
130+
filename += fpmVersion.replace('v', '') + '-';
105131

106-
filename += fpmVersion.replace('v','') + '-';
107-
132+
// Add the platform and architecture
108133
if (platform === 'linux') {
109-
110134
filename += 'linux-x86_64';
111-
112135
} else if (platform === 'darwin') {
113-
114136
filename += 'macos-x86_64';
115-
116137
} else if (platform === 'win32') {
117-
118-
filename += 'windows-x86_64.exe';
119-
138+
filename += 'windows-x86_64';
120139
} else {
121-
122140
core.setFailed('Unknown platform');
123-
124141
}
125142

126-
return filename;
143+
// If a compiler is provided, append it as a suffix
144+
if (compiler) filename += `-${compiler}`;
145+
146+
// Add the '.exe' suffix for Windows
147+
if (platform === 'win32') filename += '.exe';
127148

149+
return filename;
128150
}
129151

152+
130153
// Query github API to find the tag for the latest release
131154
//
132155
async function getLatestReleaseVersion(token){

0 commit comments

Comments
 (0)