mirror of
https://github.com/obi1kenobi/cargo-semver-checks-action.git
synced 2024-11-25 09:29:32 +01:00
* Setting environmental variables * Test the action also on 1.67
This commit is contained in:
parent
f9ffdc4a3d
commit
f2825830a8
8 changed files with 102 additions and 79 deletions
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
|
@ -8,7 +8,6 @@ on:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
RUST_BACKTRACE: 1
|
RUST_BACKTRACE: 1
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-build:
|
test-build:
|
||||||
|
@ -18,11 +17,6 @@ jobs:
|
||||||
test-action:
|
test-action:
|
||||||
name: Smoke test the action
|
name: Smoke test the action
|
||||||
uses: ./.github/workflows/test-action.yml
|
uses: ./.github/workflows/test-action.yml
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
with:
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
|
|
||||||
test-inputs:
|
test-inputs:
|
||||||
name: Test action inputs
|
name: Test action inputs
|
||||||
|
|
15
.github/workflows/test-action.yml
vendored
15
.github/workflows/test-action.yml
vendored
|
@ -5,19 +5,18 @@ name: Smoke test the action
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
inputs:
|
|
||||||
runs-on:
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
RUST_BACKTRACE: 1
|
RUST_BACKTRACE: 1
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
run-tests:
|
run-tests:
|
||||||
name: Run tests
|
name: Run tests
|
||||||
runs-on: ${{ inputs.runs-on }}
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
toolchain: ['1.66', '1.67', 'stable', 'beta', 'nightly']
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout the test repository and test with patch change and patch version bump
|
- name: Checkout the test repository and test with patch change and patch version bump
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
@ -31,6 +30,8 @@ jobs:
|
||||||
path: action
|
path: action
|
||||||
- name: Run the action
|
- name: Run the action
|
||||||
uses: ./action/
|
uses: ./action/
|
||||||
|
with:
|
||||||
|
rust-toolchain: ${{ matrix.toolchain }}
|
||||||
- name: Checkout the test with major change and patch version bump
|
- name: Checkout the test with major change and patch version bump
|
||||||
run: |
|
run: |
|
||||||
git fetch origin major_change
|
git fetch origin major_change
|
||||||
|
@ -38,6 +39,8 @@ jobs:
|
||||||
- name: Run the action (allowed to fail)
|
- name: Run the action (allowed to fail)
|
||||||
id: action_major
|
id: action_major
|
||||||
uses: ./action/
|
uses: ./action/
|
||||||
|
with:
|
||||||
|
rust-toolchain: ${{ matrix.toolchain }}
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
- name: Fail if the action has not returned any errors (but it should have)
|
- name: Fail if the action has not returned any errors (but it should have)
|
||||||
if: steps.action_major.outcome != 'failure'
|
if: steps.action_major.outcome != 'failure'
|
||||||
|
|
3
.github/workflows/test-cache.yml
vendored
3
.github/workflows/test-cache.yml
vendored
|
@ -6,6 +6,9 @@ name: Test rustdoc caching
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
|
|
||||||
|
env:
|
||||||
|
RUST_BACKTRACE: 1
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-cache-exists:
|
test-cache-exists:
|
||||||
name: Check if the cache exists after running the action
|
name: Check if the cache exists after running the action
|
||||||
|
|
1
.github/workflows/test-inputs.yml
vendored
1
.github/workflows/test-inputs.yml
vendored
|
@ -8,7 +8,6 @@ on:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
RUST_BACKTRACE: 1
|
RUST_BACKTRACE: 1
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-package-patch:
|
test-package-patch:
|
||||||
|
|
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
49
src/main.ts
49
src/main.ts
|
@ -1,5 +1,3 @@
|
||||||
import os = require("os");
|
|
||||||
|
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import * as github from "@actions/github";
|
import * as github from "@actions/github";
|
||||||
|
@ -7,36 +5,16 @@ 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";
|
||||||
|
|
||||||
|
import {
|
||||||
|
getErrorMessage,
|
||||||
|
getPlatformMatchingTarget,
|
||||||
|
getRustcVersion,
|
||||||
|
optionIfValueProvided,
|
||||||
|
} from "./utils";
|
||||||
import { RustdocCache } from "./rustdoc-cache";
|
import { RustdocCache } from "./rustdoc-cache";
|
||||||
|
|
||||||
const CARGO_TARGET_DIR = path.join("semver-checks", "target");
|
const CARGO_TARGET_DIR = path.join("semver-checks", "target");
|
||||||
|
|
||||||
function getErrorMessage(error: unknown): string {
|
|
||||||
if (error instanceof Error) {
|
|
||||||
return error.message;
|
|
||||||
} else {
|
|
||||||
return String(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getPlatformMatchingTarget(): string {
|
|
||||||
const platform = os.platform() as string;
|
|
||||||
switch (platform) {
|
|
||||||
case "linux":
|
|
||||||
return "x86_64-unknown-linux-gnu";
|
|
||||||
case "win32":
|
|
||||||
return "x86_64-pc-windows-msvc";
|
|
||||||
case "darwin":
|
|
||||||
return "x86_64-apple-darwin";
|
|
||||||
default:
|
|
||||||
throw new Error("Unsupported runner");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function optionIfValueProvided(option: string, value?: string): string[] {
|
|
||||||
return value ? [option, value] : [];
|
|
||||||
}
|
|
||||||
|
|
||||||
function getCheckReleaseArguments(): string[] {
|
function getCheckReleaseArguments(): string[] {
|
||||||
return [
|
return [
|
||||||
optionIfValueProvided("--package", rustCore.input.getInput("package")),
|
optionIfValueProvided("--package", rustCore.input.getInput("package")),
|
||||||
|
@ -84,6 +62,21 @@ async function installRustUpIfRequested(): Promise<void> {
|
||||||
// by this action, so it will not override the default toolchain globally.
|
// by this action, so it will not override the default toolchain globally.
|
||||||
process.env["RUSTUP_TOOLCHAIN"] = toolchain;
|
process.env["RUSTUP_TOOLCHAIN"] = toolchain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Disable incremental compilation.
|
||||||
|
process.env["CARGO_INCREMENTAL"] ||= "0";
|
||||||
|
|
||||||
|
// Enable colors in the output.
|
||||||
|
process.env["CARGO_TERM_COLOR"] ||= "always";
|
||||||
|
|
||||||
|
// Enable sparse checkout for crates.io except for Rust 1.66 and 1.67,
|
||||||
|
// on which it is unstable.
|
||||||
|
if (!process.env["CARGO_REGISTRIES_CRATES_IO_PROTOCOL"]) {
|
||||||
|
const rustcVersion = await getRustcVersion();
|
||||||
|
if (!rustcVersion.startsWith("rustc-1.66") && !rustcVersion.startsWith("rustc-1.67")) {
|
||||||
|
process.env["CARGO_REGISTRIES_CRATES_IO_PROTOCOL"] = "sparse";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runCargoSemverChecks(cargo: rustCore.Cargo): Promise<void> {
|
async function runCargoSemverChecks(cargo: rustCore.Cargo): Promise<void> {
|
||||||
|
|
|
@ -1,33 +1,11 @@
|
||||||
import os = require("os");
|
import os = require("os");
|
||||||
import hashFiles = require("hash-files");
|
|
||||||
|
|
||||||
import * as exec from "@actions/exec";
|
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import * as cache from "@actions/cache";
|
import * as cache from "@actions/cache";
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import * as rustCore from "@actions-rs/core";
|
import * as rustCore from "@actions-rs/core";
|
||||||
|
|
||||||
function makeExecOptions(stdout: { s: string }): exec.ExecOptions {
|
import { getCargoSemverChecksVersion, getRustcVersion, hashFilesOrEmpty } from "./utils";
|
||||||
return {
|
|
||||||
listeners: {
|
|
||||||
stdout: (buffer: Buffer): void => {
|
|
||||||
stdout.s += buffer.toString();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeWhitespaces(str: string): string {
|
|
||||||
return str.trim().replace(/\s/g, "-");
|
|
||||||
}
|
|
||||||
|
|
||||||
function hashFilesOrEmpty(patterns: string[]): string {
|
|
||||||
try {
|
|
||||||
return hashFiles.sync({ files: patterns });
|
|
||||||
} catch (error) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class RustdocCache {
|
export class RustdocCache {
|
||||||
private readonly cargo;
|
private readonly cargo;
|
||||||
|
@ -77,8 +55,8 @@ export class RustdocCache {
|
||||||
rustCore.input.getInput("prefix-key") || "",
|
rustCore.input.getInput("prefix-key") || "",
|
||||||
rustCore.input.getInput("cache-key"),
|
rustCore.input.getInput("cache-key"),
|
||||||
os.platform() as string,
|
os.platform() as string,
|
||||||
await this.getRustcVersion(),
|
await getRustcVersion(),
|
||||||
await this.getCargoSemverChecksVersion(),
|
await getCargoSemverChecksVersion(this.cargo),
|
||||||
this.getCargoLocksHash(),
|
this.getCargoLocksHash(),
|
||||||
"semver-checks-rustdoc",
|
"semver-checks-rustdoc",
|
||||||
].join("-");
|
].join("-");
|
||||||
|
@ -94,16 +72,4 @@ export class RustdocCache {
|
||||||
private getCargoLocksHash(): string {
|
private getCargoLocksHash(): string {
|
||||||
return hashFilesOrEmpty([path.join(this.workspaceRoot, "**", "Cargo.lock")]);
|
return hashFilesOrEmpty([path.join(this.workspaceRoot, "**", "Cargo.lock")]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getRustcVersion(): Promise<string> {
|
|
||||||
const stdout = { s: "" };
|
|
||||||
await exec.exec("rustc", ["--version"], makeExecOptions(stdout));
|
|
||||||
return removeWhitespaces(stdout.s);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async getCargoSemverChecksVersion(): Promise<string> {
|
|
||||||
const stdout = { s: "" };
|
|
||||||
await this.cargo.call(["semver-checks", "--version"], makeExecOptions(stdout));
|
|
||||||
return removeWhitespaces(stdout.s);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
65
src/utils.ts
Normal file
65
src/utils.ts
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
import os = require("os");
|
||||||
|
import hashFiles = require("hash-files");
|
||||||
|
|
||||||
|
import * as exec from "@actions/exec";
|
||||||
|
import * as rustCore from "@actions-rs/core";
|
||||||
|
|
||||||
|
export function getErrorMessage(error: unknown): string {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return error.message;
|
||||||
|
} else {
|
||||||
|
return String(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPlatformMatchingTarget(): string {
|
||||||
|
const platform = os.platform() as string;
|
||||||
|
switch (platform) {
|
||||||
|
case "linux":
|
||||||
|
return "x86_64-unknown-linux-gnu";
|
||||||
|
case "win32":
|
||||||
|
return "x86_64-pc-windows-msvc";
|
||||||
|
case "darwin":
|
||||||
|
return "x86_64-apple-darwin";
|
||||||
|
default:
|
||||||
|
throw new Error("Unsupported runner");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function optionIfValueProvided(option: string, value?: string): string[] {
|
||||||
|
return value ? [option, value] : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hashFilesOrEmpty(patterns: string[]): string {
|
||||||
|
try {
|
||||||
|
return hashFiles.sync({ files: patterns });
|
||||||
|
} catch (error) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeExecOptions(stdout: { s: string }): exec.ExecOptions {
|
||||||
|
return {
|
||||||
|
listeners: {
|
||||||
|
stdout: (buffer: Buffer): void => {
|
||||||
|
stdout.s += buffer.toString();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeWhitespaces(str: string): string {
|
||||||
|
return str.trim().replace(/\s/g, "-");
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getRustcVersion(): Promise<string> {
|
||||||
|
const stdout = { s: "" };
|
||||||
|
await exec.exec("rustc", ["--version"], makeExecOptions(stdout));
|
||||||
|
return removeWhitespaces(stdout.s);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getCargoSemverChecksVersion(cargo: rustCore.Cargo): Promise<string> {
|
||||||
|
const stdout = { s: "" };
|
||||||
|
await cargo.call(["semver-checks", "--version"], makeExecOptions(stdout));
|
||||||
|
return removeWhitespaces(stdout.s);
|
||||||
|
}
|
Loading…
Reference in a new issue