mirror of
https://github.com/obi1kenobi/cargo-semver-checks-action.git
synced 2024-11-21 23:49:33 +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:
|
jobs:
|
||||||
compare-dist:
|
compare-dist:
|
||||||
name: Check if compiled action in dist/ matches the source files
|
name: Test build
|
||||||
uses: ./.github/workflows/compare-dist.yml
|
uses: ./.github/workflows/test-build.yml
|
||||||
|
|
||||||
test-action:
|
test-action:
|
||||||
name: Test the action on ubuntu-latest
|
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:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
compare-dist:
|
test-build:
|
||||||
name: Check dist/
|
name: Check if the source files build successfully and match dist/ directory
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout the action
|
- name: Checkout the action
|
||||||
|
@ -23,17 +23,30 @@ jobs:
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
- name: Rebuild the action
|
- 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
|
- name: Compare the expected and actual dist/ directories
|
||||||
run: |
|
run: |
|
||||||
if [ "$(git diff dist/ | wc -l)" -gt "0" ]; then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
id: diff
|
id: diff_dist
|
||||||
- name: Upload the expected version in case of failure
|
- name: Upload the expected version of dist/ in case of failure
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
if: ${{ failure() && steps.diff_dist.conclusion == 'failure' }}
|
||||||
with:
|
with:
|
||||||
name: expected-dist
|
name: expected-dist
|
||||||
path: 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.",
|
"description": "Lint your crate API changes for semver violations.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"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": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -20,15 +24,20 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions-rs/core": "^0.1.6",
|
"@actions-rs/core": "^0.1.6",
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^1.10.0",
|
||||||
|
"@actions/exec": "^1.1.1",
|
||||||
"@actions/github": "^5.1.1",
|
"@actions/github": "^5.1.1",
|
||||||
"@actions/io": "^1.1.2",
|
"@actions/io": "^1.1.2",
|
||||||
"@actions/tool-cache": "^2.0.1",
|
"@actions/tool-cache": "^2.0.1",
|
||||||
"@types/node-fetch": "^2.6.2",
|
"@types/node-fetch": "^2.6.2"
|
||||||
"@actions/exec": "^1.1.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^18.11.18",
|
"@types/node": "^18.11.18",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
||||||
|
"@typescript-eslint/parser": "^5.53.0",
|
||||||
"@vercel/ncc": "^0.36.1",
|
"@vercel/ncc": "^0.36.1",
|
||||||
|
"eslint": "^8.34.0",
|
||||||
|
"eslint-config-prettier": "^8.6.0",
|
||||||
|
"prettier": "^2.8.4",
|
||||||
"typescript": "^4.9.5"
|
"typescript": "^4.9.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
70
src/main.ts
70
src/main.ts
|
@ -1,42 +1,43 @@
|
||||||
import os = require('os');
|
import os = require("os");
|
||||||
|
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from "@actions/exec";
|
||||||
import * as core from '@actions/core';
|
import * as core from "@actions/core";
|
||||||
import * as github from '@actions/github';
|
import * as github from "@actions/github";
|
||||||
import * as io from '@actions/io';
|
import * as io from "@actions/io";
|
||||||
import * as toolCache from '@actions/tool-cache';
|
import * as toolCache from "@actions/tool-cache";
|
||||||
import * as rustCore from '@actions-rs/core';
|
import * as rustCore from "@actions-rs/core";
|
||||||
|
|
||||||
function getPlatformMatchingTarget(): string {
|
function getPlatformMatchingTarget(): string {
|
||||||
const platform = os.platform() as string;
|
const platform = os.platform() as string;
|
||||||
switch (platform) {
|
switch (platform) {
|
||||||
case "linux":
|
case "linux":
|
||||||
return "x86_64-unknown-linux-gnu"
|
return "x86_64-unknown-linux-gnu";
|
||||||
case "win32":
|
case "win32":
|
||||||
return "x86_64-pc-windows-msvc"
|
return "x86_64-pc-windows-msvc";
|
||||||
case "darwin":
|
case "darwin":
|
||||||
return "x86_64-apple-darwin"
|
return "x86_64-apple-darwin";
|
||||||
default:
|
default:
|
||||||
throw new Error("Unsupported runner");
|
throw new Error("Unsupported runner");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function optionIfValueProvided(option: string, value?: string): string {
|
function optionIfValueProvided(option: string, value?: string): string {
|
||||||
return value ? ` ${option} ${value}` : '';
|
return value ? ` ${option} ${value}` : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCheckReleaseArguments(): string[] {
|
function getCheckReleaseArguments(): string[] {
|
||||||
return [
|
return [
|
||||||
optionIfValueProvided('--package', rustCore.input.getInput('crate-name')),
|
optionIfValueProvided("--package", rustCore.input.getInput("crate-name")),
|
||||||
optionIfValueProvided('--manifest-path', rustCore.input.getInput('manifest-path')),
|
optionIfValueProvided("--manifest-path", rustCore.input.getInput("manifest-path")),
|
||||||
rustCore.input.getInputBool('verbose') ? ' --verbose' : ''
|
rustCore.input.getInputBool("verbose") ? " --verbose" : "",
|
||||||
].filter(el => el != '');
|
].filter((el) => el != "");
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGitHubToken(): string {
|
function getGitHubToken(): string {
|
||||||
const token = process.env['GITHUB_TOKEN'] || rustCore.input.getInput('github-token');
|
const token = process.env["GITHUB_TOKEN"] || rustCore.input.getInput("github-token");
|
||||||
if (!token)
|
if (!token) {
|
||||||
throw new Error('Querying the GitHub API is possible only if the GitHub token is set.');
|
throw new Error("Querying the GitHub API is possible only if the GitHub token is set.");
|
||||||
|
}
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,12 +45,12 @@ async function getCargoSemverChecksDownloadURL(target: string): Promise<string>
|
||||||
const octokit = github.getOctokit(getGitHubToken());
|
const octokit = github.getOctokit(getGitHubToken());
|
||||||
|
|
||||||
const getReleaseUrl = await octokit.rest.repos.getLatestRelease({
|
const getReleaseUrl = await octokit.rest.repos.getLatestRelease({
|
||||||
owner: 'obi1kenobi',
|
owner: "obi1kenobi",
|
||||||
repo: 'cargo-semver-checks'
|
repo: "cargo-semver-checks",
|
||||||
});
|
});
|
||||||
|
|
||||||
const asset = getReleaseUrl.data.assets.find(asset => {
|
const asset = getReleaseUrl.data.assets.find((asset) => {
|
||||||
return asset['name'].endsWith(`${target}.tar.gz`)
|
return asset["name"].endsWith(`${target}.tar.gz`);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!asset) {
|
if (!asset) {
|
||||||
|
@ -61,17 +62,18 @@ async function getCargoSemverChecksDownloadURL(target: string): Promise<string>
|
||||||
|
|
||||||
async function installRustUp(): Promise<void> {
|
async function installRustUp(): Promise<void> {
|
||||||
const rustup = await rustCore.RustUp.getOrInstall();
|
const rustup = await rustCore.RustUp.getOrInstall();
|
||||||
await rustup.call(['show']);
|
await rustup.call(["show"]);
|
||||||
await rustup.setProfile('minimal');
|
await rustup.setProfile("minimal");
|
||||||
await rustup.installToolchain('stable');
|
await rustup.installToolchain("stable");
|
||||||
|
|
||||||
// [TODO] Remove this temporary fix once the underlying issue is fixed.
|
// [TODO] Remove this temporary fix once the underlying issue is fixed.
|
||||||
if (os.platform() == 'win32')
|
if (os.platform() == "win32") {
|
||||||
exec.exec('mkdir C:\\Users\\runneradmin\\.cargo\\registry\\index');
|
exec.exec("mkdir C:\\Users\\runneradmin\\.cargo\\registry\\index");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runCargoSemverChecks(cargo: rustCore.Cargo): Promise<void> {
|
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> {
|
async function installCargoSemverChecksFromPrecompiledBinary(): Promise<void> {
|
||||||
|
@ -79,7 +81,7 @@ async function installCargoSemverChecksFromPrecompiledBinary(): Promise<void> {
|
||||||
|
|
||||||
core.info(`downloading cargo-semver-checks from ${url}`);
|
core.info(`downloading cargo-semver-checks from ${url}`);
|
||||||
const tarballPath = await toolCache.downloadTool(url, undefined, `token ${getGitHubToken()}`, {
|
const tarballPath = await toolCache.downloadTool(url, undefined, `token ${getGitHubToken()}`, {
|
||||||
accept: 'application/octet-stream'
|
accept: "application/octet-stream",
|
||||||
});
|
});
|
||||||
core.info(`extracting ${tarballPath}`);
|
core.info(`extracting ${tarballPath}`);
|
||||||
const binPath = await toolCache.extractTar(tarballPath, undefined, ["xz"]);
|
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> {
|
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> {
|
async function installCargoSemverChecks(cargo: rustCore.Cargo): Promise<void> {
|
||||||
if (await io.which('cargo-semver-checks') != '') {
|
if ((await io.which("cargo-semver-checks")) != "") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info('cargo-semver-checks is not installed, installing now...');
|
core.info("cargo-semver-checks is not installed, installing now...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await installCargoSemverChecksFromPrecompiledBinary();
|
await installCargoSemverChecksFromPrecompiledBinary();
|
||||||
} catch (error: any) {
|
} 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(`Error: ${error.message}`);
|
||||||
core.info('Installing using cargo install...');
|
core.info("Installing using cargo install...");
|
||||||
|
|
||||||
await installCargoSemverChecksUsingCargo(cargo);
|
await installCargoSemverChecksUsingCargo(cargo);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue