Skip to content

Commit

Permalink
Fixes #43: OpenTofu 1.6 can no longer be downloaded (#44)
Browse files Browse the repository at this point in the history
* Fixes #43: OpenTofu 1.6 can no longer be downloaded

Signed-off-by: AbstractionFactory <[email protected]>

* More sane self-test

Signed-off-by: AbstractionFactory <[email protected]>

---------

Signed-off-by: AbstractionFactory <[email protected]>
  • Loading branch information
abstractionfactory authored Dec 10, 2024
1 parent 12f4deb commit 592200b
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 398 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/setup-tofu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
tofu-versions: [1.6.0-alpha1, latest]
tofu-versions: [1.6.0, latest]
tofu-wrapper: [true, false]
steps:
- name: Checkout
Expand Down
27 changes: 13 additions & 14 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
*/

class Build {
constructor (name, url) {
constructor (version, name) {
this.name = name;
this.url = url;
this.url = 'https://github.com/opentofu/opentofu/releases/download/v' + version + '/' + name;
}
}

class Release {
constructor (releaseMeta) {
this.version = releaseMeta.tag_name.replace('v', '');
this.builds = releaseMeta.assets.map(asset => new Build(asset.name, asset.browser_download_url));
this.version = releaseMeta.id.replace('v', '');
this.builds = releaseMeta.files.map(asset => new Build(this.version, asset));
}

getBuild (platform, arch) {
Expand All @@ -34,17 +34,12 @@ class Release {
* @return {Array<Release>} Releases.
*/
async function fetchReleases (githubToken) {
const url = 'https://api.github.com/repos/opentofu/opentofu/releases';
const url = 'https://get.opentofu.org/tofu/api.json';

const headers = {
Accept: 'application/vnd.github+json',
'X-GitHub-Api-Version': '2022-11-28'
Accept: 'application/json'
};

if (githubToken) {
headers.Authorization = `Bearer ${githubToken}`;
}

const resp = await fetch(url, {
headers
});
Expand All @@ -54,8 +49,12 @@ async function fetchReleases (githubToken) {
}

const releasesMeta = await resp.json();
/**
* @type {Array}
*/
const versions = releasesMeta.versions;

return releasesMeta.map(releaseMeta => new Release(releaseMeta));
return versions.map(releaseMeta => new Release(releaseMeta));
}

const semver = __nccwpck_require__(1383);
Expand Down Expand Up @@ -168,7 +167,7 @@ async function downloadAndExtractCLI (url) {
if (os.platform().startsWith('win')) {
core.debug(`OpenTofu CLI Download Path is ${pathToCLIZip}`);
const fixedPathToCLIZip = `${pathToCLIZip}.zip`;
io.mv(pathToCLIZip, fixedPathToCLIZip);
await io.mv(pathToCLIZip, fixedPathToCLIZip);
core.debug(`Moved download to ${fixedPathToCLIZip}`);
pathToCLI = await tc.extractZip(fixedPathToCLIZip);
} else {
Expand Down Expand Up @@ -225,7 +224,7 @@ async function addCredentials (credentialsHostname, credentialsToken, osPlat) {
credentials "${credentialsHostname}" {
token = "${credentialsToken}"
}`.trim();
// eslint-enable
// eslint-enable

// default to OS-specific path
let credsFile = osPlat === 'win32'
Expand Down
23 changes: 11 additions & 12 deletions lib/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
*/

class Build {
constructor (name, url) {
constructor (version, name) {
this.name = name;
this.url = url;
this.url = 'https://github.com/opentofu/opentofu/releases/download/v' + version + '/' + name;
}
}

class Release {
constructor (releaseMeta) {
this.version = releaseMeta.tag_name.replace('v', '');
this.builds = releaseMeta.assets.map(asset => new Build(asset.name, asset.browser_download_url));
this.version = releaseMeta.id.replace('v', '');
this.builds = releaseMeta.files.map(asset => new Build(this.version, asset));
}

getBuild (platform, arch) {
Expand All @@ -28,17 +28,12 @@ class Release {
* @return {Array<Release>} Releases.
*/
async function fetchReleases (githubToken) {
const url = 'https://api.github.com/repos/opentofu/opentofu/releases';
const url = 'https://get.opentofu.org/tofu/api.json';

const headers = {
Accept: 'application/vnd.github+json',
'X-GitHub-Api-Version': '2022-11-28'
Accept: 'application/json'
};

if (githubToken) {
headers.Authorization = `Bearer ${githubToken}`;
}

const resp = await fetch(url, {
headers
});
Expand All @@ -48,8 +43,12 @@ async function fetchReleases (githubToken) {
}

const releasesMeta = await resp.json();
/**
* @type {Array}
*/
const versions = releasesMeta.versions;

return releasesMeta.map(releaseMeta => new Release(releaseMeta));
return versions.map(releaseMeta => new Release(releaseMeta));
}

const semver = require('semver');
Expand Down
4 changes: 2 additions & 2 deletions lib/setup-tofu.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function downloadAndExtractCLI (url) {
if (os.platform().startsWith('win')) {
core.debug(`OpenTofu CLI Download Path is ${pathToCLIZip}`);
const fixedPathToCLIZip = `${pathToCLIZip}.zip`;
io.mv(pathToCLIZip, fixedPathToCLIZip);
await io.mv(pathToCLIZip, fixedPathToCLIZip);
core.debug(`Moved download to ${fixedPathToCLIZip}`);
pathToCLI = await tc.extractZip(fixedPathToCLIZip);
} else {
Expand Down Expand Up @@ -105,7 +105,7 @@ async function addCredentials (credentialsHostname, credentialsToken, osPlat) {
credentials "${credentialsHostname}" {
token = "${credentialsToken}"
}`.trim();
// eslint-enable
// eslint-enable

// default to OS-specific path
let credsFile = osPlat === 'win32'
Expand Down
Loading

0 comments on commit 592200b

Please sign in to comment.