@@ -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
|
||||
```
|
||||
|
||||
@@ -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 %}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user