mirror of
				https://github.com/actions-rs/toolchain.git
				synced 2025-10-31 19:33:53 +00:00 
			
		
		
		
	Allow to override toolchain from rust-toolchain file (#35)
This commit is contained in:
		
							parent
							
								
									e2aeba25b2
								
							
						
					
					
						commit
						6a1db6369e
					
				
							
								
								
									
										15
									
								
								.githooks/pre-commit
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										15
									
								
								.githooks/pre-commit
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,15 @@ | |||||||
|  | #!/bin/bash | ||||||
|  | 
 | ||||||
|  | # This commit hook checks whether we ran `npm run build` when committed TypeScript files. | ||||||
|  | # For GitHub actions to work, we need to check the compiled JavaScript into VCS. | ||||||
|  | # | ||||||
|  | # This script can yield false positives in cases where you only make stylistic changes to the TypeScript code that don't result in changes to the compiled JavaScript code. | ||||||
|  | # It is your responsibility as a developer to then commit the changes with `git commit --no-verify` and simply skip this commit hook. | ||||||
|  | 
 | ||||||
|  | TS_FILES=$(git diff --staged --name-only | grep -c '.ts') | ||||||
|  | DIST_MODIFIED=$(git diff --staged --name-only | grep -c dist/index.js) | ||||||
|  | 
 | ||||||
|  | if [ $TS_FILES -gt 0 ] && [ $DIST_MODIFIED -eq 0 ] ; then | ||||||
|  |     echo "You modified TypeScript files but apparently did not run 'npm run build'". | ||||||
|  |     exit 1; | ||||||
|  | fi | ||||||
							
								
								
									
										14
									
								
								.github/workflows/ci.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										14
									
								
								.github/workflows/ci.yml
									
									
									
									
										vendored
									
									
								
							| @ -1,9 +1,9 @@ | |||||||
| name: Continuous integration | name: Continuous integration | ||||||
| 
 | 
 | ||||||
| on: [push] | on: [push, pull_request] | ||||||
| 
 | 
 | ||||||
| jobs: | jobs: | ||||||
|   check_pr: |   test: | ||||||
|     runs-on: ubuntu-latest |     runs-on: ubuntu-latest | ||||||
|     steps: |     steps: | ||||||
|       - name: Create npm configuration |       - name: Create npm configuration | ||||||
| @ -18,7 +18,6 @@ jobs: | |||||||
| 
 | 
 | ||||||
|   install_stable: |   install_stable: | ||||||
|     runs-on: ubuntu-latest |     runs-on: ubuntu-latest | ||||||
|     needs: check_pr |  | ||||||
|     steps: |     steps: | ||||||
|       - uses: actions/checkout@v1 |       - uses: actions/checkout@v1 | ||||||
|       - uses: ./ |       - uses: ./ | ||||||
| @ -27,7 +26,6 @@ jobs: | |||||||
| 
 | 
 | ||||||
|   install_nightly: |   install_nightly: | ||||||
|     runs-on: ubuntu-latest |     runs-on: ubuntu-latest | ||||||
|     needs: check_pr |  | ||||||
|     steps: |     steps: | ||||||
|       - uses: actions/checkout@v1 |       - uses: actions/checkout@v1 | ||||||
|       - uses: ./ |       - uses: ./ | ||||||
| @ -39,7 +37,6 @@ jobs: | |||||||
|   install_stable_in_docker: |   install_stable_in_docker: | ||||||
|     runs-on: ubuntu-latest |     runs-on: ubuntu-latest | ||||||
|     container: ubuntu:latest  # Docker image, not the GitHub Actions VM |     container: ubuntu:latest  # Docker image, not the GitHub Actions VM | ||||||
|     needs: check_pr |  | ||||||
|     steps: |     steps: | ||||||
|       # `rustup` will need `curl` or `wget` later |       # `rustup` will need `curl` or `wget` later | ||||||
|       - run: apt-get update && apt-get install -y curl |       - run: apt-get update && apt-get install -y curl | ||||||
| @ -47,3 +44,10 @@ jobs: | |||||||
|       - uses: ./ |       - uses: ./ | ||||||
|         with: |         with: | ||||||
|           toolchain: stable |           toolchain: stable | ||||||
|  | 
 | ||||||
|  |   install_stable_through_rust_toolchain_file: | ||||||
|  |     runs-on: ubuntu-latest | ||||||
|  |     steps: | ||||||
|  |       - uses: actions/checkout@v1 | ||||||
|  |       - run: echo "stable" > ./rust-toolchain | ||||||
|  |       - uses: ./ | ||||||
|  | |||||||
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -89,3 +89,6 @@ typings/ | |||||||
| 
 | 
 | ||||||
| # DynamoDB Local files | # DynamoDB Local files | ||||||
| .dynamodb/ | .dynamodb/ | ||||||
|  | 
 | ||||||
|  | # IntelliJ IDEs | ||||||
|  | .idea | ||||||
|  | |||||||
| @ -1,22 +1,57 @@ | |||||||
| import * as args from '../src/args' | import {toolchain_args} from "../src/args"; | ||||||
| 
 | import {morph} from "mock-env" | ||||||
| const testEnvVars = { | import {sync as tempWriteSync} from "temp-write" | ||||||
|     INPUT_TOOLCHAIN: 'nightly-2019-04-20', |  | ||||||
|     INPUT_DEFAULT: 'false', |  | ||||||
|     INPUT_OVERRIDE: 'true' |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| describe('actions-rs/toolchain', () => { | describe('actions-rs/toolchain', () => { | ||||||
|     beforeEach(() => { |  | ||||||
|     for (const key in testEnvVars) |  | ||||||
|         process.env[key] = testEnvVars[key as keyof typeof testEnvVars] |  | ||||||
|     }) |  | ||||||
| 
 |  | ||||||
|     it('Parses action input into toolchain options', async () => { |     it('Parses action input into toolchain options', async () => { | ||||||
|         const result = args.toolchain_args(); |         let args = morph(() => { | ||||||
|  |             return toolchain_args("./rust-toolchain"); | ||||||
|  |         }, { | ||||||
|  |             'INPUT_TOOLCHAIN': 'nightly-2019-04-20', | ||||||
|  |             'INPUT_DEFAULT': 'false', | ||||||
|  |             'INPUT_OVERRIDE': 'true' | ||||||
|  |         }); | ||||||
| 
 | 
 | ||||||
|         expect(result.name).toBe('nightly-2019-04-20'); |         expect(args.name).toBe('nightly-2019-04-20'); | ||||||
|         expect(result.default).toBe(false); |         expect(args.default).toBe(false); | ||||||
|         expect(result.override).toBe(true); |         expect(args.override).toBe(true); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     it('uses input variable if rust-toolchain file does not exist', function () { | ||||||
|  |         let args = morph(() => { | ||||||
|  |             return toolchain_args("./rust-toolchain"); | ||||||
|  |         }, { | ||||||
|  |             'INPUT_TOOLCHAIN': 'nightly', | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         expect(args.name).toBe("nightly") | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     it('toolchain input is required if rust-toolchain does not exist', function () { | ||||||
|  |         expect(() => toolchain_args("./rust-toolchain")).toThrowError() | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     it('prioritizes rust-toolchain file over input variable', function () { | ||||||
|  |         let rustToolchainFile = tempWriteSync("1.39.0"); | ||||||
|  | 
 | ||||||
|  |         let args = morph(() => { | ||||||
|  |             return toolchain_args(rustToolchainFile); | ||||||
|  |         }, { | ||||||
|  |             'INPUT_TOOLCHAIN': 'nightly', | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         expect(args.name).toBe("1.39.0") | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     it('trims content of the override file', function () { | ||||||
|  |         let rustToolchainFile = tempWriteSync("\n     1.39.0\n\n\n\n"); | ||||||
|  | 
 | ||||||
|  |         let args = morph(() => { | ||||||
|  |             return toolchain_args(rustToolchainFile); | ||||||
|  |         }, { | ||||||
|  |             'INPUT_TOOLCHAIN': 'nightly', | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         expect(args.name).toBe("1.39.0") | ||||||
|     }); |     }); | ||||||
| }); | }); | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										57
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										57
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @ -27,9 +27,9 @@ | |||||||
|             } |             } | ||||||
|         }, |         }, | ||||||
|         "@actions/core": { |         "@actions/core": { | ||||||
|             "version": "1.1.3", |             "version": "1.2.0", | ||||||
|             "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.1.3.tgz", |             "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.0.tgz", | ||||||
|             "integrity": "sha512-2BIib53Jh4Cfm+1XNuZYYGTeRo8yiWEAUMoliMh1qQGMaqTF4VUlhhcsBylTu4qWmUx45DrY0y0XskimAHSqhw==" |             "integrity": "sha512-ZKdyhlSlyz38S6YFfPnyNgCDZuAF2T0Qv5eHflNWytPS8Qjvz39bZFMry9Bb/dpSnqWcNeav5yM2CTYpJeY+Dw==" | ||||||
|         }, |         }, | ||||||
|         "@actions/exec": { |         "@actions/exec": { | ||||||
|             "version": "1.0.1", |             "version": "1.0.1", | ||||||
| @ -2389,8 +2389,7 @@ | |||||||
|         "graceful-fs": { |         "graceful-fs": { | ||||||
|             "version": "4.2.2", |             "version": "4.2.2", | ||||||
|             "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.2.tgz", |             "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.2.tgz", | ||||||
|             "integrity": "sha512-IItsdsea19BoLC7ELy13q1iJFNmd7ofZH5+X/pJr90/nRoPEX0DJo1dHDbgtYWOhJhcCgMDTOw84RZ72q6lB+Q==", |             "integrity": "sha512-IItsdsea19BoLC7ELy13q1iJFNmd7ofZH5+X/pJr90/nRoPEX0DJo1dHDbgtYWOhJhcCgMDTOw84RZ72q6lB+Q==" | ||||||
|             "dev": true |  | ||||||
|         }, |         }, | ||||||
|         "growly": { |         "growly": { | ||||||
|             "version": "1.3.0", |             "version": "1.3.0", | ||||||
| @ -3530,6 +3529,21 @@ | |||||||
|             "resolved": "https://registry.npmjs.org/macos-release/-/macos-release-2.3.0.tgz", |             "resolved": "https://registry.npmjs.org/macos-release/-/macos-release-2.3.0.tgz", | ||||||
|             "integrity": "sha512-OHhSbtcviqMPt7yfw5ef5aghS2jzFVKEFyCJndQt2YpSQ9qRVSEv2axSJI1paVThEu+FFGs584h/1YhxjVqajA==" |             "integrity": "sha512-OHhSbtcviqMPt7yfw5ef5aghS2jzFVKEFyCJndQt2YpSQ9qRVSEv2axSJI1paVThEu+FFGs584h/1YhxjVqajA==" | ||||||
|         }, |         }, | ||||||
|  |         "make-dir": { | ||||||
|  |             "version": "3.0.0", | ||||||
|  |             "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.0.0.tgz", | ||||||
|  |             "integrity": "sha512-grNJDhb8b1Jm1qeqW5R/O63wUo4UXo2v2HMic6YT9i/HBlF93S8jkMgH7yugvY9ABDShH4VZMn8I+U8+fCNegw==", | ||||||
|  |             "requires": { | ||||||
|  |                 "semver": "^6.0.0" | ||||||
|  |             }, | ||||||
|  |             "dependencies": { | ||||||
|  |                 "semver": { | ||||||
|  |                     "version": "6.3.0", | ||||||
|  |                     "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", | ||||||
|  |                     "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }, | ||||||
|         "make-error": { |         "make-error": { | ||||||
|             "version": "1.3.5", |             "version": "1.3.5", | ||||||
|             "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.5.tgz", |             "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.5.tgz", | ||||||
| @ -3657,6 +3671,15 @@ | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         }, |         }, | ||||||
|  |         "mock-env": { | ||||||
|  |             "version": "0.2.0", | ||||||
|  |             "resolved": "https://registry.npmjs.org/mock-env/-/mock-env-0.2.0.tgz", | ||||||
|  |             "integrity": "sha1-BD9rv4F80NXKWKbWTmRxQq37NTw=", | ||||||
|  |             "dev": true, | ||||||
|  |             "requires": { | ||||||
|  |                 "has": "^1.0.1" | ||||||
|  |             } | ||||||
|  |         }, | ||||||
|         "ms": { |         "ms": { | ||||||
|             "version": "2.0.0", |             "version": "2.0.0", | ||||||
|             "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", |             "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", | ||||||
| @ -4744,6 +4767,30 @@ | |||||||
|             "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==", |             "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==", | ||||||
|             "dev": true |             "dev": true | ||||||
|         }, |         }, | ||||||
|  |         "temp-dir": { | ||||||
|  |             "version": "1.0.0", | ||||||
|  |             "resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-1.0.0.tgz", | ||||||
|  |             "integrity": "sha1-CnwOom06Oa+n4OvqnB/AvE2qAR0=" | ||||||
|  |         }, | ||||||
|  |         "temp-write": { | ||||||
|  |             "version": "4.0.0", | ||||||
|  |             "resolved": "https://registry.npmjs.org/temp-write/-/temp-write-4.0.0.tgz", | ||||||
|  |             "integrity": "sha512-HIeWmj77uOOHb0QX7siN3OtwV3CTntquin6TNVg6SHOqCP3hYKmox90eeFOGaY1MqJ9WYDDjkyZrW6qS5AWpbw==", | ||||||
|  |             "requires": { | ||||||
|  |                 "graceful-fs": "^4.1.15", | ||||||
|  |                 "is-stream": "^2.0.0", | ||||||
|  |                 "make-dir": "^3.0.0", | ||||||
|  |                 "temp-dir": "^1.0.0", | ||||||
|  |                 "uuid": "^3.3.2" | ||||||
|  |             }, | ||||||
|  |             "dependencies": { | ||||||
|  |                 "is-stream": { | ||||||
|  |                     "version": "2.0.0", | ||||||
|  |                     "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.0.tgz", | ||||||
|  |                     "integrity": "sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw==" | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         }, | ||||||
|         "test-exclude": { |         "test-exclude": { | ||||||
|             "version": "5.2.3", |             "version": "5.2.3", | ||||||
|             "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-5.2.3.tgz", |             "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-5.2.3.tgz", | ||||||
|  | |||||||
| @ -11,6 +11,7 @@ | |||||||
|     "scripts": { |     "scripts": { | ||||||
|         "build": "ncc build src/main.ts --minify", |         "build": "ncc build src/main.ts --minify", | ||||||
|         "watch": "ncc build src/main.ts --watch", |         "watch": "ncc build src/main.ts --watch", | ||||||
|  |         "pretest": "git config core.hooksPath .githooks", | ||||||
|         "test": "jest" |         "test": "jest" | ||||||
|     }, |     }, | ||||||
|     "repository": { |     "repository": { | ||||||
| @ -29,17 +30,19 @@ | |||||||
|         "url": "https://github.com/actions-rs/toolchain/issues" |         "url": "https://github.com/actions-rs/toolchain/issues" | ||||||
|     }, |     }, | ||||||
|     "dependencies": { |     "dependencies": { | ||||||
|         "@actions/core": "^1.1.1", |         "@actions-rs/core": "^0.0.8", | ||||||
|  |         "@actions/core": "^1.2.0", | ||||||
|         "@actions/exec": "^1.0.0", |         "@actions/exec": "^1.0.0", | ||||||
|         "@actions/io": "^1.0.0", |         "@actions/io": "^1.0.0" | ||||||
|         "@actions-rs/core": "^0.0.8" |  | ||||||
|     }, |     }, | ||||||
|     "devDependencies": { |     "devDependencies": { | ||||||
|  |         "temp-write": "^4.0.0", | ||||||
|         "@types/jest": "^24.0.23", |         "@types/jest": "^24.0.23", | ||||||
|         "@types/node": "^12.12.14", |         "@types/node": "^12.12.14", | ||||||
|         "@zeit/ncc": "^0.20.5", |         "@zeit/ncc": "^0.20.5", | ||||||
|         "jest": "^24.9.0", |         "jest": "^24.9.0", | ||||||
|         "jest-circus": "^24.9.0", |         "jest-circus": "^24.9.0", | ||||||
|  |         "mock-env": "^0.2.0", | ||||||
|         "ts-jest": "^24.2.0", |         "ts-jest": "^24.2.0", | ||||||
|         "typescript": "^3.7.2" |         "typescript": "^3.7.2" | ||||||
|     } |     } | ||||||
|  | |||||||
							
								
								
									
										22
									
								
								src/args.ts
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/args.ts
									
									
									
									
									
								
							| @ -1,5 +1,6 @@ | |||||||
| import * as core from '@actions/core'; |  | ||||||
| import {input} from '@actions-rs/core'; | import {input} from '@actions-rs/core'; | ||||||
|  | import {info, debug} from "@actions/core"; | ||||||
|  | import {existsSync, readFileSync} from 'fs'; | ||||||
| 
 | 
 | ||||||
| export interface ToolchainOptions { | export interface ToolchainOptions { | ||||||
|     name: string, |     name: string, | ||||||
| @ -10,13 +11,14 @@ export interface ToolchainOptions { | |||||||
|     components: string[] | undefined, |     components: string[] | undefined, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export function toolchain_args(): ToolchainOptions { | export function toolchain_args(overrideFile: string): ToolchainOptions { | ||||||
|     let components: string[] | undefined = input.getInputList('components'); |     let components: string[] | undefined = input.getInputList('components'); | ||||||
|     if (components && components.length === 0) { |     if (components && components.length === 0) { | ||||||
|         components = undefined; |         components = undefined; | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|     return { |     return { | ||||||
|         name: input.getInput('toolchain', {required: true}), |         name: determineToolchain(overrideFile), | ||||||
|         target: input.getInput('target') || undefined, |         target: input.getInput('target') || undefined, | ||||||
|         default: input.getInputBool('default'), |         default: input.getInputBool('default'), | ||||||
|         override: input.getInputBool('override'), |         override: input.getInputBool('override'), | ||||||
| @ -24,3 +26,17 @@ export function toolchain_args(): ToolchainOptions { | |||||||
|         components: components, |         components: components, | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | function determineToolchain(overrideFile: string): string { | ||||||
|  |     if (existsSync(overrideFile)) { | ||||||
|  |         debug(`using toolchain override from ${overrideFile}`); | ||||||
|  |         const content = readFileSync(overrideFile, { | ||||||
|  |             encoding: "utf-8", | ||||||
|  |             flag: "r" | ||||||
|  |         }); | ||||||
|  |         return content.trim(); | ||||||
|  |     } else { | ||||||
|  |         debug(`toolchain override file ${overrideFile} does not exist, falling back to input variable`); | ||||||
|  |         return input.getInput('toolchain', {required: true}) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | |||||||
| @ -1,12 +1,16 @@ | |||||||
| import * as core from '@actions/core'; | import * as core from '@actions/core'; | ||||||
| import * as exec from '@actions/exec'; | import * as exec from '@actions/exec'; | ||||||
| import * as io from '@actions/io'; | import * as io from '@actions/io'; | ||||||
|  | import path from "path"; | ||||||
| 
 | 
 | ||||||
| import * as args from './args'; | import * as args from './args'; | ||||||
| import {RustUp, ToolchainOptions} from '@actions-rs/core'; | import {RustUp, ToolchainOptions} from '@actions-rs/core'; | ||||||
| 
 | 
 | ||||||
| async function run() { | async function run() { | ||||||
|     const opts = args.toolchain_args(); |     // we use path.join to make sure this works on Windows, Linux and MacOS
 | ||||||
|  |     let toolchainOverrideFile = path.join(process.cwd(), "rust-toolchain"); | ||||||
|  | 
 | ||||||
|  |     const opts = args.toolchain_args(toolchainOverrideFile); | ||||||
|     const rustup = await RustUp.getOrInstall(); |     const rustup = await RustUp.getOrInstall(); | ||||||
|     await rustup.call(['show']); |     await rustup.call(['show']); | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										7
									
								
								types/mock-env/index.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								types/mock-env/index.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,7 @@ | |||||||
|  | declare module "mock-env" { | ||||||
|  |     function morph<T>( | ||||||
|  |         callback: () => T, | ||||||
|  |         vars: object, | ||||||
|  |         toRemove?: string[] | ||||||
|  |     ) | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user