mirror of
https://github.com/obi1kenobi/cargo-semver-checks-action.git
synced 2024-11-21 15:49:30 +01:00
Add eslint and prettier (#10)
This commit is contained in:
parent
ea31db666e
commit
40af1490bc
8 changed files with 2709 additions and 49 deletions
9
.eslintrc.cjs
Normal file
9
.eslintrc.cjs
Normal file
|
@ -0,0 +1,9 @@
|
|||
module.exports = {
|
||||
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['@typescript-eslint'],
|
||||
root: true,
|
||||
rules: {
|
||||
'curly': 'error'
|
||||
}
|
||||
};
|
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
|
@ -8,8 +8,8 @@ on:
|
|||
|
||||
jobs:
|
||||
compare-dist:
|
||||
name: Check if compiled action in dist/ matches the source files
|
||||
uses: ./.github/workflows/compare-dist.yml
|
||||
name: Test build
|
||||
uses: ./.github/workflows/test-build.yml
|
||||
|
||||
test-action:
|
||||
name: Test the action on ubuntu-latest
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
name: Check if compiled action in dist/ matches the source files
|
||||
name: Test action build
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
|
||||
jobs:
|
||||
compare-dist:
|
||||
name: Check dist/
|
||||
test-build:
|
||||
name: Check if the source files build successfully and match dist/ directory
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout the action
|
||||
|
@ -23,17 +23,30 @@ jobs:
|
|||
- name: Install dependencies
|
||||
run: npm ci
|
||||
- name: Rebuild the action
|
||||
run: npm run build
|
||||
run: npm run all
|
||||
- name: Compare the expected and actual src/ directories
|
||||
run: |
|
||||
if [ "$(git diff src/ | wc -l)" -gt "0" ]; then
|
||||
echo "Source files are not properly formatted!"
|
||||
exit 1
|
||||
fi
|
||||
id: diff_src
|
||||
- name: Upload the expected version of src/ in case of failure
|
||||
uses: actions/upload-artifact@v3
|
||||
if: ${{ failure() && steps.diff_src.conclusion == 'failure' }}
|
||||
with:
|
||||
name: expected-src
|
||||
path: src/
|
||||
- name: Compare the expected and actual dist/ directories
|
||||
run: |
|
||||
if [ "$(git diff dist/ | wc -l)" -gt "0" ]; then
|
||||
echo "Detected uncommitted changes after build."
|
||||
echo "Built sources do not match the content of the dist/ directory!"
|
||||
exit 1
|
||||
fi
|
||||
id: diff
|
||||
- name: Upload the expected version in case of failure
|
||||
id: diff_dist
|
||||
- name: Upload the expected version of dist/ in case of failure
|
||||
uses: actions/upload-artifact@v3
|
||||
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
||||
if: ${{ failure() && steps.diff_dist.conclusion == 'failure' }}
|
||||
with:
|
||||
name: expected-dist
|
||||
path: dist/
|
4
.prettierrc.json
Normal file
4
.prettierrc.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"tabWidth": 4,
|
||||
"printWidth": 100
|
||||
}
|
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
2623
package-lock.json
generated
2623
package-lock.json
generated
File diff suppressed because it is too large
Load diff
15
package.json
15
package.json
|
@ -4,7 +4,11 @@
|
|||
"description": "Lint your crate API changes for semver violations.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "ncc build src/main.ts --license licenses.txt --minify"
|
||||
"build": "ncc build src/main.ts --license licenses.txt --minify",
|
||||
"format": "prettier --write src/**/*.ts",
|
||||
"format-check": "prettier --check src/**/*.ts",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"all": "npm run format && npm run lint && npm run build"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -20,15 +24,20 @@
|
|||
"dependencies": {
|
||||
"@actions-rs/core": "^0.1.6",
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/github": "^5.1.1",
|
||||
"@actions/io": "^1.1.2",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"@types/node-fetch": "^2.6.2",
|
||||
"@actions/exec": "^1.1.1"
|
||||
"@types/node-fetch": "^2.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.11.18",
|
||||
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
||||
"@typescript-eslint/parser": "^5.53.0",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"eslint": "^8.34.0",
|
||||
"eslint-config-prettier": "^8.6.0",
|
||||
"prettier": "^2.8.4",
|
||||
"typescript": "^4.9.5"
|
||||
}
|
||||
}
|
||||
|
|
72
src/main.ts
72
src/main.ts
|
@ -1,42 +1,43 @@
|
|||
import os = require('os');
|
||||
import os = require("os");
|
||||
|
||||
import * as exec from '@actions/exec';
|
||||
import * as core from '@actions/core';
|
||||
import * as github from '@actions/github';
|
||||
import * as io from '@actions/io';
|
||||
import * as toolCache from '@actions/tool-cache';
|
||||
import * as rustCore from '@actions-rs/core';
|
||||
import * as exec from "@actions/exec";
|
||||
import * as core from "@actions/core";
|
||||
import * as github from "@actions/github";
|
||||
import * as io from "@actions/io";
|
||||
import * as toolCache from "@actions/tool-cache";
|
||||
import * as rustCore from "@actions-rs/core";
|
||||
|
||||
function getPlatformMatchingTarget(): string {
|
||||
const platform = os.platform() as string;
|
||||
switch (platform) {
|
||||
case "linux":
|
||||
return "x86_64-unknown-linux-gnu"
|
||||
return "x86_64-unknown-linux-gnu";
|
||||
case "win32":
|
||||
return "x86_64-pc-windows-msvc"
|
||||
return "x86_64-pc-windows-msvc";
|
||||
case "darwin":
|
||||
return "x86_64-apple-darwin"
|
||||
return "x86_64-apple-darwin";
|
||||
default:
|
||||
throw new Error("Unsupported runner");
|
||||
}
|
||||
}
|
||||
|
||||
function optionIfValueProvided(option: string, value?: string): string {
|
||||
return value ? ` ${option} ${value}` : '';
|
||||
return value ? ` ${option} ${value}` : "";
|
||||
}
|
||||
|
||||
function getCheckReleaseArguments(): string[] {
|
||||
return [
|
||||
optionIfValueProvided('--package', rustCore.input.getInput('crate-name')),
|
||||
optionIfValueProvided('--manifest-path', rustCore.input.getInput('manifest-path')),
|
||||
rustCore.input.getInputBool('verbose') ? ' --verbose' : ''
|
||||
].filter(el => el != '');
|
||||
optionIfValueProvided("--package", rustCore.input.getInput("crate-name")),
|
||||
optionIfValueProvided("--manifest-path", rustCore.input.getInput("manifest-path")),
|
||||
rustCore.input.getInputBool("verbose") ? " --verbose" : "",
|
||||
].filter((el) => el != "");
|
||||
}
|
||||
|
||||
function getGitHubToken(): string {
|
||||
const token = process.env['GITHUB_TOKEN'] || rustCore.input.getInput('github-token');
|
||||
if (!token)
|
||||
throw new Error('Querying the GitHub API is possible only if the GitHub token is set.');
|
||||
const token = process.env["GITHUB_TOKEN"] || rustCore.input.getInput("github-token");
|
||||
if (!token) {
|
||||
throw new Error("Querying the GitHub API is possible only if the GitHub token is set.");
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
|
@ -44,12 +45,12 @@ async function getCargoSemverChecksDownloadURL(target: string): Promise<string>
|
|||
const octokit = github.getOctokit(getGitHubToken());
|
||||
|
||||
const getReleaseUrl = await octokit.rest.repos.getLatestRelease({
|
||||
owner: 'obi1kenobi',
|
||||
repo: 'cargo-semver-checks'
|
||||
owner: "obi1kenobi",
|
||||
repo: "cargo-semver-checks",
|
||||
});
|
||||
|
||||
const asset = getReleaseUrl.data.assets.find(asset => {
|
||||
return asset['name'].endsWith(`${target}.tar.gz`)
|
||||
const asset = getReleaseUrl.data.assets.find((asset) => {
|
||||
return asset["name"].endsWith(`${target}.tar.gz`);
|
||||
});
|
||||
|
||||
if (!asset) {
|
||||
|
@ -61,17 +62,18 @@ async function getCargoSemverChecksDownloadURL(target: string): Promise<string>
|
|||
|
||||
async function installRustUp(): Promise<void> {
|
||||
const rustup = await rustCore.RustUp.getOrInstall();
|
||||
await rustup.call(['show']);
|
||||
await rustup.setProfile('minimal');
|
||||
await rustup.installToolchain('stable');
|
||||
await rustup.call(["show"]);
|
||||
await rustup.setProfile("minimal");
|
||||
await rustup.installToolchain("stable");
|
||||
|
||||
// [TODO] Remove this temporary fix once the underlying issue is fixed.
|
||||
if (os.platform() == 'win32')
|
||||
exec.exec('mkdir C:\\Users\\runneradmin\\.cargo\\registry\\index');
|
||||
if (os.platform() == "win32") {
|
||||
exec.exec("mkdir C:\\Users\\runneradmin\\.cargo\\registry\\index");
|
||||
}
|
||||
}
|
||||
|
||||
async function runCargoSemverChecks(cargo: rustCore.Cargo): Promise<void> {
|
||||
await cargo.call(['semver-checks', 'check-release'].concat(getCheckReleaseArguments()));
|
||||
await cargo.call(["semver-checks", "check-release"].concat(getCheckReleaseArguments()));
|
||||
}
|
||||
|
||||
async function installCargoSemverChecksFromPrecompiledBinary(): Promise<void> {
|
||||
|
@ -79,7 +81,7 @@ async function installCargoSemverChecksFromPrecompiledBinary(): Promise<void> {
|
|||
|
||||
core.info(`downloading cargo-semver-checks from ${url}`);
|
||||
const tarballPath = await toolCache.downloadTool(url, undefined, `token ${getGitHubToken()}`, {
|
||||
accept: 'application/octet-stream'
|
||||
accept: "application/octet-stream",
|
||||
});
|
||||
core.info(`extracting ${tarballPath}`);
|
||||
const binPath = await toolCache.extractTar(tarballPath, undefined, ["xz"]);
|
||||
|
@ -88,22 +90,22 @@ async function installCargoSemverChecksFromPrecompiledBinary(): Promise<void> {
|
|||
}
|
||||
|
||||
async function installCargoSemverChecksUsingCargo(cargo: rustCore.Cargo): Promise<void> {
|
||||
await cargo.call(['install', 'cargo-semver-checks', '--locked']);
|
||||
await cargo.call(["install", "cargo-semver-checks", "--locked"]);
|
||||
}
|
||||
|
||||
async function installCargoSemverChecks(cargo: rustCore.Cargo): Promise<void> {
|
||||
if (await io.which('cargo-semver-checks') != '') {
|
||||
if ((await io.which("cargo-semver-checks")) != "") {
|
||||
return;
|
||||
}
|
||||
|
||||
core.info('cargo-semver-checks is not installed, installing now...');
|
||||
|
||||
core.info("cargo-semver-checks is not installed, installing now...");
|
||||
|
||||
try {
|
||||
await installCargoSemverChecksFromPrecompiledBinary();
|
||||
} catch (error: any) {
|
||||
core.info('Failed to download precompiled binary of cargo-semver-checks.');
|
||||
core.info("Failed to download precompiled binary of cargo-semver-checks.");
|
||||
core.info(`Error: ${error.message}`);
|
||||
core.info('Installing using cargo install...');
|
||||
core.info("Installing using cargo install...");
|
||||
|
||||
await installCargoSemverChecksUsingCargo(cargo);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue