Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/pull.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "1"
rules:
# Syncs upstream master to local
- base: master
upstream: action-rs:master
mergeMethod: hardreset
# Syncs modified master with upstream
- base: oxide/master
upstream: master
mergeMethod: hardreset
19 changes: 19 additions & 0 deletions README.oxide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Oxide fork documentation

This project is a fork of [actions-rs/toolchain](https://github.com/actions-rs/toolchain).

### Justification

This fork was created to assist our efforts in enabling automatic pinning of our rust toolchain using renovate and the `rust-toolchain.toml` file. The upstream project only has support for the first version of the `rust-toolchain` file which is simply the toolchain version and nothing else. [actions-rs/toolchain#209](https://github.com/actions-rs/toolchain/pull/209) was created upstream to enable `toml` to be used in the `rust-toolchain` file as well as supporting the `.toml` extension.

### When to delete this fork

After [actions-rs/toolchain#209](https://github.com/actions-rs/toolchain/pull/209) is merged upstream we may safely delete this fork and revert to using the upstream action.

### Structure of the fork

Following our [🔒 recommended approach](https://github.com/oxidecomputer/rfd/tree/master/rfd/0211) this project uses `oxide/master` as it's main branch with the original projects `master` being preserved. Any changes to the project should be merged into `oxide/master` _not_ `master`.

### Keeping the fork up-to-date

This project uses [wei/pull](https://github.com/wei/pull) to keep in sync with upstream changes. See `.github/pull.yml` for the relevant configuration.
13 changes: 13 additions & 0 deletions __tests__/args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,17 @@ describe("actions-rs/toolchain", () => {

expect(args.name).toBe("1.39.0");
});

it("supports toml override file", function () {
const rustToolchainFile = tempWriteSync(`
[toolchain]
channel = "stable"
`);

const args = morph(() => {
return getToolchainArgs(rustToolchainFile);
}, {});

expect(args.name).toBe("stable");
});
});
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ outputs:
description: Installed rustup version

runs:
using: 'node12'
using: 'node20'
main: 'dist/index.js'
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

10,170 changes: 10,156 additions & 14 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"@actions-rs/core": "^0.1.6",
"@actions/core": "^1.2.6",
"@actions/exec": "^1.0.4",
"@actions/io": "^1.0.2"
"@actions/io": "^1.0.2",
"fast-toml": "^0.5.4"
},
"devDependencies": {
"@types/jest": "^26.0.15",
Expand Down
24 changes: 20 additions & 4 deletions src/args.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { input } from "@actions-rs/core";
import { debug } from "@actions/core";
import { existsSync, readFileSync } from "fs";
import { parse } from "fast-toml";

export interface ToolchainOptions {
name: string;
Expand All @@ -19,20 +20,35 @@ function determineToolchain(overrideFile: string): string {
return toolchainInput;
}

if (!existsSync(overrideFile)) {
const toolchainPath = existsSync(overrideFile)
? overrideFile
: existsSync(`${overrideFile}.toml`)
? `${overrideFile}.toml`
: undefined;

if (!toolchainPath) {
throw new Error(
"toolchain input was not given and repository does not have a rust-toolchain file"
);
}

const rustToolchainFile = readFileSync(overrideFile, {
const rustToolchainFile = readFileSync(toolchainPath, {
encoding: "utf-8",
flag: "r",
}).trim();

debug(`using toolchain from rust-toolchain file: ${rustToolchainFile}`);
const toolchain = rustToolchainFile.includes("[toolchain]")
? parse<{ toolchain?: { channel?: string } }>(rustToolchainFile)
?.toolchain?.channel
: rustToolchainFile;

if (!toolchain) {
throw new Error(`channel is not specified in ${toolchainPath}`);
}

debug(`using toolchain from rust-toolchain file: ${toolchain}`);

return rustToolchainFile;
return toolchain;
}

export function getToolchainArgs(overrideFile: string): ToolchainOptions {
Expand Down
9 changes: 9 additions & 0 deletions types/fast-toml/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare module "fast-toml" {
export function parse<R extends Record<string, unknown>>(input: string): R;
export function parseFile<R extends Record<string, unknown>>(
file: string
): Promise<R>;
export function parseFileSync<R extends Record<string, unknown>>(
file: string
): R;
}