From c4f075847d41f2d59c636122c2432ef8586750d0 Mon Sep 17 00:00:00 2001 From: haimantika mitra <32809211+Haimantika@users.noreply.github.com> Date: Thu, 13 Jun 2024 23:54:37 +0530 Subject: [PATCH 1/2] Updates environment files documentation (#33197) Co-authored-by: Haimantika Mitra Co-authored-by: Alex Nguyen <150945400+nguyenalex836@users.noreply.github.com> Co-authored-by: Siara <108543037+SiaraMist@users.noreply.github.com> --- .../workflow-commands-for-github-actions.md | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/content/actions/using-workflows/workflow-commands-for-github-actions.md b/content/actions/using-workflows/workflow-commands-for-github-actions.md index 9789eeb8e1..44a2509c86 100644 --- a/content/actions/using-workflows/workflow-commands-for-github-actions.md +++ b/content/actions/using-workflows/workflow-commands-for-github-actions.md @@ -570,7 +570,39 @@ console.log("The running PID from the main action is: " + process.env.STATE_pro ## Environment files -During the execution of a workflow, the runner generates temporary files that can be used to perform certain actions. The path to these files are exposed via environment variables. You will need to use UTF-8 encoding when writing to these files to ensure proper processing of the commands. Multiple commands can be written to the same file, separated by newlines. +During the execution of a workflow, the runner generates temporary files that can be used to perform certain actions. The path to these files can be accessed and edited using GitHub's default environment variables. See "[AUTOTITLE](/actions/learn-github-actions/variables#default-environment-variables)." You will need to use UTF-8 encoding when writing to these files to ensure proper processing of the commands. Multiple commands can be written to the same file, separated by newlines. +To use environment variables in a GitHub Action, you create or modify `.env` files using specific GitHub Actions commands. + +Here's how: + +```yaml copy +name: Example Workflow for Environment Files + +on: push + +jobs: + set_and_use_env_vars: + runs-on: ubuntu-latest + steps: + - name: Set environment variable + run: echo "MY_ENV_VAR=myValue" >> $GITHUB_ENV + + - name: Use environment variable + run: | + echo "The value of MY_ENV_VAR is $MY_ENV_VAR" + +``` + +Another example would be to use it to store metadata like build timestamps, commit SHAs, or artifact names: + +```yaml copy +steps: + - name: Store build timestamp + run: echo "BUILD_TIME=$(date +'%T')" >> $GITHUB_ENV + + - name: Deploy using stored timestamp + run: echo "Deploying at $BUILD_TIME" +``` {% powershell %} From 1403ad3a7765ebacca10258fcf42c29ff15f584c Mon Sep 17 00:00:00 2001 From: Mark Maxwell <138938022+mark-mxwl@users.noreply.github.com> Date: Thu, 13 Jun 2024 08:34:17 -1000 Subject: [PATCH 2/2] Update building-and-testing-net.md (#32613) Co-authored-by: Siara <108543037+SiaraMist@users.noreply.github.com> --- .../building-and-testing-net.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/content/actions/automating-builds-and-tests/building-and-testing-net.md b/content/actions/automating-builds-and-tests/building-and-testing-net.md index 10d9fcf9be..0f46936fe1 100644 --- a/content/actions/automating-builds-and-tests/building-and-testing-net.md +++ b/content/actions/automating-builds-and-tests/building-and-testing-net.md @@ -139,7 +139,7 @@ steps: ### Caching dependencies -You can cache NuGet dependencies using a unique key, which allows you to restore the dependencies for future workflows with the [`cache`](https://github.com/marketplace/actions/cache) action. For example, the YAML below installs the `Newtonsoft` package. +You can cache NuGet dependencies for future workflows using the optional `cache` input. For example, the YAML below caches the NuGet `global-packages` folder, and then installs the `Newtonsoft` package. A second optional input, `cache-dependency-path`, can be used to specify the path to a dependency file: `packages.lock.json`. For more information, see "[AUTOTITLE](/actions/using-workflows/caching-dependencies-to-speed-up-workflows)." @@ -149,14 +149,8 @@ steps: - name: Setup dotnet uses: {% data reusables.actions.action-setup-dotnet %} with: - dotnet-version: '6.0.x' -- uses: {% data reusables.actions.action-cache %} - with: - path: ~/.nuget/packages - # Look to see if there is a cache hit for the corresponding requirements file - key: {% raw %}${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} - restore-keys: | - ${{ runner.os }}-nuget{% endraw %} + dotnet-version: '6.x' + cache: true - name: Install dependencies run: dotnet add package Newtonsoft.Json --version 12.0.1 ```