Skip to content

Commit 9f44723

Browse files
authored
feat: show tflint version and set output (#353)
1 parent a8a2cbd commit 9f44723

File tree

4 files changed

+77
-10
lines changed

4 files changed

+77
-10
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ jobs:
9393
steps:
9494
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
9595
- name: Use Action
96+
id: setup-tflint
9697
uses: ./
9798
with:
9899
tflint_version: ${{ matrix.tflint_version }}
@@ -105,6 +106,20 @@ jobs:
105106
- name: Validate
106107
if: matrix.tflint_version == 'latest'
107108
run: tflint -v
109+
- name: Verify version output
110+
run: |
111+
if [[ "${{ matrix.tflint_version }}" == "latest" ]]; then
112+
expected=$(gh api repos/terraform-linters/tflint/releases/latest --jq '.tag_name' | sed 's/^v//')
113+
else
114+
version='${{ matrix.tflint_version }}'
115+
expected=${version:1}
116+
fi
117+
if [[ "${{ steps.setup-tflint.outputs.tflint-version }}" != "$expected" ]]; then
118+
echo "Expected version output '$expected', got '${{ steps.setup-tflint.outputs.tflint-version }}'"
119+
exit 1
120+
fi
121+
env:
122+
GH_TOKEN: ${{ github.token }}
108123

109124
integration-checksum:
110125
runs-on: ubuntu-latest

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ inputs:
2929
default: '~/.tflint.d/plugins'
3030
required: false
3131
outputs:
32+
tflint-version:
33+
description: The installed version of TFLint
3234
stdout:
3335
description: The output (stdout) produced by the tflint command. Only available if `tflint_wrapper` is set to `true`.
3436
stderr:

dist/index.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85094,6 +85094,8 @@ var external_os_ = __nccwpck_require__(70857);
8509485094
var external_path_ = __nccwpck_require__(16928);
8509585095
;// CONCATENATED MODULE: external "stream/promises"
8509685096
const promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("stream/promises");
85097+
// EXTERNAL MODULE: ./node_modules/@actions/exec/lib/exec.js
85098+
var exec = __nccwpck_require__(95236);
8509785099
// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js
8509885100
var io = __nccwpck_require__(94994);
8509985101
// EXTERNAL MODULE: ./node_modules/@actions/tool-cache/lib/tool-cache.js
@@ -88958,6 +88960,7 @@ async function restoreCache() {
8895888960

8895988961

8896088962

88963+
8896188964
/**
8896288965
* Get the GitHub platform architecture name
8896388966
* @param {string} arch - https://nodejs.org/api/os.html#os_os_arch
@@ -88991,7 +88994,6 @@ function getOctokit() {
8899188994

8899288995
async function getTFLintVersion(inputVersion) {
8899388996
if (!inputVersion || inputVersion === 'latest') {
88994-
core.debug('Requesting for [latest] version ...');
8899588997
const octokit = getOctokit();
8899688998
const response = await octokit.repos.getLatestRelease({
8899788999
owner: 'terraform-linters',
@@ -89012,8 +89014,9 @@ async function fileSHA256(filePath) {
8901289014
return hash.digest('hex');
8901389015
}
8901489016

89015-
async function downloadCLI(url, checksums) {
89016-
core.debug(`Downloading tflint CLI from ${url}`);
89017+
async function downloadCLI(url, checksums, version) {
89018+
core.info(`Attempting to download ${version}...`);
89019+
core.info(`Acquiring ${version} from ${url}`);
8901789020
const pathToCLIZip = await tool_cache.downloadTool(url);
8901889021

8901989022
if (checksums.length > 0) {
@@ -89030,7 +89033,7 @@ async function downloadCLI(url, checksums) {
8903089033
core.debug('SHA256 hash verified successfully');
8903189034
}
8903289035

89033-
core.debug('Extracting tflint CLI zip file');
89036+
core.info('Extracting...');
8903489037
const pathToCLI = await tool_cache.extractZip(pathToCLIZip);
8903589038
core.debug(`tflint CLI path is ${pathToCLI}.`);
8903689039

@@ -89074,7 +89077,7 @@ async function run() {
8907489077
core.debug(`Getting download URL for tflint version ${version}: ${platform} ${arch}`);
8907589078
const url = `https://github.com/terraform-linters/tflint/releases/download/${version}/tflint_${platform}_${arch}.zip`;
8907689079

89077-
const pathToCLI = await downloadCLI(url, checksums);
89080+
const pathToCLI = await downloadCLI(url, checksums, version);
8907889081

8907989082
if (wrapper) {
8908089083
await installWrapper(pathToCLI);
@@ -89085,6 +89088,29 @@ async function run() {
8908589088
const matchersPath = __nccwpck_require__.ab + "matchers.json";
8908689089
core.info(`##[add-matcher]${matchersPath}`);
8908789090

89091+
// Get and output actual installed version
89092+
try {
89093+
let stdout = '';
89094+
await exec.exec('tflint', ['--version'], {
89095+
listeners: {
89096+
stdout: (data) => {
89097+
stdout += data.toString();
89098+
},
89099+
},
89100+
});
89101+
89102+
const firstLine = stdout.split('\n')[0];
89103+
const match = firstLine.match(/TFLint version (.+)/);
89104+
if (match) {
89105+
const installedVersion = match[1];
89106+
core.setOutput('tflint-version', installedVersion);
89107+
} else {
89108+
core.warning('Unable to parse tflint version from output');
89109+
}
89110+
} catch (error) {
89111+
core.warning(`Failed to get tflint version: ${error.message}`);
89112+
}
89113+
8908889114
return version;
8908989115
} catch (ex) {
8909089116
core.error(ex);

src/setup-tflint.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import path from 'path';
55
import { pipeline } from 'stream/promises';
66

77
import core from '@actions/core';
8+
import exec from '@actions/exec';
89
import io from '@actions/io';
910
import * as tc from '@actions/tool-cache';
1011
import { Octokit } from '@octokit/rest';
@@ -44,7 +45,6 @@ function getOctokit() {
4445

4546
async function getTFLintVersion(inputVersion) {
4647
if (!inputVersion || inputVersion === 'latest') {
47-
core.debug('Requesting for [latest] version ...');
4848
const octokit = getOctokit();
4949
const response = await octokit.repos.getLatestRelease({
5050
owner: 'terraform-linters',
@@ -65,8 +65,9 @@ async function fileSHA256(filePath) {
6565
return hash.digest('hex');
6666
}
6767

68-
async function downloadCLI(url, checksums) {
69-
core.debug(`Downloading tflint CLI from ${url}`);
68+
async function downloadCLI(url, checksums, version) {
69+
core.info(`Attempting to download ${version}...`);
70+
core.info(`Acquiring ${version} from ${url}`);
7071
const pathToCLIZip = await tc.downloadTool(url);
7172

7273
if (checksums.length > 0) {
@@ -83,7 +84,7 @@ async function downloadCLI(url, checksums) {
8384
core.debug('SHA256 hash verified successfully');
8485
}
8586

86-
core.debug('Extracting tflint CLI zip file');
87+
core.info('Extracting...');
8788
const pathToCLI = await tc.extractZip(pathToCLIZip);
8889
core.debug(`tflint CLI path is ${pathToCLI}.`);
8990

@@ -127,7 +128,7 @@ async function run() {
127128
core.debug(`Getting download URL for tflint version ${version}: ${platform} ${arch}`);
128129
const url = `https://github.com/terraform-linters/tflint/releases/download/${version}/tflint_${platform}_${arch}.zip`;
129130

130-
const pathToCLI = await downloadCLI(url, checksums);
131+
const pathToCLI = await downloadCLI(url, checksums, version);
131132

132133
if (wrapper) {
133134
await installWrapper(pathToCLI);
@@ -138,6 +139,29 @@ async function run() {
138139
const matchersPath = path.join(__dirname, '..', '.github', 'matchers.json');
139140
core.info(`##[add-matcher]${matchersPath}`);
140141

142+
// Get and output actual installed version
143+
try {
144+
let stdout = '';
145+
await exec.exec('tflint', ['--version'], {
146+
listeners: {
147+
stdout: (data) => {
148+
stdout += data.toString();
149+
},
150+
},
151+
});
152+
153+
const firstLine = stdout.split('\n')[0];
154+
const match = firstLine.match(/TFLint version (.+)/);
155+
if (match) {
156+
const installedVersion = match[1];
157+
core.setOutput('tflint-version', installedVersion);
158+
} else {
159+
core.warning('Unable to parse tflint version from output');
160+
}
161+
} catch (error) {
162+
core.warning(`Failed to get tflint version: ${error.message}`);
163+
}
164+
141165
return version;
142166
} catch (ex) {
143167
core.error(ex);

0 commit comments

Comments
 (0)