+
Skip to content

Prevent an error from a lack of permissions to write to /tmp/local-ci #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jun 1, 2022
Merged
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
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ This will also run on a pre-commit hook that will install on `npm i`

You may want to downlod and install a development `.vsix` file, instead of installing this extension via the [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=LocalCI.local-ci).

You'll need at least a [free CircleCI account](https://circleci.com/signup/) for this.

Also, it'd be good to use Firefox instead of Chrome. It looks like Chrome converts the `.vsix` file into an unusable `.zip` file on downloading it.

1. Click the commit check you want to download the `.vsix` for. This could be in a PR, or simply the `develop` branch.
2. For the package job, click Details
3. Click the Artifacts tab
4. Click the `.vsix` file to download it:

https://user-images.githubusercontent.com/4063887/162601777-d12a00f2-6a27-47c7-bc8c-b505e77ca3dc.mp4

(No audio in this video)

## Testing A Build Locally

1. Enter the Command Palette, either through a shortcut, or View > Command Palette
Expand Down
7 changes: 7 additions & 0 deletions src/test/expected/dynamic-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ jobs:
set-up-config:
executor: continuation/default
steps:
- run:
name: Ensure volume is writable
command: |-
if [ "$(ls -ld /tmp/local-ci | awk '{print $3}')" != "$(whoami)" ]
then
sudo chown $(whoami) /tmp/local-ci
fi
- checkout
- run:
name: Set more environment variables
Expand Down
56 changes: 56 additions & 0 deletions src/test/expected/with-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ jobs:
set-up-dependencies:
executor: default-executor
steps:
- run:
name: Ensure volume is writable
command: |-
if [ "$(ls -ld /tmp/local-ci | awk '{print $3}')" != "$(whoami)" ]
then
sudo chown $(whoami) /tmp/local-ci
fi
- checkout
- run:
name: Set more environment variables
Expand Down Expand Up @@ -72,6 +79,13 @@ jobs:
run-prettier:
executor: default-executor
steps:
- run:
name: Ensure volume is writable
command: |-
if [ "$(ls -ld /tmp/local-ci | awk '{print $3}')" != "$(whoami)" ]
then
sudo chown $(whoami) /tmp/local-ci
fi
- run:
name: Attach workspace
command: |-
Expand Down Expand Up @@ -104,6 +118,13 @@ jobs:
run-linter:
executor: default-executor
steps:
- run:
name: Ensure volume is writable
command: |-
if [ "$(ls -ld /tmp/local-ci | awk '{print $3}')" != "$(whoami)" ]
then
sudo chown $(whoami) /tmp/local-ci
fi
- run:
name: Attach workspace
command: |-
Expand All @@ -122,6 +143,13 @@ jobs:
run-unit-tests:
executor: default-executor
steps:
- run:
name: Ensure volume is writable
command: |-
if [ "$(ls -ld /tmp/local-ci | awk '{print $3}')" != "$(whoami)" ]
then
sudo chown $(whoami) /tmp/local-ci
fi
- run:
name: Attach workspace
command: |-
Expand All @@ -140,6 +168,13 @@ jobs:
e2e-tests:
executor: default-executor
steps:
- run:
name: Ensure volume is writable
command: |-
if [ "$(ls -ld /tmp/local-ci | awk '{print $3}')" != "$(whoami)" ]
then
sudo chown $(whoami) /tmp/local-ci
fi
- run:
name: Attach workspace
command: |-
Expand Down Expand Up @@ -183,6 +218,13 @@ jobs:
build:
executor: default-executor
steps:
- run:
name: Ensure volume is writable
command: |-
if [ "$(ls -ld /tmp/local-ci | awk '{print $3}')" != "$(whoami)" ]
then
sudo chown $(whoami) /tmp/local-ci
fi
- run:
name: Attach workspace
command: |-
Expand All @@ -204,6 +246,13 @@ jobs:
verify-bundles-sizes:
executor: default-executor
steps:
- run:
name: Ensure volume is writable
command: |-
if [ "$(ls -ld /tmp/local-ci | awk '{print $3}')" != "$(whoami)" ]
then
sudo chown $(whoami) /tmp/local-ci
fi
- run:
name: Attach workspace
command: |-
Expand All @@ -222,6 +271,13 @@ jobs:
deploy:
executor: default-executor
steps:
- run:
name: Ensure volume is writable
command: |-
if [ "$(ls -ld /tmp/local-ci | awk '{print $3}')" != "$(whoami)" ]
then
sudo chown $(whoami) /tmp/local-ci
fi
- run:
name: Attach workspace
command: |-
Expand Down
26 changes: 0 additions & 26 deletions src/test/suite/utils/isWindows.test.ts

This file was deleted.

15 changes: 9 additions & 6 deletions src/utils/commitContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import * as cp from 'child_process';
import getSpawnOptions from './getSpawnOptions';
import { GET_RUNNING_CONTAINER_FUNCTION } from '../constants';

// Commits the latest container so that this can open an interactive session when it finishes.
// Contianers exit when they finish.
// So this creates an alternative container for shell access.
// This starts by removing previous images of the same repo, as images can be 1-2 GB each.
// The while loop has a [[ true ]] condition because runJob()
// ends this process with .kill().
/**
* Commits the latest container so that this can open an interactive session when it finishes.
*
* Containers exit when they finish.
* So this creates an alternative container for shell access.
* This starts by removing previous images of the same repo, as images can be 1-2 GB each.
* The while loop has a [[ true ]] condition because runJob()
* ends this process with .kill().
*/
export default function commitContainer(
dockerImage: string,
imageRepo: string
Expand Down
2 changes: 1 addition & 1 deletion src/utils/disposeTerminalsForJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import getTerminalName from './getTerminalName';
import getDebuggingTerminalName from './getDebuggingTerminalName';
import getFinalTerminalName from './getFinalTerminalName';

// Closes VS Code terminals for a job.
/** Closes VS Code terminals for a job. */
export default function disposeTerminalsForJob(jobName: string): void {
const terminalNames = [
getTerminalName(jobName),
Expand Down
7 changes: 5 additions & 2 deletions src/utils/getAllConfigFilePaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import * as vscode from 'vscode';
import { SELECTED_CONFIG_PATH } from '../constants';
import getRepoBasename from './getRepoBasename';

// A workspace might have multiple .circleci/config.yml files.
// This gets all of those files.
/**
* Gets all of the paths to .circleci/config.yml files
*
* A workspace might have multiple .circleci/config.yml files.
*/
export default async function getAllConfigFilePaths(
context: vscode.ExtensionContext
): Promise<ConfigFileQuickPick[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getCheckoutJobs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Gets the names of the jobs that have a 'checkout' step.
/** Gets the names of the jobs that have a 'checkout' step. */
export default function getCheckoutJobs(config: CiConfig): string[] {
return Object.keys(config?.jobs ?? []).filter((jobName) =>
(config?.jobs ?? {})[jobName]?.steps?.some(
Expand Down
7 changes: 5 additions & 2 deletions src/utils/getFirstWorkspaceRootPath.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import * as vscode from 'vscode';

// Gets the absolute path to this 1st VS Code workspace folder.
// Though there could be several workspace folders.
/**
* Gets the absolute path to the 1st VS Code workspace folder.
*
* Though there could be several workspace folders.
*/
export default function getFirstWorkspaceRootPath(): string {
return vscode.workspace?.workspaceFolders?.length
? vscode.workspace.workspaceFolders[0]?.uri?.path
Expand Down
5 changes: 0 additions & 5 deletions src/utils/isWindows.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/utils/runJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import uncommittedWarning from './uncommittedWarning';
import getDynamicConfigPath from './getDynamicConfigPath';
import JobProvider from '../classes/JobProvider';

// Whether this job creates a dynamic config: https://circleci.com/docs/2.0/dynamic-config/
/** Whether this job creates a dynamic config: https://circleci.com/docs/2.0/dynamic-config/ */
function doesJobCreateDynamicConfig(job: Job | undefined): boolean {
return (
!!job?.steps &&
Expand Down
9 changes: 6 additions & 3 deletions src/utils/uncommittedWarning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import * as vscode from 'vscode';
import { SUPPRESS_UNCOMMITTED_FILE_WARNING } from '../constants';
import getSpawnOptions from './getSpawnOptions';

// Shows a warning if there are uncommitted files in the repo.
// Those won't be part of the build.
// Uncommitted changes to .circleci/config.yml will still be part of the build.
/**
* Shows a warning if there are uncommitted files in the repo.
*
* Those won't be part of the build.
* Uncommitted changes to .circleci/config.yml will still be part of the build.
*/
export default function uncommittedWarning(
context: vscode.ExtensionContext,
repoPath: string,
Expand Down
14 changes: 13 additions & 1 deletion src/utils/writeProcessFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ function getPersistToWorkspaceCommand(step: FullStep): string | undefined {
);
}

function getEnsureVolumeIsWritableStep() {
return {
run: {
name: 'Ensure volume is writable',
command: `if [ "$(ls -ld ${CONTAINER_STORAGE_DIRECTORY} | awk '{print $3}')" != "$(whoami)" ]
then
sudo chown $(whoami) ${CONTAINER_STORAGE_DIRECTORY}
fi`,
},
};
}

function getEnvVarStep() {
return {
run: {
Expand Down Expand Up @@ -199,7 +211,7 @@ export default function writeProcessFile(
...accumulator,
[jobName]: {
...configJobs[jobName],
steps: newSteps,
steps: [getEnsureVolumeIsWritableStep(), ...(newSteps ?? [])],
},
};
},
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载