From 9d6d60f331f2815b1a0bd91f696b8a71165476a0 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Thu, 28 Oct 2021 18:55:22 -0500 Subject: [PATCH 1/4] Add instructions for using Codespaces --- .devcontainer/scripts/onCreateCommand.sh | 3 ++ docs/workflow/Codespaces.md | 35 ++++++++++++++++++++++++ docs/workflow/README.md | 2 ++ 3 files changed, 40 insertions(+) create mode 100644 docs/workflow/Codespaces.md diff --git a/.devcontainer/scripts/onCreateCommand.sh b/.devcontainer/scripts/onCreateCommand.sh index dc0154c619b82..983db183068c6 100755 --- a/.devcontainer/scripts/onCreateCommand.sh +++ b/.devcontainer/scripts/onCreateCommand.sh @@ -4,3 +4,6 @@ set -e # prebuild the repo, so it is ready for development ./build.sh libs+clr -rc Release + +# save the commit hash of the currently built assemblies, so developers know which version was built +git rev-parse HEAD > ./artifacts/prebuild.sha diff --git a/docs/workflow/Codespaces.md b/docs/workflow/Codespaces.md new file mode 100644 index 0000000000000..68b914f2a7a27 --- /dev/null +++ b/docs/workflow/Codespaces.md @@ -0,0 +1,35 @@ +# Using Codespaces +Codespaces allows you to develop in a Docker container running in the cloud. You can use an in-browser version of VS Code or the full VS Code application with the [GitHub Codespaces VS Code Extension](https://marketplace.visualstudio.com/items?itemName=GitHub.codespaces). This means you don't need to install dotnet/runtime's prerequisites on your current machine in order to develop in dotnet/runtime. + +## Create a Codespace + +dotnet/runtime runs a nightly GitHub Action to build the latest code in the repo. This allows you to immediately start developing and testing after creating a codespace without having to build the whole repo. When the machine is created, it will have built the repo using the code as of 6 AM UTC that morning. + +**NOTE**: In order to use a prebuilt codespace, when you create your machine be sure to select an **`8 core`** machine. + +See https://docs.github.com/codespaces/developing-in-codespaces/creating-a-codespace#creating-a-codespace for instructions on how to create a new codespace. + +### Workarounds + +There is an issue with Codespaces prebuilds that your repo will be checked out to the latest branch's HEAD. However, the binaries in the `artifacts` folder were built when the prebuild GitHub Action was run. Because of this, your build may be broken, depending on what kind of changes came into the repo that day. To fix this run the following after you create your codespace: + +* `git reset --hard $(cat ./artifacts/prebuild.sha)` + +## Updating dotnet/runtime's Codespaces Configuration + +The Codespaces configuration is spread across the following places: + +1. The [.devcontainer](../../.devcontainer) folder contains: + - `devcontainer.json` file configures the codespace and mostly has VS Code settings + - The Dockerfile used to create the image + - The `scripts` folder contains any scripts that are executed during the creation of the codespace. This has the build command that builds the entire repo for prebuilds. +2. The GitHub Action can be configured at [create-codespaces-prebuild](../../.github/workflows/create-codespaces-prebuild.yml) + - This contains when the Action is run, what regions we build prebuilds for, and what size machines + +In order to test out your changes, here is the process: +1. Edit and commit the files to a branch. +2. Push that to a branch on dotnet/runtime. Be careful that you aren't pushing to `main` or some other important branch. Prefix your branch name with your GitHub account name, so others know it is a dev branch. ex. `dotnet-bot/FixCodespaces`. +3. In the "Actions" tab at the top of dotnet/runtime: + - Select "Create Codespaces Prebuild" action on the left + - On the right click "Run workflow" and pick your branch + - After it runs, try to create a codespace diff --git a/docs/workflow/README.md b/docs/workflow/README.md index 06b5d07f9b118..a759e57f99570 100644 --- a/docs/workflow/README.md +++ b/docs/workflow/README.md @@ -46,6 +46,8 @@ To build just one part you use the root build script (build.cmd/sh), and you add For instructions on how to edit code and debug your changes, see [Editing and Debugging](editing-and-debugging.md). +For instructions on using GitHub Codespaces, see [Codespaces](Codespaces.md). + ## Configurations You may need to build the tree in a combination of configurations. This section explains why. From 704f03e362d195073e3930bd97e40a5a1bf591f2 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Wed, 3 Nov 2021 03:09:16 +0000 Subject: [PATCH 2/4] Automate resetting the HEAD to the same commit ID used to build the pre-built container --- .devcontainer/devcontainer.json | 3 +++ .devcontainer/scripts/postCreateCommand.sh | 6 ++++++ docs/workflow/Codespaces.md | 6 ------ 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100755 .devcontainer/scripts/postCreateCommand.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b3dfd99aebd89..baf0b306f73cc 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -23,6 +23,9 @@ // Use 'onCreateCommand' to run pre-build commands inside the codespace "onCreateCommand": "${containerWorkspaceFolder}/.devcontainer/scripts/onCreateCommand.sh", + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "${containerWorkspaceFolder}/.devcontainer/scripts/postCreateCommand.sh", + // Add the locally installed dotnet to the path to ensure that it is activated // This allows developers to just use 'dotnet build' on the command-line, and the local dotnet version will be used. "remoteEnv": { diff --git a/.devcontainer/scripts/postCreateCommand.sh b/.devcontainer/scripts/postCreateCommand.sh new file mode 100755 index 0000000000000..8086037ab9af4 --- /dev/null +++ b/.devcontainer/scripts/postCreateCommand.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -e + +# reset the repo to the commit hash that was used to build the prebuilt Codespace +git reset --hard $(cat ./artifacts/prebuild.sha) diff --git a/docs/workflow/Codespaces.md b/docs/workflow/Codespaces.md index 68b914f2a7a27..b8b51430abc28 100644 --- a/docs/workflow/Codespaces.md +++ b/docs/workflow/Codespaces.md @@ -9,12 +9,6 @@ dotnet/runtime runs a nightly GitHub Action to build the latest code in the repo See https://docs.github.com/codespaces/developing-in-codespaces/creating-a-codespace#creating-a-codespace for instructions on how to create a new codespace. -### Workarounds - -There is an issue with Codespaces prebuilds that your repo will be checked out to the latest branch's HEAD. However, the binaries in the `artifacts` folder were built when the prebuild GitHub Action was run. Because of this, your build may be broken, depending on what kind of changes came into the repo that day. To fix this run the following after you create your codespace: - -* `git reset --hard $(cat ./artifacts/prebuild.sha)` - ## Updating dotnet/runtime's Codespaces Configuration The Codespaces configuration is spread across the following places: From 798a4a1446f4b0d63372e95b0bde395700ccb5ac Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Wed, 3 Nov 2021 23:32:05 +0000 Subject: [PATCH 3/4] - Add notes about tesitng changes. - Add 4-core machines --- .github/workflows/create-codespaces-prebuild.yml | 2 +- docs/workflow/Codespaces.md | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/create-codespaces-prebuild.yml b/.github/workflows/create-codespaces-prebuild.yml index db269106e05a5..5aebbd6898bb5 100644 --- a/.github/workflows/create-codespaces-prebuild.yml +++ b/.github/workflows/create-codespaces-prebuild.yml @@ -12,6 +12,6 @@ jobs: - uses: github/codespaces-precache@v1-stable with: regions: WestUs2 EastUs WestEurope - sku_name: premiumLinux + sku_name: standardLinux32gb premiumLinux env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/docs/workflow/Codespaces.md b/docs/workflow/Codespaces.md index b8b51430abc28..c116e4c0bf1b6 100644 --- a/docs/workflow/Codespaces.md +++ b/docs/workflow/Codespaces.md @@ -20,9 +20,14 @@ The Codespaces configuration is spread across the following places: 2. The GitHub Action can be configured at [create-codespaces-prebuild](../../.github/workflows/create-codespaces-prebuild.yml) - This contains when the Action is run, what regions we build prebuilds for, and what size machines -In order to test out your changes, here is the process: +To test out changes to the `.devcontainer` files, you can follow the process in [Applying changes to your configuration](https://docs.github.com/codespaces/customizing-your-codespace/configuring-codespaces-for-your-project#applying-changes-to-your-configuration) docs. This allows you to rebuild the Codespace privately before creating a PR. + +To test out your `.yml` changes, here is the process: + +**Note**: *Executing these steps will overwrite the current prebuilt container for the entire repo. Afterwards, anyone creating a new codespace will get a prebuilt machine with your test changes until the Action in `main` is executed again.* + 1. Edit and commit the files to a branch. -2. Push that to a branch on dotnet/runtime. Be careful that you aren't pushing to `main` or some other important branch. Prefix your branch name with your GitHub account name, so others know it is a dev branch. ex. `dotnet-bot/FixCodespaces`. +2. Push that to a branch on dotnet/runtime. Be careful that you aren't pushing to `main` or some other important branch. Prefix your branch name with your GitHub account name, so others know it is a dev branch. ex. `username/FixCodespaces`. 3. In the "Actions" tab at the top of dotnet/runtime: - Select "Create Codespaces Prebuild" action on the left - On the right click "Run workflow" and pick your branch From bdc0bf5e547c1215dff71c66fc7f1d09e750f714 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Mon, 8 Nov 2021 16:34:48 -0600 Subject: [PATCH 4/4] Revert 4-core change --- .github/workflows/create-codespaces-prebuild.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/create-codespaces-prebuild.yml b/.github/workflows/create-codespaces-prebuild.yml index 5aebbd6898bb5..db269106e05a5 100644 --- a/.github/workflows/create-codespaces-prebuild.yml +++ b/.github/workflows/create-codespaces-prebuild.yml @@ -12,6 +12,6 @@ jobs: - uses: github/codespaces-precache@v1-stable with: regions: WestUs2 EastUs WestEurope - sku_name: standardLinux32gb premiumLinux + sku_name: premiumLinux env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}