mirror of
https://github.com/actions/setup-dotnet.git
synced 2026-03-24 23:52:17 +08:00
Compare commits
8 Commits
tool-confi
...
v2.2.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e6bd2905e | ||
|
|
603ff3ab1c | ||
|
|
d284574c05 | ||
|
|
bac33b41f7 | ||
|
|
f56a6a6861 | ||
|
|
fb81433816 | ||
|
|
9798ae12d7 | ||
|
|
aab9aab748 |
@@ -1,6 +0,0 @@
|
|||||||
# Ignore list
|
|
||||||
/*
|
|
||||||
|
|
||||||
# Do not ignore these folders:
|
|
||||||
!__tests__/
|
|
||||||
!src/
|
|
||||||
51
.eslintrc.js
51
.eslintrc.js
@@ -1,51 +0,0 @@
|
|||||||
// This is a reusable configuration file copied from https://github.com/actions/reusable-workflows/tree/main/reusable-configurations. Please don't make changes to this file as it's the subject of an automatic update.
|
|
||||||
module.exports = {
|
|
||||||
extends: [
|
|
||||||
'eslint:recommended',
|
|
||||||
'plugin:@typescript-eslint/recommended',
|
|
||||||
'plugin:eslint-plugin-jest/recommended',
|
|
||||||
'eslint-config-prettier'
|
|
||||||
],
|
|
||||||
parser: '@typescript-eslint/parser',
|
|
||||||
plugins: ['@typescript-eslint', 'eslint-plugin-node', 'eslint-plugin-jest'],
|
|
||||||
rules: {
|
|
||||||
'@typescript-eslint/no-require-imports': 'error',
|
|
||||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
||||||
'@typescript-eslint/no-explicit-any': 'off',
|
|
||||||
'@typescript-eslint/no-empty-function': 'off',
|
|
||||||
'@typescript-eslint/ban-ts-comment': [
|
|
||||||
'error',
|
|
||||||
{
|
|
||||||
'ts-ignore': 'allow-with-description'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
'no-console': 'error',
|
|
||||||
'yoda': 'error',
|
|
||||||
'prefer-const': [
|
|
||||||
'error',
|
|
||||||
{
|
|
||||||
destructuring: 'all'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
'no-control-regex': 'off',
|
|
||||||
'no-constant-condition': ['error', {checkLoops: false}],
|
|
||||||
'node/no-extraneous-import': 'error'
|
|
||||||
},
|
|
||||||
overrides: [
|
|
||||||
{
|
|
||||||
files: ['**/*{test,spec}.ts'],
|
|
||||||
rules: {
|
|
||||||
'@typescript-eslint/no-unused-vars': 'off',
|
|
||||||
'jest/no-standalone-expect': 'off',
|
|
||||||
'jest/no-conditional-expect': 'off',
|
|
||||||
'no-console': 'off',
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
env: {
|
|
||||||
node: true,
|
|
||||||
es6: true,
|
|
||||||
'jest/globals': true
|
|
||||||
}
|
|
||||||
};
|
|
||||||
3
.gitattributes
vendored
3
.gitattributes
vendored
@@ -1,2 +1 @@
|
|||||||
* text=auto eol=lf
|
.licenses/** -diff linguist-generated=true
|
||||||
.licenses/** -diff linguist-generated=true
|
|
||||||
2
.github/CODEOWNERS
vendored
2
.github/CODEOWNERS
vendored
@@ -1 +1 @@
|
|||||||
* @actions/setup-actions-team
|
* @actions/virtual-environments-owners
|
||||||
|
|||||||
17
.github/workflows/basic-validation.yml
vendored
17
.github/workflows/basic-validation.yml
vendored
@@ -1,17 +0,0 @@
|
|||||||
name: Basic validation
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
paths-ignore:
|
|
||||||
- '**.md'
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
- releases/*
|
|
||||||
paths-ignore:
|
|
||||||
- '**.md'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
call-basic-validation:
|
|
||||||
name: Basic validation
|
|
||||||
uses: actions/reusable-workflows/.github/workflows/basic-validation.yml@main
|
|
||||||
41
.github/workflows/check-dist.yml
vendored
41
.github/workflows/check-dist.yml
vendored
@@ -1,3 +1,8 @@
|
|||||||
|
# `dist/index.js` is a special file in Actions.
|
||||||
|
# When you reference an action with `uses:` in a workflow,
|
||||||
|
# `index.js` is the code that will run.
|
||||||
|
# For our project, we generate this file through a build process from other source files.
|
||||||
|
# We need to make sure the checked-in `index.js` actually matches what we expect it to be.
|
||||||
name: Check dist/
|
name: Check dist/
|
||||||
|
|
||||||
on:
|
on:
|
||||||
@@ -12,6 +17,36 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
call-check-dist:
|
check-dist:
|
||||||
name: Check dist/
|
runs-on: ubuntu-latest
|
||||||
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set Node.js 16
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 16.x
|
||||||
|
cache: npm
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci --ignore-scripts
|
||||||
|
|
||||||
|
- name: Rebuild the dist/ directory
|
||||||
|
run: npm run build
|
||||||
|
|
||||||
|
- name: Compare the expected and actual dist/ directories
|
||||||
|
run: |
|
||||||
|
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
|
||||||
|
echo "Detected uncommitted changes after build. See status below:"
|
||||||
|
git diff
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
id: diff
|
||||||
|
|
||||||
|
# If index.js was different than expected, upload the expected version as an artifact
|
||||||
|
- uses: actions/upload-artifact@v4
|
||||||
|
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
||||||
|
with:
|
||||||
|
name: dist
|
||||||
|
path: dist/
|
||||||
|
|||||||
70
.github/workflows/codeql-analysis.yml
vendored
70
.github/workflows/codeql-analysis.yml
vendored
@@ -1,14 +1,70 @@
|
|||||||
name: CodeQL analysis
|
# For most projects, this workflow file will not need changing; you simply need
|
||||||
|
# to commit it to your repository.
|
||||||
|
#
|
||||||
|
# You may wish to alter this file to override the set of languages analyzed,
|
||||||
|
# or to provide custom queries or build logic.
|
||||||
|
#
|
||||||
|
# ******** NOTE ********
|
||||||
|
# We have attempted to detect the languages in your repository. Please check
|
||||||
|
# the `language` matrix defined below to confirm you have the correct set of
|
||||||
|
# supported CodeQL languages.
|
||||||
|
#
|
||||||
|
name: "CodeQL"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [ main ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [main]
|
# The branches below must be a subset of the branches above
|
||||||
|
branches: [ main ]
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 3 * * 0'
|
- cron: '23 19 * * 0'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
call-codeQL-analysis:
|
analyze:
|
||||||
name: CodeQL analysis
|
name: Analyze
|
||||||
uses: actions/reusable-workflows/.github/workflows/codeql-analysis.yml@main
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
actions: read
|
||||||
|
contents: read
|
||||||
|
security-events: write
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
language: [ 'javascript' ]
|
||||||
|
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
||||||
|
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
# Initializes the CodeQL tools for scanning.
|
||||||
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v2
|
||||||
|
with:
|
||||||
|
languages: ${{ matrix.language }}
|
||||||
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
|
# By default, queries listed here will override any specified in a config file.
|
||||||
|
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||||
|
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||||
|
|
||||||
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
|
- name: Autobuild
|
||||||
|
uses: github/codeql-action/autobuild@v2
|
||||||
|
|
||||||
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
|
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
||||||
|
|
||||||
|
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||||
|
# and modify them (or add more) to build your code if your project
|
||||||
|
# uses a compiled language
|
||||||
|
|
||||||
|
#- run: |
|
||||||
|
# make bootstrap
|
||||||
|
# make release
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v2
|
||||||
|
|||||||
368
.github/workflows/e2e-tests.yml
vendored
368
.github/workflows/e2e-tests.yml
vendored
@@ -1,368 +0,0 @@
|
|||||||
name: e2e tests
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
paths-ignore:
|
|
||||||
- '**.md'
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
- releases/*
|
|
||||||
paths-ignore:
|
|
||||||
- '**.md'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test-setup-multiple-versions:
|
|
||||||
runs-on: ${{ matrix.operating-system }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Clear toolcache
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
|
||||||
- name: Setup dotnet 2.2.402, 3.1.404 and 3.0.x
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
dotnet-version: |
|
|
||||||
2.2.402
|
|
||||||
3.1.404
|
|
||||||
3.0.x
|
|
||||||
- name: Verify dotnet
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/verify-dotnet.ps1 -Patterns "^2.2.402$", "^3.1.404$", "^3.0"
|
|
||||||
|
|
||||||
test-setup-full-version:
|
|
||||||
runs-on: ${{ matrix.operating-system }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Clear toolcache
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
|
||||||
# Side-by-side install of 2.2 and 3.1 used for the test project
|
|
||||||
- name: Setup dotnet 2.2.402
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
dotnet-version: 2.2.402
|
|
||||||
- name: Setup dotnet 3.1.201
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
dotnet-version: 3.1.201
|
|
||||||
# We are including this variable to force the generation of the nuget config file to verify that it is created in the correct place
|
|
||||||
source-url: https://api.nuget.org/v3/index.json
|
|
||||||
env:
|
|
||||||
NUGET_AUTH_TOKEN: NOTATOKEN
|
|
||||||
- name: Verify dotnet
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/verify-dotnet.ps1 -Patterns "^3.1.201$", "^2.2.402$" -CheckNugetConfig
|
|
||||||
|
|
||||||
test-setup-without-patch-version:
|
|
||||||
runs-on: ${{ matrix.operating-system }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Clear toolcache
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
|
||||||
# 2.0, 3.0, 5.0 needs to be in single quotes to interpret as a string instead of as an integer
|
|
||||||
- name: Setup dotnet '3.1'
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
dotnet-version: '3.1'
|
|
||||||
- name: Setup dotnet '2.2'
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
dotnet-version: '2.2'
|
|
||||||
- name: Verify dotnet
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/verify-dotnet.ps1 -Patterns "^3.1", "^2.2"
|
|
||||||
|
|
||||||
test-setup-prerelease-version:
|
|
||||||
runs-on: ${{ matrix.operating-system }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Clear toolcache
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
|
||||||
- name: Setup dotnet '3.1.100-preview1-014459'
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
dotnet-version: '3.1.100-preview1-014459'
|
|
||||||
- name: Verify dotnet
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/verify-dotnet.ps1 -Patterns "3.1.100-preview1-014459"
|
|
||||||
|
|
||||||
test-setup-latest-patch-version:
|
|
||||||
runs-on: ${{ matrix.operating-system }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Clear toolcache
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
|
||||||
- name: Setup dotnet 3.1.x
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
dotnet-version: 3.1.x
|
|
||||||
- name: Setup dotnet 2.2.X
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
dotnet-version: 2.2.X
|
|
||||||
- name: Verify dotnet
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/verify-dotnet.ps1 -Patterns "^2.2", "^3.1"
|
|
||||||
|
|
||||||
test-ABCxx-syntax:
|
|
||||||
runs-on: ${{ matrix.operating-system }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Clear toolcache
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
|
||||||
|
|
||||||
- name: Setup dotnet 6.0.4xx
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
dotnet-version: '6.0.4xx'
|
|
||||||
- name: Verify dotnet
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/verify-dotnet.ps1 -Patterns "^6\.0\.4\d{2}"
|
|
||||||
|
|
||||||
test-setup-with-wildcard:
|
|
||||||
runs-on: ${{ matrix.operating-system }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Clear toolcache
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
|
||||||
- name: Setup dotnet 3.1.*
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
dotnet-version: 3.1.*
|
|
||||||
- name: Setup dotnet 2.2.*
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
dotnet-version: 2.2.*
|
|
||||||
- name: Verify dotnet
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/verify-dotnet.ps1 -Patterns "^3.1", "^2.2"
|
|
||||||
|
|
||||||
test-setup-global-json-specified-and-version:
|
|
||||||
runs-on: ${{ matrix.operating-system }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Clear toolcache
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
|
||||||
- name: Write global.json
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
mkdir subdirectory
|
|
||||||
echo '{"sdk":{"version": "2.2.207","rollForward": "latestFeature"}}' > ./subdirectory/global.json
|
|
||||||
- name: Setup dotnet
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
dotnet-version: 3.1
|
|
||||||
global-json-file: ./subdirectory/global.json
|
|
||||||
- name: Verify dotnet
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/verify-dotnet.ps1 -Patterns "^2.2", "^3.1"
|
|
||||||
|
|
||||||
test-setup-global-json-only:
|
|
||||||
runs-on: ${{ matrix.operating-system }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Clear toolcache
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
|
||||||
- name: Write global.json
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
mkdir subdirectory
|
|
||||||
echo '{"sdk":{"version": "2.2.207","rollForward": "latestFeature"}}' > ./subdirectory/global.json
|
|
||||||
- name: Setup dotnet
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
global-json-file: ./subdirectory/global.json
|
|
||||||
- name: Verify dotnet
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/verify-dotnet.ps1 -Patterns "^2.2"
|
|
||||||
|
|
||||||
test-setup-with-dotnet-quality:
|
|
||||||
runs-on: ${{ matrix.operating-system }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Clear toolcache
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
|
||||||
|
|
||||||
- name: Setup dotnet 7.0 with preview quality
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
dotnet-version: '7.0'
|
|
||||||
dotnet-quality: 'preview'
|
|
||||||
- name: Verify dotnet
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/verify-dotnet.ps1 -Patterns "^7\.0\.\d+-"
|
|
||||||
|
|
||||||
test-dotnet-version-output-during-single-version-installation:
|
|
||||||
runs-on: ${{ matrix.operating-system }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Clear toolcache
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
|
||||||
|
|
||||||
- name: Setup dotnet 6.0.401
|
|
||||||
uses: ./
|
|
||||||
id: step1
|
|
||||||
with:
|
|
||||||
dotnet-version: '6.0.401'
|
|
||||||
|
|
||||||
- name: Verify value of the dotnet-version output
|
|
||||||
shell: pwsh
|
|
||||||
run: |
|
|
||||||
$version = & dotnet --version
|
|
||||||
Write-Host "Installed version: $version"
|
|
||||||
if (-not ($version -eq '${{steps.step1.outputs.dotnet-version}}')) { throw "Unexpected output value" }
|
|
||||||
|
|
||||||
test-dotnet-version-output-during-multiple-version-installation:
|
|
||||||
runs-on: ${{ matrix.operating-system }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Clear toolcache
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
|
||||||
|
|
||||||
- name: Setup dotnet 6.0.401, 5.0.408, 7.0.100-rc.1.22431.12
|
|
||||||
uses: ./
|
|
||||||
id: step2
|
|
||||||
with:
|
|
||||||
dotnet-version: |
|
|
||||||
7.0.100-rc.1.22431.12
|
|
||||||
6.0.401
|
|
||||||
5.0.408
|
|
||||||
|
|
||||||
- name: Verify value of the dotnet-version output
|
|
||||||
shell: pwsh
|
|
||||||
run: |
|
|
||||||
$version = "7.0.100-rc.1.22431.12"
|
|
||||||
if (-not ($version -eq '${{steps.step2.outputs.dotnet-version}}')) { throw "Unexpected output value" }
|
|
||||||
|
|
||||||
test-proxy:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: ubuntu:latest
|
|
||||||
options: --dns 127.0.0.1
|
|
||||||
services:
|
|
||||||
squid-proxy:
|
|
||||||
image: ubuntu/squid:latest
|
|
||||||
ports:
|
|
||||||
- 3128:3128
|
|
||||||
env:
|
|
||||||
https_proxy: http://squid-proxy:3128
|
|
||||||
http_proxy: http://squid-proxy:3128
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Install Powershell
|
|
||||||
run: |
|
|
||||||
apt-get update
|
|
||||||
apt-get install -y wget apt-transport-https software-properties-common
|
|
||||||
wget -q "https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb"
|
|
||||||
dpkg -i packages-microsoft-prod.deb
|
|
||||||
rm packages-microsoft-prod.deb
|
|
||||||
apt-get update
|
|
||||||
apt-get install -y powershell
|
|
||||||
- name: Clear toolcache
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
|
||||||
- name: Setup dotnet 6.0
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
dotnet-version: 6.0
|
|
||||||
source-url: https://api.nuget.org/v3/index.json
|
|
||||||
env:
|
|
||||||
NUGET_AUTH_TOKEN: NOTATOKEN
|
|
||||||
- name: Verify dotnet
|
|
||||||
shell: pwsh
|
|
||||||
run: |
|
|
||||||
__tests__/verify-dotnet.ps1 -Patterns "^6.0" -CheckNugetConfig
|
|
||||||
|
|
||||||
test-bypass-proxy:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
env:
|
|
||||||
https_proxy: http://no-such-proxy:3128
|
|
||||||
no_proxy: github.com,dotnetcli.blob.core.windows.net,download.visualstudio.microsoft.com,api.nuget.org,dotnetcli.azureedge.net
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Clear toolcache
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
|
||||||
- name: Setup dotnet 3.1.201
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
dotnet-version: 3.1.201
|
|
||||||
source-url: https://api.nuget.org/v3/index.json
|
|
||||||
env:
|
|
||||||
NUGET_AUTH_TOKEN: NOTATOKEN
|
|
||||||
- name: Verify dotnet
|
|
||||||
shell: pwsh
|
|
||||||
run: __tests__/verify-dotnet.ps1 -Patterns "^3.1.201$" -CheckNugetConfig
|
|
||||||
16
.github/workflows/licensed.yml
vendored
16
.github/workflows/licensed.yml
vendored
@@ -10,6 +10,16 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
call-licensed:
|
test:
|
||||||
name: Licensed
|
runs-on: ubuntu-latest
|
||||||
uses: actions/reusable-workflows/.github/workflows/licensed.yml@main
|
name: Check licenses
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- run: npm ci --ignore-scripts
|
||||||
|
- name: Install licensed
|
||||||
|
run: |
|
||||||
|
cd $RUNNER_TEMP
|
||||||
|
curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/3.4.4/licensed-3.4.4-linux-x64.tar.gz
|
||||||
|
sudo tar -xzf licensed.tar.gz
|
||||||
|
sudo mv licensed /usr/local/bin/licensed
|
||||||
|
- run: licensed status
|
||||||
|
|||||||
13
.github/workflows/release-new-action-version.yml
vendored
13
.github/workflows/release-new-action-version.yml
vendored
@@ -1,5 +1,4 @@
|
|||||||
name: Release new action version
|
name: Release new action version
|
||||||
|
|
||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
types: [released]
|
types: [released]
|
||||||
@@ -21,9 +20,9 @@ jobs:
|
|||||||
name: releaseNewActionVersion
|
name: releaseNewActionVersion
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Update the ${{ env.TAG_NAME }} tag
|
- name: Update the ${{ env.TAG_NAME }} tag
|
||||||
id: update-major-tag
|
id: update-major-tag
|
||||||
uses: actions/publish-action@v0.2.2
|
uses: actions/publish-action@v0.1.0
|
||||||
with:
|
with:
|
||||||
source-tag: ${{ env.TAG_NAME }}
|
source-tag: ${{ env.TAG_NAME }}
|
||||||
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
||||||
10
.github/workflows/test-dotnet.yml
vendored
10
.github/workflows/test-dotnet.yml
vendored
@@ -17,8 +17,8 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
|
operating-system: [ubuntu-22.04, windows-latest, macOS-latest]
|
||||||
dotnet-version: ['2.1', '2.2', '3.0', '3.1', '5.0', '6.0', '7.0', '8.0']
|
dotnet-version: ['2.1', '2.2', '3.0', '3.1', '5.0']
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
@@ -29,7 +29,9 @@ jobs:
|
|||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
dotnet-version: ${{ matrix.dotnet-version }}
|
dotnet-version: ${{ matrix.dotnet-version }}
|
||||||
- name: Verify installed version
|
- name: Check installed version
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: |
|
run: |
|
||||||
__tests__/verify-dotnet.ps1 -Patterns "^${{ matrix.dotnet-version }}"
|
$version = & dotnet --version
|
||||||
|
Write-Host "Installed version: $version"
|
||||||
|
if (-not $version.StartsWith("${{ matrix.dotnet-version }}")) { throw "Unexpected version" }
|
||||||
11
.github/workflows/update-config-files.yml
vendored
11
.github/workflows/update-config-files.yml
vendored
@@ -1,11 +0,0 @@
|
|||||||
name: Update configuration files
|
|
||||||
|
|
||||||
on:
|
|
||||||
schedule:
|
|
||||||
- cron: '0 3 * * 0'
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
call-update-configuration-files:
|
|
||||||
name: Update configuration files
|
|
||||||
uses: actions/reusable-workflows/.github/workflows/update-config-files.yml@main
|
|
||||||
244
.github/workflows/workflow.yml
vendored
Normal file
244
.github/workflows/workflow.yml
vendored
Normal file
@@ -0,0 +1,244 @@
|
|||||||
|
name: Main workflow
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
paths-ignore:
|
||||||
|
- '**.md'
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- releases/*
|
||||||
|
paths-ignore:
|
||||||
|
- '**.md'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ${{ matrix.operating-system }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Set Node.js 16
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 16.x
|
||||||
|
cache: npm
|
||||||
|
- run: npm ci --ignore-scripts
|
||||||
|
- run: npm run build
|
||||||
|
- run: npm run format-check
|
||||||
|
- run: npm test
|
||||||
|
- name: Verify no unstaged changes
|
||||||
|
if: runner.os != 'windows'
|
||||||
|
run: __tests__/verify-no-unstaged-changes.sh
|
||||||
|
|
||||||
|
test-setup-multiple-versions:
|
||||||
|
runs-on: ${{ matrix.operating-system }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
operating-system: [ubuntu-22.04, windows-latest, macOS-latest]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Clear toolcache
|
||||||
|
shell: pwsh
|
||||||
|
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
||||||
|
- name: Setup dotnet 2.2.402 and 3.1.404
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
dotnet-version: |
|
||||||
|
2.2.402
|
||||||
|
3.1.404
|
||||||
|
3.0.x
|
||||||
|
- name: Verify dotnet
|
||||||
|
shell: pwsh
|
||||||
|
run: __tests__/verify-dotnet.ps1 2.2.402 3.1.404 '3.0'
|
||||||
|
|
||||||
|
test-setup-full-version:
|
||||||
|
runs-on: ${{ matrix.operating-system }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
operating-system: [ubuntu-22.04, windows-latest, macos-13]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Clear toolcache
|
||||||
|
shell: pwsh
|
||||||
|
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
||||||
|
# Side-by-side install of 2.2 and 3.1 used for the test project
|
||||||
|
- name: Setup dotnet 2.2.402
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
dotnet-version: 2.2.402
|
||||||
|
- name: Setup dotnet 3.1.201
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
dotnet-version: 3.1.201
|
||||||
|
# We are including this veriable to force the generation of the nuget config file to verify that it is created in the correct place
|
||||||
|
source-url: https://api.nuget.org/v3/index.json
|
||||||
|
env:
|
||||||
|
NUGET_AUTH_TOKEN: NOTATOKEN
|
||||||
|
- name: Verify nuget config file
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
if (-Not (Test-Path "../nuget.config")) { throw "nuget file not generated correctly" }
|
||||||
|
- name: Verify dotnet
|
||||||
|
shell: pwsh
|
||||||
|
run: __tests__/verify-dotnet.ps1 3.1.201 2.2.402
|
||||||
|
|
||||||
|
test-setup-without-patch-version:
|
||||||
|
runs-on: ${{ matrix.operating-system }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
operating-system: [ubuntu-22.04, windows-latest, macOS-latest]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Clear toolcache
|
||||||
|
shell: pwsh
|
||||||
|
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
||||||
|
# 2.0, 3.0, 5.0 needs to be in single quotes to interpret as a string instead of as an integer
|
||||||
|
- name: Setup dotnet '3.1'
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
dotnet-version: '3.1'
|
||||||
|
- name: Setup dotnet '2.2'
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
dotnet-version: '2.2'
|
||||||
|
- name: Verify dotnet
|
||||||
|
shell: pwsh
|
||||||
|
run: __tests__/verify-dotnet.ps1 3.1 2.2
|
||||||
|
|
||||||
|
test-setup-latest-patch-version:
|
||||||
|
runs-on: ${{ matrix.operating-system }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
operating-system: [ubuntu-22.04, windows-latest, macOS-latest]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Clear toolcache
|
||||||
|
shell: pwsh
|
||||||
|
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
||||||
|
- name: Setup dotnet 3.1.x
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
dotnet-version: 3.1.x
|
||||||
|
- name: Setup dotnet 2.2.x
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
dotnet-version: 2.2.x
|
||||||
|
- name: Verify dotnet
|
||||||
|
shell: pwsh
|
||||||
|
run: __tests__/verify-dotnet.ps1 3.1 2.2
|
||||||
|
|
||||||
|
test-setup-with-wildcard:
|
||||||
|
runs-on: ${{ matrix.operating-system }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
operating-system: [ubuntu-22.04, windows-latest, macOS-latest]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Clear toolcache
|
||||||
|
shell: pwsh
|
||||||
|
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
||||||
|
- name: Setup dotnet 3.1.*
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
dotnet-version: 3.1.*
|
||||||
|
- name: Setup dotnet 2.2.*
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
dotnet-version: 2.2.*
|
||||||
|
- name: Verify dotnet
|
||||||
|
shell: pwsh
|
||||||
|
run: __tests__/verify-dotnet.ps1 3.1 2.2
|
||||||
|
|
||||||
|
test-setup-global-json-specified-and-version:
|
||||||
|
runs-on: ${{ matrix.operating-system }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
operating-system: [ubuntu-22.04, windows-latest, macOS-latest]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Clear toolcache
|
||||||
|
shell: pwsh
|
||||||
|
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
|
||||||
|
- name: Write global.json
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
mkdir subdirectory
|
||||||
|
echo '{"sdk":{"version": "2.2","rollForward": "latestFeature"}}' > ./subdirectory/global.json
|
||||||
|
- name: Setup dotnet
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
dotnet-version: 3.1
|
||||||
|
global-json-file: ./subdirectory/global.json
|
||||||
|
- name: Verify dotnet
|
||||||
|
shell: pwsh
|
||||||
|
run: __tests__/verify-dotnet.ps1 2.2 3.1
|
||||||
|
|
||||||
|
test-proxy:
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
container:
|
||||||
|
image: ubuntu:20.04
|
||||||
|
options: --dns 127.0.0.1
|
||||||
|
services:
|
||||||
|
squid-proxy:
|
||||||
|
image: ubuntu/squid:latest
|
||||||
|
ports:
|
||||||
|
- 3128:3128
|
||||||
|
env:
|
||||||
|
https_proxy: http://squid-proxy:3128
|
||||||
|
http_proxy: http://squid-proxy:3128
|
||||||
|
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Clear tool cache
|
||||||
|
run: rm -rf "/usr/share/dotnet"
|
||||||
|
- name: Install curl
|
||||||
|
run: |
|
||||||
|
apt update
|
||||||
|
apt -y install curl libssl1.1 libssl-dev
|
||||||
|
- name: Setup dotnet 3.1.201
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
dotnet-version: 3.1.201
|
||||||
|
source-url: https://api.nuget.org/v3/index.json
|
||||||
|
env:
|
||||||
|
NUGET_AUTH_TOKEN: NOTATOKEN
|
||||||
|
- name: Verify dotnet
|
||||||
|
run: __tests__/verify-dotnet.sh 3.1.201
|
||||||
|
|
||||||
|
test-bypass-proxy:
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
env:
|
||||||
|
https_proxy: http://no-such-proxy:3128
|
||||||
|
no_proxy: github.com,download.visualstudio.microsoft.com,api.nuget.org,builds.dotnet.microsoft.com,ci.dot.net
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Clear tool cache
|
||||||
|
run: rm -rf "/usr/share/dotnet"
|
||||||
|
- name: Setup dotnet 3.1.201
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
dotnet-version: 3.1.201
|
||||||
|
source-url: https://api.nuget.org/v3/index.json
|
||||||
|
env:
|
||||||
|
NUGET_AUTH_TOKEN: NOTATOKEN
|
||||||
|
- name: Verify dotnet
|
||||||
|
run: __tests__/verify-dotnet.sh 3.1.201
|
||||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -3,8 +3,8 @@ global.json
|
|||||||
lib/
|
lib/
|
||||||
node_modules/
|
node_modules/
|
||||||
__tests__/runner/*
|
__tests__/runner/*
|
||||||
__tests__/e2e-test-csproj/bin/
|
__tests__/sample-csproj/bin/
|
||||||
__tests__/e2e-test-csproj/obj/
|
__tests__/sample-csproj/obj/
|
||||||
|
|
||||||
# Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
|
# Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
|
||||||
# Logs
|
# Logs
|
||||||
|
|||||||
@@ -2,4 +2,3 @@
|
|||||||
. "$(dirname -- "$0")/_/husky.sh"
|
. "$(dirname -- "$0")/_/husky.sh"
|
||||||
|
|
||||||
npm run format
|
npm run format
|
||||||
npm run lint:fix
|
|
||||||
|
|||||||
@@ -3,4 +3,3 @@
|
|||||||
|
|
||||||
# Tests are not run at push time since they can take 2-4 minutes to complete
|
# Tests are not run at push time since they can take 2-4 minutes to complete
|
||||||
npm run format-check
|
npm run format-check
|
||||||
npm run lint
|
|
||||||
|
|||||||
BIN
.licenses/npm/@actions/core.dep.yml
generated
BIN
.licenses/npm/@actions/core.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@actions/exec.dep.yml
generated
BIN
.licenses/npm/@actions/exec.dep.yml
generated
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/@actions/http-client-1.0.8.dep.yml
generated
Normal file
BIN
.licenses/npm/@actions/http-client-1.0.8.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/@actions/io.dep.yml
generated
BIN
.licenses/npm/@actions/io.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/fast-xml-parser.dep.yml
generated
BIN
.licenses/npm/fast-xml-parser.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/strnum.dep.yml
generated
BIN
.licenses/npm/strnum.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/uuid.dep.yml
generated
BIN
.licenses/npm/uuid.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/xmlbuilder.dep.yml
generated
Normal file
BIN
.licenses/npm/xmlbuilder.dep.yml
generated
Normal file
Binary file not shown.
@@ -1,7 +0,0 @@
|
|||||||
# Ignore list
|
|
||||||
/*
|
|
||||||
|
|
||||||
# Do not ignore these folders:
|
|
||||||
!__tests__/
|
|
||||||
!.github/
|
|
||||||
!src/
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
// This is a reusable configuration file copied from https://github.com/actions/reusable-workflows/tree/main/reusable-configurations. Please don't make changes to this file as it's the subject of an automatic update.
|
|
||||||
module.exports = {
|
|
||||||
printWidth: 80,
|
|
||||||
tabWidth: 2,
|
|
||||||
useTabs: false,
|
|
||||||
semi: true,
|
|
||||||
singleQuote: true,
|
|
||||||
trailingComma: 'none',
|
|
||||||
bracketSpacing: false,
|
|
||||||
arrowParens: 'avoid'
|
|
||||||
};
|
|
||||||
11
.prettierrc.json
Normal file
11
.prettierrc.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"printWidth": 80,
|
||||||
|
"tabWidth": 2,
|
||||||
|
"useTabs": false,
|
||||||
|
"semi": true,
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "none",
|
||||||
|
"bracketSpacing": false,
|
||||||
|
"arrowParens": "avoid",
|
||||||
|
"parser": "typescript"
|
||||||
|
}
|
||||||
191
README.md
191
README.md
@@ -1,7 +1,6 @@
|
|||||||
# setup-dotnet
|
# setup-dotnet
|
||||||
|
|
||||||
[](https://github.com/actions/setup-dotnet/actions/workflows/basic-validation.yml)
|
[](https://github.com/actions/setup-dotnet)
|
||||||
[](https://github.com/actions/setup-dotnet/actions/workflows/e2e-tests.yml)
|
|
||||||
|
|
||||||
This action sets up a [.NET CLI](https://github.com/dotnet/sdk) environment for use in actions by:
|
This action sets up a [.NET CLI](https://github.com/dotnet/sdk) environment for use in actions by:
|
||||||
|
|
||||||
@@ -9,82 +8,62 @@ This action sets up a [.NET CLI](https://github.com/dotnet/sdk) environment for
|
|||||||
- registering problem matchers for error output
|
- registering problem matchers for error output
|
||||||
- setting up authentication to private package sources like GitHub Packages
|
- setting up authentication to private package sources like GitHub Packages
|
||||||
|
|
||||||
> **Note**: GitHub hosted runners have some versions of the .NET SDK
|
Please Note: GitHub hosted runners have some versions of the .NET SDK
|
||||||
preinstalled. Installed versions are subject to change. Please refer to the
|
preinstalled. Installed versions are subject to change. Please refer to the
|
||||||
documentation:
|
documentation
|
||||||
[Software installed on github hosted runners](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-software)
|
[software installed on github hosted runners](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-software)
|
||||||
for .NET SDK versions that are currently available.
|
for .NET SDK versions that are currently available.
|
||||||
|
|
||||||
## Usage
|
# Usage
|
||||||
|
|
||||||
See [action.yml](action.yml)
|
See [action.yml](action.yml)
|
||||||
|
|
||||||
**Basic**:
|
Basic:
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-dotnet@v3
|
- uses: actions/setup-dotnet@v2
|
||||||
with:
|
with:
|
||||||
dotnet-version: '3.1.x'
|
dotnet-version: '3.1.x' # SDK Version to use; x will use the latest version of the 3.1 channel
|
||||||
- run: dotnet build <my project>
|
- run: dotnet build <my project>
|
||||||
```
|
```
|
||||||
> **Warning**: Unless a concrete version is specified in the [`global.json`](https://learn.microsoft.com/en-us/dotnet/core/tools/global-json) file, **_the latest .NET version installed on the runner (including preinstalled versions) will be used [by default](https://learn.microsoft.com/en-us/dotnet/core/versions/selection#the-sdk-uses-the-latest-installed-version)_**. Please refer to the [documentation](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-software) for the currently preinstalled .NET SDK versions.
|
Multiple versions:
|
||||||
|
> Note: In case multiple versions are installed, the latest .NET version will be used by default unless another version is specified in the `global.json` file.
|
||||||
|
|
||||||
**Multiple version installation**:
|
|
||||||
```yml
|
```yml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Setup dotnet
|
- name: Setup dotnet
|
||||||
uses: actions/setup-dotnet@v3
|
uses: actions/setup-dotnet@v2
|
||||||
with:
|
with:
|
||||||
dotnet-version: |
|
dotnet-version: |
|
||||||
3.1.x
|
3.1.x
|
||||||
5.0.x
|
5.0.x
|
||||||
- run: dotnet build <my project>
|
- run: dotnet build <my project>
|
||||||
```
|
```
|
||||||
## Supported version syntax
|
Preview version:
|
||||||
|
|
||||||
The `dotnet-version` input supports following syntax:
|
|
||||||
|
|
||||||
- **A.B.C** (e.g 6.0.400, 7.0.100-preview.7.22377.5) - installs exact version of .NET SDK
|
|
||||||
- **A.B** or **A.B.x** (e.g. 3.1, 3.1.x) - installs the latest patch version of .NET SDK on the channel `3.1`, including prerelease versions (preview, rc)
|
|
||||||
- **A** or **A.x** (e.g. 3, 3.x) - installs the latest minor version of the specified major tag, including prerelease versions (preview, rc)
|
|
||||||
- **A.B.Cxx** (e.g. 6.0.4xx) - available since `.NET 5.0` release. Installs the latest version of the specific SDK release, including prerelease versions (preview, rc).
|
|
||||||
|
|
||||||
|
|
||||||
## Using the `dotnet-quality` input
|
|
||||||
This input sets up the action to install the latest build of the specified quality in the channel. The possible values of `dotnet-quality` are: **daily**, **signed**, **validated**, **preview**, **ga**.
|
|
||||||
|
|
||||||
> **Note**: `dotnet-quality` input can be used only with .NET SDK version in 'A.B', 'A.B.x', 'A', 'A.x' and 'A.B.Cxx' formats where the major version is higher than 5. In other cases, `dotnet-quality` input will be ignored.
|
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-dotnet@v3
|
- uses: actions/setup-dotnet@v2
|
||||||
with:
|
with:
|
||||||
dotnet-version: '6.0.x'
|
dotnet-version: '6.0.x'
|
||||||
dotnet-quality: 'preview'
|
include-prerelease: true
|
||||||
- run: dotnet build <my project>
|
- run: dotnet build <my project>
|
||||||
```
|
```
|
||||||
|
global.json in a subdirectory:
|
||||||
## Using the `global-json-file` input
|
|
||||||
`setup-dotnet` action can read .NET SDK version from a `global.json` file. Input `global-json-file` is used for specifying the path to the `global.json`. If the file that was supplied to `global-json-file` input doesn't exist, the action will fail with error.
|
|
||||||
|
|
||||||
>**Note**: In case both `dotnet-version` and `global-json-file` inputs are used, versions from both inputs will be installed.
|
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-dotnet@v3
|
- uses: actions/setup-dotnet@v2
|
||||||
with:
|
with:
|
||||||
global-json-file: csharp/global.json
|
global-json-file: csharp/global.json
|
||||||
- run: dotnet build <my project>
|
- run: dotnet build <my project>
|
||||||
working-directory: csharp
|
working-directory: csharp
|
||||||
```
|
```
|
||||||
|
|
||||||
## Matrix Testing
|
Matrix Testing:
|
||||||
Using `setup-dotnet` it's possible to use [matrix syntax](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix) to install several versions of .NET SDK:
|
```yaml
|
||||||
```yml
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -95,44 +74,38 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Setup dotnet
|
- name: Setup dotnet
|
||||||
uses: actions/setup-dotnet@v3
|
uses: actions/setup-dotnet@v2
|
||||||
with:
|
with:
|
||||||
dotnet-version: ${{ matrix.dotnet }}
|
dotnet-version: ${{ matrix.dotnet }}
|
||||||
- name: Execute dotnet
|
- run: dotnet build <my project>
|
||||||
run: dotnet build <my project>
|
|
||||||
```
|
```
|
||||||
>**Note**: Unless a concrete version is specified in the [`global.json`](https://learn.microsoft.com/en-us/dotnet/core/tools/global-json) file, the latest .NET version installed on the runner (including preinstalled versions) will be used [by default](https://learn.microsoft.com/en-us/dotnet/core/versions/selection#the-sdk-uses-the-latest-installed-version). To control this behavior you may want to use temporary `global.json` files:
|
|
||||||
|
|
||||||
**Matrix testing with temporary global.json creation**
|
Side by Side Testing:
|
||||||
```yml
|
```yaml
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
name: Dotnet Side by Side testing sample
|
||||||
matrix:
|
|
||||||
dotnet: [ '2.1.x', '3.1.x', '5.0.x' ]
|
|
||||||
name: Dotnet ${{ matrix.dotnet }} sample
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Setup dotnet
|
- name: Setup dotnet
|
||||||
uses: actions/setup-dotnet@v3
|
uses: actions/setup-dotnet@v2
|
||||||
id: stepid
|
|
||||||
with:
|
with:
|
||||||
dotnet-version: ${{ matrix.dotnet }}
|
dotnet-version: |
|
||||||
- name: Create temporary global.json
|
2.1.x
|
||||||
run: echo '{"sdk":{"version": "${{ steps.stepid.outputs.dotnet-version }}"}}' > ./global.json
|
3.1.x
|
||||||
- name: Execute dotnet
|
- run: dotnet build <my project>
|
||||||
run: dotnet build <my project>
|
- run: dotnet test <my project>
|
||||||
```
|
```
|
||||||
## Setting up authentication for nuget feeds
|
|
||||||
|
|
||||||
### Github Package Registry (GPR)
|
Authentication for nuget feeds:
|
||||||
```yml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-dotnet@v3
|
# Authenticates packages to push to GPR
|
||||||
|
- uses: actions/setup-dotnet@v2
|
||||||
with:
|
with:
|
||||||
dotnet-version: '3.1.x'
|
dotnet-version: '3.1.x' # SDK Version to use.
|
||||||
source-url: https://nuget.pkg.github.com/<owner>/index.json
|
source-url: https://nuget.pkg.github.com/<owner>/index.json
|
||||||
env:
|
env:
|
||||||
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||||
@@ -141,22 +114,19 @@ steps:
|
|||||||
run: dotnet pack --configuration Release <my project>
|
run: dotnet pack --configuration Release <my project>
|
||||||
- name: Publish the package to GPR
|
- name: Publish the package to GPR
|
||||||
run: dotnet nuget push <my project>/bin/Release/*.nupkg
|
run: dotnet nuget push <my project>/bin/Release/*.nupkg
|
||||||
```
|
|
||||||
|
|
||||||
### Azure Artifacts
|
# Authenticates packages to push to Azure Artifacts
|
||||||
```yml
|
- uses: actions/setup-dotnet@v2
|
||||||
- uses: actions/setup-dotnet@v3
|
|
||||||
with:
|
with:
|
||||||
source-url: https://pkgs.dev.azure.com/<your-organization>/_packaging/<your-feed-name>/nuget/v3/index.json
|
source-url: https://pkgs.dev.azure.com/<your-organization>/_packaging/<your-feed-name>/nuget/v3/index.json
|
||||||
env:
|
env:
|
||||||
NUGET_AUTH_TOKEN: ${{secrets.AZURE_DEVOPS_PAT}} # Note, create a secret with this name in Settings
|
NUGET_AUTH_TOKEN: ${{secrets.AZURE_DEVOPS_PAT}} # Note, create a secret with this name in Settings
|
||||||
- name: Publish the package to Azure Artifacts
|
- name: Publish the package to Azure Artifacts
|
||||||
run: dotnet nuget push <my project>/bin/Release/*.nupkg
|
run: dotnet nuget push <my project>/bin/Release/*.nupkg
|
||||||
```
|
|
||||||
|
|
||||||
### nuget.org
|
# Authenticates packages to push to nuget.org.
|
||||||
```yml
|
# It's only the way to push a package to nuget.org feed for macOS/Linux machines due to API key config store limitations.
|
||||||
- uses: actions/setup-dotnet@v3
|
- uses: actions/setup-dotnet@v2
|
||||||
with:
|
with:
|
||||||
dotnet-version: 3.1.x
|
dotnet-version: 3.1.x
|
||||||
- name: Publish the package to nuget.org
|
- name: Publish the package to nuget.org
|
||||||
@@ -164,91 +134,32 @@ steps:
|
|||||||
env:
|
env:
|
||||||
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_TOKEN }}
|
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_TOKEN }}
|
||||||
```
|
```
|
||||||
> **Note**: It's the only way to push a package to nuget.org feed for macOS/Linux machines due to API key config store limitations.
|
|
||||||
|
|
||||||
# Outputs and environment variables
|
## Environment Variables to use with dotnet
|
||||||
|
|
||||||
## Outputs
|
|
||||||
|
|
||||||
### `dotnet-version`
|
|
||||||
|
|
||||||
Using the **dotnet-version** output it's possible to get the installed by the action .NET SDK version.
|
|
||||||
|
|
||||||
**Single version installation**
|
|
||||||
|
|
||||||
In case of a single version installation, the `dotnet-version` output contains the version that is installed by the action.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
- uses: actions/setup-dotnet@v3
|
|
||||||
id: stepid
|
|
||||||
with:
|
|
||||||
dotnet-version: 3.1.422
|
|
||||||
- run: echo '${{ steps.stepid.outputs.dotnet-version }}' # outputs 3.1.422
|
|
||||||
```
|
|
||||||
|
|
||||||
**Multiple version installation**
|
|
||||||
|
|
||||||
In case of a multiple version installation, the `dotnet-version` output contains the latest version that is installed by the action.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
- uses: actions/setup-dotnet@v3
|
|
||||||
id: stepid
|
|
||||||
with:
|
|
||||||
dotnet-version: |
|
|
||||||
3.1.422
|
|
||||||
5.0.408
|
|
||||||
- run: echo '${{ steps.stepid.outputs.dotnet-version }}' # outputs 5.0.408
|
|
||||||
```
|
|
||||||
**Installation from global.json**
|
|
||||||
|
|
||||||
When the `dotnet-version` input is used along with the `global-json-file` input, the `dotnet-version` output contains the version resolved from the `global.json`.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
- uses: actions/setup-dotnet@v3
|
|
||||||
id: stepid
|
|
||||||
with:
|
|
||||||
dotnet-version: |
|
|
||||||
3.1.422
|
|
||||||
5.0.408
|
|
||||||
global-json-file: "./global.json" # contains version 2.2.207
|
|
||||||
- run: echo '${{ steps.stepid.outputs.dotnet-version }}' # outputs 2.2.207
|
|
||||||
```
|
|
||||||
|
|
||||||
## Environment variables
|
|
||||||
|
|
||||||
Some environment variables may be necessary for your particular case or to improve logging. Some examples are listed below, but the full list with complete details can be found here: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables
|
Some environment variables may be necessary for your particular case or to improve logging. Some examples are listed below, but the full list with complete details can be found here: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables
|
||||||
|
|
||||||
| **Env.variable** | **Description** | **Default value** |
|
- DOTNET_NOLOGO - removes logo and telemetry message from first run of dotnet cli (default: false)
|
||||||
| ----------- | ----------- | ----------- |
|
- DOTNET_CLI_TELEMETRY_OPTOUT - opt-out of telemetry being sent to Microsoft (default: false)
|
||||||
| DOTNET_INSTALL_DIR |Specifies a directory where .NET SDKs should be installed by the action.|*default value for each OS* |
|
- DOTNET_MULTILEVEL_LOOKUP - configures whether the global install location is used as a fall-back (default: true)
|
||||||
| DOTNET_NOLOGO |Removes logo and telemetry message from first run of dotnet cli|*false*|
|
|
||||||
| DOTNET_CLI_TELEMETRY_OPTOUT |Opt-out of telemetry being sent to Microsoft|*false*|
|
|
||||||
| DOTNET_MULTILEVEL_LOOKUP |Configures whether the global install location is used as a fall-back|*true*|
|
|
||||||
|
|
||||||
The default value of the `DOTNET_INSTALL_DIR` environment variable depends on the operation system which is used on a runner:
|
Example usage:
|
||||||
| **Operation system** | **Default value** |
|
```yaml
|
||||||
| ----------- | ----------- |
|
|
||||||
| **Windows** | `C:\Program Files\dotnet` |
|
|
||||||
| **Ubuntu** | `/usr/share/dotnet` |
|
|
||||||
| **macOS** | `/Users/runner/.dotnet` |
|
|
||||||
|
|
||||||
**Example usage**:
|
|
||||||
```yml
|
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
DOTNET_INSTALL_DIR: "path/to/directory"
|
DOTNET_NOLOGO: true
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@main
|
- uses: actions/checkout@main
|
||||||
- uses: actions/setup-dotnet@v3
|
- uses: actions/setup-dotnet@v2
|
||||||
with:
|
with:
|
||||||
dotnet-version: '3.1.x'
|
dotnet-version: '3.1.x' # SDK Version to use.
|
||||||
```
|
```
|
||||||
|
|
||||||
## License
|
# License
|
||||||
|
|
||||||
The scripts and documentation in this project are released under the [MIT License](LICENSE)
|
The scripts and documentation in this project are released under the [MIT License](LICENSE)
|
||||||
|
|
||||||
## Contributions
|
# Contributions
|
||||||
|
|
||||||
Contributions are welcome! See [Contributor's Guide](docs/contributors.md)
|
Contributions are welcome! See [Contributor's Guide](docs/contributors.md)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`authutil tests existing config not in repo root, sets up a partial NuGet.config user/PAT for GPR 1`] = `
|
exports[`authutil tests Existing config not in repo root, sets up a partial NuGet.config user/PAT for GPR 1`] = `
|
||||||
"<?xml version=\\"1.0\\"?>
|
"<?xml version=\\"1.0\\"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<config>
|
<config>
|
||||||
@@ -15,7 +15,7 @@ exports[`authutil tests existing config not in repo root, sets up a partial NuGe
|
|||||||
</configuration>"
|
</configuration>"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`authutil tests existing config w/ Azure Artifacts source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR 1`] = `
|
exports[`authutil tests Existing config w/ Azure Artifacts source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR 1`] = `
|
||||||
"<?xml version=\\"1.0\\"?>
|
"<?xml version=\\"1.0\\"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<config>
|
<config>
|
||||||
@@ -30,7 +30,7 @@ exports[`authutil tests existing config w/ Azure Artifacts source and NuGet.org,
|
|||||||
</configuration>"
|
</configuration>"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`authutil tests existing config w/ GPR source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR 1`] = `
|
exports[`authutil tests Existing config w/ GPR source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR 1`] = `
|
||||||
"<?xml version=\\"1.0\\"?>
|
"<?xml version=\\"1.0\\"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<config>
|
<config>
|
||||||
@@ -45,7 +45,7 @@ exports[`authutil tests existing config w/ GPR source and NuGet.org, sets up a p
|
|||||||
</configuration>"
|
</configuration>"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`authutil tests existing config w/ no GPR sources, sets up a full NuGet.config with URL and user/PAT for GPR 1`] = `
|
exports[`authutil tests Existing config w/ no GPR sources, sets up a full NuGet.config with URL and user/PAT for GPR 1`] = `
|
||||||
"<?xml version=\\"1.0\\"?>
|
"<?xml version=\\"1.0\\"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<config>
|
<config>
|
||||||
@@ -63,7 +63,7 @@ exports[`authutil tests existing config w/ no GPR sources, sets up a full NuGet.
|
|||||||
</configuration>"
|
</configuration>"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`authutil tests existing config w/ no sources, sets up a full NuGet.config with URL and user/PAT for GPR 1`] = `
|
exports[`authutil tests Existing config w/ no sources, sets up a full NuGet.config with URL and user/PAT for GPR 1`] = `
|
||||||
"<?xml version=\\"1.0\\"?>
|
"<?xml version=\\"1.0\\"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<config>
|
<config>
|
||||||
@@ -81,7 +81,7 @@ exports[`authutil tests existing config w/ no sources, sets up a full NuGet.conf
|
|||||||
</configuration>"
|
</configuration>"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`authutil tests existing config w/ only Azure Artifacts source, sets up a partial NuGet.config user/PAT for GPR 1`] = `
|
exports[`authutil tests Existing config w/ only Azure Artifacts source, sets up a partial NuGet.config user/PAT for GPR 1`] = `
|
||||||
"<?xml version=\\"1.0\\"?>
|
"<?xml version=\\"1.0\\"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<config>
|
<config>
|
||||||
@@ -96,7 +96,7 @@ exports[`authutil tests existing config w/ only Azure Artifacts source, sets up
|
|||||||
</configuration>"
|
</configuration>"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`authutil tests existing config w/ only GPR source, sets up a partial NuGet.config user/PAT for GPR 1`] = `
|
exports[`authutil tests Existing config w/ only GPR source, sets up a partial NuGet.config user/PAT for GPR 1`] = `
|
||||||
"<?xml version=\\"1.0\\"?>
|
"<?xml version=\\"1.0\\"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<config>
|
<config>
|
||||||
@@ -111,7 +111,7 @@ exports[`authutil tests existing config w/ only GPR source, sets up a partial Nu
|
|||||||
</configuration>"
|
</configuration>"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`authutil tests existing config w/ two GPR sources, sets up a partial NuGet.config user/PAT for GPR 1`] = `
|
exports[`authutil tests Existing config w/ two GPR sources, sets up a partial NuGet.config user/PAT for GPR 1`] = `
|
||||||
"<?xml version=\\"1.0\\"?>
|
"<?xml version=\\"1.0\\"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<config>
|
<config>
|
||||||
@@ -130,7 +130,7 @@ exports[`authutil tests existing config w/ two GPR sources, sets up a partial Nu
|
|||||||
</configuration>"
|
</configuration>"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`authutil tests no existing config, sets up a full NuGet.config with URL and other owner/PAT for GPR 1`] = `
|
exports[`authutil tests No existing config, sets up a full NuGet.config with URL and other owner/PAT for GPR 1`] = `
|
||||||
"<?xml version=\\"1.0\\"?>
|
"<?xml version=\\"1.0\\"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<config>
|
<config>
|
||||||
@@ -148,7 +148,7 @@ exports[`authutil tests no existing config, sets up a full NuGet.config with URL
|
|||||||
</configuration>"
|
</configuration>"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`authutil tests no existing config, sets up a full NuGet.config with URL and token for other source 1`] = `
|
exports[`authutil tests No existing config, sets up a full NuGet.config with URL and token for other source 1`] = `
|
||||||
"<?xml version=\\"1.0\\"?>
|
"<?xml version=\\"1.0\\"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<config>
|
<config>
|
||||||
@@ -166,7 +166,7 @@ exports[`authutil tests no existing config, sets up a full NuGet.config with URL
|
|||||||
</configuration>"
|
</configuration>"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`authutil tests no existing config, sets up a full NuGet.config with URL and user/PAT for GPR 1`] = `
|
exports[`authutil tests No existing config, sets up a full NuGet.config with URL and user/PAT for GPR 1`] = `
|
||||||
"<?xml version=\\"1.0\\"?>
|
"<?xml version=\\"1.0\\"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<config>
|
<config>
|
||||||
|
|||||||
@@ -1,336 +1,340 @@
|
|||||||
import * as io from '@actions/io';
|
import io = require('@actions/io');
|
||||||
import fs from 'fs';
|
import fs = require('fs');
|
||||||
import path from 'path';
|
import path = require('path');
|
||||||
|
|
||||||
const fakeSourcesDirForTesting = path.join(
|
const fakeSourcesDirForTesting = path.join(
|
||||||
__dirname,
|
__dirname,
|
||||||
'runner',
|
'runner',
|
||||||
path.join(Math.random().toString(36).substring(7)),
|
path.join(
|
||||||
's'
|
Math.random()
|
||||||
);
|
.toString(36)
|
||||||
|
.substring(7)
|
||||||
const invalidNuGetConfig = `<?xml version="1.0" encoding="utf-8"?>`;
|
),
|
||||||
|
's'
|
||||||
const emptyNuGetConfig = `<?xml version="1.0" encoding="utf-8"?>
|
);
|
||||||
<configuration>
|
|
||||||
</configuration>`;
|
const invalidNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>`;
|
||||||
|
|
||||||
const nugetorgNuGetConfig = `<?xml version="1.0" encoding="utf-8"?>
|
const emptyNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<packageSources>
|
</configuration>`;
|
||||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
|
||||||
</packageSources>
|
const nugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
</configuration>`;
|
<configuration>
|
||||||
|
<packageSources>
|
||||||
const gprnugetorgNuGetConfig = `<?xml version="1.0" encoding="utf-8"?>
|
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||||
<configuration>
|
</packageSources>
|
||||||
<packageSources>
|
</configuration>`;
|
||||||
<add key="GPR" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
|
||||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
const gprnugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
</packageSources>
|
<configuration>
|
||||||
</configuration>`;
|
<packageSources>
|
||||||
|
<add key="GPR" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
||||||
const gprNuGetConfig = `<?xml version="1.0" encoding="utf-8"?>
|
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||||
<configuration>
|
</packageSources>
|
||||||
<packageSources>
|
</configuration>`;
|
||||||
<add key="GPR" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
|
||||||
</packageSources>
|
const gprNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
</configuration>`;
|
<configuration>
|
||||||
|
<packageSources>
|
||||||
const twogprNuGetConfig = `<?xml version="1.0" encoding="utf-8"?>
|
<add key="GPR" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
||||||
<configuration>
|
</packageSources>
|
||||||
<packageSources>
|
</configuration>`;
|
||||||
<add key="GPR-GitHub" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
|
||||||
<add key="GPR-Actions" value="https://nuget.pkg.github.com/actions/index.json" protocolVersion="3" />
|
const twogprNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
</packageSources>
|
<configuration>
|
||||||
</configuration>`;
|
<packageSources>
|
||||||
|
<add key="GPR-GitHub" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
||||||
const spaceNuGetConfig = `<?xml version="1.0" encoding="utf-8"?>
|
<add key="GPR-Actions" value="https://nuget.pkg.github.com/actions/index.json" protocolVersion="3" />
|
||||||
<configuration>
|
</packageSources>
|
||||||
<packageSources>
|
</configuration>`;
|
||||||
<add key="GPR GitHub" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
|
||||||
</packageSources>
|
const spaceNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
</configuration>`;
|
<configuration>
|
||||||
|
<packageSources>
|
||||||
const azureartifactsNuGetConfig = `<?xml version="1.0" encoding="utf-8"?>
|
<add key="GPR GitHub" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
|
||||||
<configuration>
|
</packageSources>
|
||||||
<packageSources>
|
</configuration>`;
|
||||||
<add key="AzureArtifacts" value="https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json" protocolVersion="3" />
|
|
||||||
</packageSources>
|
const azureartifactsNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
</configuration>`;
|
<configuration>
|
||||||
|
<packageSources>
|
||||||
const azureartifactsnugetorgNuGetConfig = `<?xml version="1.0" encoding="utf-8"?>
|
<add key="AzureArtifacts" value="https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json" protocolVersion="3" />
|
||||||
<configuration>
|
</packageSources>
|
||||||
<packageSources>
|
</configuration>`;
|
||||||
<add key="AzureArtifacts" value="https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json" protocolVersion="3" />
|
|
||||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
const azureartifactsnugetorgNuGetConfig: string = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
</packageSources>
|
<configuration>
|
||||||
</configuration>`;
|
<packageSources>
|
||||||
|
<add key="AzureArtifacts" value="https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json" protocolVersion="3" />
|
||||||
// We want a NuGet.config one level above the sources directory, so it doesn't trample a user's NuGet.config but is still picked up by NuGet/dotnet.
|
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||||
const nugetConfigFile = path.join(fakeSourcesDirForTesting, '../nuget.config');
|
</packageSources>
|
||||||
|
</configuration>`;
|
||||||
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
|
|
||||||
import * as auth from '../src/authutil';
|
// We want a NuGet.config one level above the sources directory, so it doesn't trample a user's NuGet.config but is still picked up by NuGet/dotnet.
|
||||||
|
const nugetConfigFile = path.join(fakeSourcesDirForTesting, '../nuget.config');
|
||||||
describe('authutil tests', () => {
|
|
||||||
beforeEach(async () => {
|
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
|
||||||
await io.rmRF(fakeSourcesDirForTesting);
|
import * as auth from '../src/authutil';
|
||||||
await io.mkdirP(fakeSourcesDirForTesting);
|
|
||||||
}, 30000);
|
describe('authutil tests', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
afterAll(async () => {
|
await io.rmRF(fakeSourcesDirForTesting);
|
||||||
await io.rmRF(fakeSourcesDirForTesting);
|
await io.mkdirP(fakeSourcesDirForTesting);
|
||||||
}, 30000);
|
}, 30000);
|
||||||
|
|
||||||
beforeEach(() => {
|
afterAll(async () => {
|
||||||
if (fs.existsSync(nugetConfigFile)) {
|
await io.rmRF(fakeSourcesDirForTesting);
|
||||||
fs.unlinkSync(nugetConfigFile);
|
}, 30000);
|
||||||
}
|
|
||||||
process.env['INPUT_OWNER'] = '';
|
beforeEach(() => {
|
||||||
process.env['NUGET_AUTH_TOKEN'] = '';
|
if (fs.existsSync(nugetConfigFile)) {
|
||||||
});
|
fs.unlinkSync(nugetConfigFile);
|
||||||
|
}
|
||||||
it('no existing config, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
|
process.env['INPUT_OWNER'] = '';
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
process.env['NUGET_AUTH_TOKEN'] = '';
|
||||||
auth.configAuthentication(
|
});
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
|
||||||
'',
|
it('No existing config, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
|
||||||
fakeSourcesDirForTesting
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
);
|
await auth.configAuthentication(
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
expect(
|
'',
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fakeSourcesDirForTesting
|
||||||
).toMatchSnapshot();
|
);
|
||||||
});
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
|
expect(
|
||||||
it('no existing config, auth token environment variable not provided, throws', async () => {
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
let thrown = false;
|
).toMatchSnapshot();
|
||||||
try {
|
});
|
||||||
auth.configAuthentication(
|
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
it('No existing config, auth token environment variable not provided, throws', async () => {
|
||||||
'',
|
let thrown = false;
|
||||||
fakeSourcesDirForTesting
|
try {
|
||||||
);
|
await auth.configAuthentication(
|
||||||
} catch {
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
thrown = true;
|
'',
|
||||||
}
|
fakeSourcesDirForTesting
|
||||||
expect(thrown).toBe(true);
|
);
|
||||||
});
|
} catch {
|
||||||
|
thrown = true;
|
||||||
it('no existing config, sets up a full NuGet.config with URL and other owner/PAT for GPR', async () => {
|
}
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
expect(thrown).toBe(true);
|
||||||
process.env['INPUT_OWNER'] = 'otherorg';
|
});
|
||||||
auth.configAuthentication(
|
|
||||||
'https://nuget.pkg.github.com/otherorg/index.json',
|
it('No existing config, sets up a full NuGet.config with URL and other owner/PAT for GPR', async () => {
|
||||||
'',
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
fakeSourcesDirForTesting
|
process.env['INPUT_OWNER'] = 'otherorg';
|
||||||
);
|
await auth.configAuthentication(
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
'https://nuget.pkg.github.com/otherorg/index.json',
|
||||||
expect(
|
'',
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fakeSourcesDirForTesting
|
||||||
).toMatchSnapshot();
|
);
|
||||||
});
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
|
expect(
|
||||||
it('existing config (invalid), tries to parse an invalid NuGet.config and throws', async () => {
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
).toMatchSnapshot();
|
||||||
const inputNuGetConfigPath: string = path.join(
|
});
|
||||||
fakeSourcesDirForTesting,
|
|
||||||
'nuget.config'
|
it('Existing config (invalid), tries to parse an invalid NuGet.config and throws', async () => {
|
||||||
);
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
fs.writeFileSync(inputNuGetConfigPath, invalidNuGetConfig);
|
const inputNuGetConfigPath: string = path.join(
|
||||||
let thrown = false;
|
fakeSourcesDirForTesting,
|
||||||
try {
|
'nuget.config'
|
||||||
auth.configAuthentication(
|
);
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
fs.writeFileSync(inputNuGetConfigPath, invalidNuGetConfig);
|
||||||
'',
|
let thrown = false;
|
||||||
fakeSourcesDirForTesting
|
try {
|
||||||
);
|
await auth.configAuthentication(
|
||||||
} catch {
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
thrown = true;
|
'',
|
||||||
}
|
fakeSourcesDirForTesting
|
||||||
expect(thrown).toBe(true);
|
);
|
||||||
});
|
} catch {
|
||||||
|
thrown = true;
|
||||||
it('existing config w/ no sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
|
}
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
expect(thrown).toBe(true);
|
||||||
const inputNuGetConfigPath: string = path.join(
|
});
|
||||||
fakeSourcesDirForTesting,
|
|
||||||
'nuget.config'
|
it('Existing config w/ no sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
|
||||||
);
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
fs.writeFileSync(inputNuGetConfigPath, emptyNuGetConfig);
|
const inputNuGetConfigPath: string = path.join(
|
||||||
auth.configAuthentication(
|
fakeSourcesDirForTesting,
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
'nuget.config'
|
||||||
'',
|
);
|
||||||
fakeSourcesDirForTesting
|
fs.writeFileSync(inputNuGetConfigPath, emptyNuGetConfig);
|
||||||
);
|
await auth.configAuthentication(
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
expect(
|
'',
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fakeSourcesDirForTesting
|
||||||
).toMatchSnapshot();
|
);
|
||||||
});
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
|
expect(
|
||||||
it('existing config w/ no GPR sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
).toMatchSnapshot();
|
||||||
const inputNuGetConfigPath: string = path.join(
|
});
|
||||||
fakeSourcesDirForTesting,
|
|
||||||
'nuget.config'
|
it('Existing config w/ no GPR sources, sets up a full NuGet.config with URL and user/PAT for GPR', async () => {
|
||||||
);
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
fs.writeFileSync(inputNuGetConfigPath, nugetorgNuGetConfig);
|
const inputNuGetConfigPath: string = path.join(
|
||||||
auth.configAuthentication(
|
fakeSourcesDirForTesting,
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
'nuget.config'
|
||||||
'',
|
);
|
||||||
fakeSourcesDirForTesting
|
fs.writeFileSync(inputNuGetConfigPath, nugetorgNuGetConfig);
|
||||||
);
|
await auth.configAuthentication(
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
expect(
|
'',
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fakeSourcesDirForTesting
|
||||||
).toMatchSnapshot();
|
);
|
||||||
});
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
|
expect(
|
||||||
it('existing config w/ only GPR source, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
).toMatchSnapshot();
|
||||||
const inputNuGetConfigPath: string = path.join(
|
});
|
||||||
fakeSourcesDirForTesting,
|
|
||||||
'nuget.config'
|
it('Existing config w/ only GPR source, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
||||||
);
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
const inputNuGetConfigPath: string = path.join(
|
||||||
auth.configAuthentication(
|
fakeSourcesDirForTesting,
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
'nuget.config'
|
||||||
'',
|
);
|
||||||
fakeSourcesDirForTesting
|
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
||||||
);
|
await auth.configAuthentication(
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
expect(
|
'',
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fakeSourcesDirForTesting
|
||||||
).toMatchSnapshot();
|
);
|
||||||
});
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
|
expect(
|
||||||
it('existing config w/ GPR source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
).toMatchSnapshot();
|
||||||
const inputNuGetConfigPath: string = path.join(
|
});
|
||||||
fakeSourcesDirForTesting,
|
|
||||||
'nuget.config'
|
it('Existing config w/ GPR source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
||||||
);
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
fs.writeFileSync(inputNuGetConfigPath, gprnugetorgNuGetConfig);
|
const inputNuGetConfigPath: string = path.join(
|
||||||
auth.configAuthentication(
|
fakeSourcesDirForTesting,
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
'nuget.config'
|
||||||
'',
|
);
|
||||||
fakeSourcesDirForTesting
|
fs.writeFileSync(inputNuGetConfigPath, gprnugetorgNuGetConfig);
|
||||||
);
|
await auth.configAuthentication(
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
expect(
|
'',
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fakeSourcesDirForTesting
|
||||||
).toMatchSnapshot();
|
);
|
||||||
});
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
|
expect(
|
||||||
it('existing config w/ two GPR sources, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
).toMatchSnapshot();
|
||||||
const inputNuGetConfigPath: string = path.join(
|
});
|
||||||
fakeSourcesDirForTesting,
|
|
||||||
'nuget.config'
|
it('Existing config w/ two GPR sources, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
||||||
);
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
fs.writeFileSync(inputNuGetConfigPath, twogprNuGetConfig);
|
const inputNuGetConfigPath: string = path.join(
|
||||||
auth.configAuthentication(
|
fakeSourcesDirForTesting,
|
||||||
'https://nuget.pkg.github.com',
|
'nuget.config'
|
||||||
'',
|
);
|
||||||
fakeSourcesDirForTesting
|
fs.writeFileSync(inputNuGetConfigPath, twogprNuGetConfig);
|
||||||
);
|
await auth.configAuthentication(
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
'https://nuget.pkg.github.com',
|
||||||
expect(
|
'',
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fakeSourcesDirForTesting
|
||||||
).toMatchSnapshot();
|
);
|
||||||
});
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
|
expect(
|
||||||
it('existing config w/ spaces in key, throws for now', async () => {
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
).toMatchSnapshot();
|
||||||
const inputNuGetConfigPath: string = path.join(
|
});
|
||||||
fakeSourcesDirForTesting,
|
|
||||||
'nuget.config'
|
it('Existing config w/ spaces in key, throws for now', async () => {
|
||||||
);
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
fs.writeFileSync(inputNuGetConfigPath, spaceNuGetConfig);
|
const inputNuGetConfigPath: string = path.join(
|
||||||
let thrown = false;
|
fakeSourcesDirForTesting,
|
||||||
try {
|
'nuget.config'
|
||||||
auth.configAuthentication(
|
);
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
fs.writeFileSync(inputNuGetConfigPath, spaceNuGetConfig);
|
||||||
'',
|
let thrown = false;
|
||||||
fakeSourcesDirForTesting
|
try {
|
||||||
);
|
await auth.configAuthentication(
|
||||||
} catch {
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
thrown = true;
|
'',
|
||||||
}
|
fakeSourcesDirForTesting
|
||||||
expect(thrown).toBe(true);
|
);
|
||||||
});
|
} catch {
|
||||||
|
thrown = true;
|
||||||
it('existing config not in repo root, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
}
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
expect(thrown).toBe(true);
|
||||||
const inputNuGetConfigDirectory: string = path.join(
|
});
|
||||||
fakeSourcesDirForTesting,
|
|
||||||
'subfolder'
|
it('Existing config not in repo root, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
||||||
);
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
const inputNuGetConfigPath: string = path.join(
|
const inputNuGetConfigDirectory: string = path.join(
|
||||||
inputNuGetConfigDirectory,
|
fakeSourcesDirForTesting,
|
||||||
'nuget.config'
|
'subfolder'
|
||||||
);
|
);
|
||||||
fs.mkdirSync(inputNuGetConfigDirectory, {recursive: true});
|
const inputNuGetConfigPath: string = path.join(
|
||||||
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
inputNuGetConfigDirectory,
|
||||||
auth.configAuthentication(
|
'nuget.config'
|
||||||
'https://nuget.pkg.github.com/OwnerName/index.json',
|
);
|
||||||
'subfolder/nuget.config',
|
fs.mkdirSync(inputNuGetConfigDirectory, {recursive: true});
|
||||||
fakeSourcesDirForTesting
|
fs.writeFileSync(inputNuGetConfigPath, gprNuGetConfig);
|
||||||
);
|
await auth.configAuthentication(
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
'https://nuget.pkg.github.com/OwnerName/index.json',
|
||||||
expect(
|
'subfolder/nuget.config',
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fakeSourcesDirForTesting
|
||||||
).toMatchSnapshot();
|
);
|
||||||
});
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
|
expect(
|
||||||
it('existing config w/ only Azure Artifacts source, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
).toMatchSnapshot();
|
||||||
const inputNuGetConfigPath: string = path.join(
|
});
|
||||||
fakeSourcesDirForTesting,
|
|
||||||
'nuget.config'
|
it('Existing config w/ only Azure Artifacts source, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
||||||
);
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
fs.writeFileSync(inputNuGetConfigPath, azureartifactsNuGetConfig);
|
const inputNuGetConfigPath: string = path.join(
|
||||||
auth.configAuthentication(
|
fakeSourcesDirForTesting,
|
||||||
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
'nuget.config'
|
||||||
'',
|
);
|
||||||
fakeSourcesDirForTesting
|
fs.writeFileSync(inputNuGetConfigPath, azureartifactsNuGetConfig);
|
||||||
);
|
await auth.configAuthentication(
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
||||||
expect(
|
'',
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fakeSourcesDirForTesting
|
||||||
).toMatchSnapshot();
|
);
|
||||||
});
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
|
expect(
|
||||||
it('existing config w/ Azure Artifacts source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
).toMatchSnapshot();
|
||||||
const inputNuGetConfigPath: string = path.join(
|
});
|
||||||
fakeSourcesDirForTesting,
|
|
||||||
'nuget.config'
|
it('Existing config w/ Azure Artifacts source and NuGet.org, sets up a partial NuGet.config user/PAT for GPR', async () => {
|
||||||
);
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
fs.writeFileSync(inputNuGetConfigPath, azureartifactsnugetorgNuGetConfig);
|
const inputNuGetConfigPath: string = path.join(
|
||||||
auth.configAuthentication(
|
fakeSourcesDirForTesting,
|
||||||
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
'nuget.config'
|
||||||
'',
|
);
|
||||||
fakeSourcesDirForTesting
|
fs.writeFileSync(inputNuGetConfigPath, azureartifactsnugetorgNuGetConfig);
|
||||||
);
|
await auth.configAuthentication(
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
||||||
expect(
|
'',
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fakeSourcesDirForTesting
|
||||||
).toMatchSnapshot();
|
);
|
||||||
});
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
|
expect(
|
||||||
it('no existing config, sets up a full NuGet.config with URL and token for other source', async () => {
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
).toMatchSnapshot();
|
||||||
auth.configAuthentication(
|
});
|
||||||
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
|
||||||
'',
|
it('No existing config, sets up a full NuGet.config with URL and token for other source', async () => {
|
||||||
fakeSourcesDirForTesting
|
process.env['NUGET_AUTH_TOKEN'] = 'TEST_FAKE_AUTH_TOKEN';
|
||||||
);
|
await auth.configAuthentication(
|
||||||
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
'https://pkgs.dev.azure.com/amullans/_packaging/GitHubBuilds/nuget/v3/index.json',
|
||||||
expect(
|
'',
|
||||||
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
fakeSourcesDirForTesting
|
||||||
).toMatchSnapshot();
|
);
|
||||||
});
|
expect(fs.existsSync(nugetConfigFile)).toBe(true);
|
||||||
});
|
expect(
|
||||||
|
fs.readFileSync(nugetConfigFile, {encoding: 'utf8'})
|
||||||
|
).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,45 +1,23 @@
|
|||||||
import cscFile from '../.github/csc.json';
|
import fs = require('fs');
|
||||||
|
|
||||||
describe('csc tests', () => {
|
describe('csc tests', () => {
|
||||||
test('regular expression in csc.json is valid', async () => {
|
it('Valid regular expression', async () => {
|
||||||
const regexPattern = cscFile['problemMatcher'][0]['pattern'][0]['regexp'];
|
var cscFile = require('../.github/csc.json');
|
||||||
const regexResultsMap = cscFile['problemMatcher'][0]['pattern'][0];
|
var regex = cscFile['problemMatcher'][0]['pattern'][0]['regexp'];
|
||||||
|
|
||||||
const regex = new RegExp(regexPattern);
|
console.log(regex);
|
||||||
|
var re = new RegExp(regex);
|
||||||
|
|
||||||
const stringsToMatch = [
|
// Ideally we would verify that this
|
||||||
|
var stringsToMatch = [
|
||||||
'Program.cs(10,79): error CS1002: ; expected [/Users/zacharyeisinger/Documents/repo/setup-dotnet/__tests__/sample-broken-csproj/sample.csproj]',
|
'Program.cs(10,79): error CS1002: ; expected [/Users/zacharyeisinger/Documents/repo/setup-dotnet/__tests__/sample-broken-csproj/sample.csproj]',
|
||||||
"S:\\Msbuild\\src\\Build\\Evaluation\\ExpressionShredder.cs(33,7): error CS1003: Syntax error, ',' expected [S:\\msbuild\\src\\Build\\Microsoft.Build.csproj > Properties:prop]"
|
"S:\\Msbuild\\src\\Build\\Evaluation\\ExpressionShredder.cs(33,7): error CS1003: Syntax error, ',' expected [S:\\msbuild\\src\\Build\\Microsoft.Build.csproj > Properties:prop]"
|
||||||
];
|
];
|
||||||
// Expected results are calculated according to the csc matcher located in csc.json file
|
|
||||||
const expectedResults = [
|
|
||||||
{
|
|
||||||
file: 'Program.cs',
|
|
||||||
line: '10',
|
|
||||||
severity: 'error',
|
|
||||||
code: 'CS1002',
|
|
||||||
message: '; expected',
|
|
||||||
fromPath:
|
|
||||||
'/Users/zacharyeisinger/Documents/repo/setup-dotnet/__tests__/sample-broken-csproj/sample.csproj'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
file: 'S:\\Msbuild\\src\\Build\\Evaluation\\ExpressionShredder.cs',
|
|
||||||
line: '33',
|
|
||||||
severity: 'error',
|
|
||||||
code: 'CS1003',
|
|
||||||
message: "Syntax error, ',' expected",
|
|
||||||
fromPath:
|
|
||||||
'S:\\msbuild\\src\\Build\\Microsoft.Build.csproj > Properties:prop'
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
stringsToMatch.map((string, index) => {
|
stringsToMatch.forEach(string => {
|
||||||
const matchedResultsArray = string.match(regex);
|
var matchStr = string.match(re);
|
||||||
for (const propName in expectedResults[index]) {
|
console.log(matchStr);
|
||||||
const propertyIndex = regexResultsMap[propName];
|
expect(matchStr).toEqual(expect.anything());
|
||||||
const expectedPropValue = expectedResults[index][propName];
|
|
||||||
const matchedPropValue = matchedResultsArray![propertyIndex];
|
|
||||||
expect(matchedPropValue).toEqual(expectedPropValue);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}, 10000);
|
}, 10000);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace test_csproj
|
|
||||||
{
|
|
||||||
[TestClass]
|
|
||||||
public class Test
|
|
||||||
{
|
|
||||||
[TestMethod]
|
|
||||||
public void TestMethod()
|
|
||||||
{
|
|
||||||
Console.WriteLine("TestMethod");
|
|
||||||
int calculatedResult = 1000 / 25;
|
|
||||||
int expectedResult = 40;
|
|
||||||
Assert.AreEqual(calculatedResult, expectedResult);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>$(TEST_TARGET_FRAMEWORK)</TargetFramework>
|
|
||||||
<IsPackable>false</IsPackable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<!-- These packages will be downloaded over the network for testing proxy settings -->
|
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170810-02" />
|
|
||||||
<PackageReference Include="MSTest.TestAdapter" Version="1.1.18" />
|
|
||||||
<PackageReference Include="MSTest.TestFramework" Version="1.1.18" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
import path from 'path';
|
|
||||||
import fs from 'fs';
|
|
||||||
import * as hc from '@actions/http-client';
|
|
||||||
|
|
||||||
const HTTP_CLIENT_OPTIONS = {allowRetries: true, maxRetries: 10} as const;
|
|
||||||
const TEST_TIMEOUT = 30000;
|
|
||||||
|
|
||||||
describe('Dotnet installation scripts tests', () => {
|
|
||||||
it(
|
|
||||||
'Uses an up to date bash download script',
|
|
||||||
async () => {
|
|
||||||
const httpCallbackClient = new hc.HttpClient(
|
|
||||||
'setup-dotnet-test',
|
|
||||||
[],
|
|
||||||
HTTP_CLIENT_OPTIONS
|
|
||||||
);
|
|
||||||
const response: hc.HttpClientResponse = await httpCallbackClient.get(
|
|
||||||
'https://dot.net/v1/dotnet-install.sh'
|
|
||||||
);
|
|
||||||
expect(response.message.statusCode).toBe(200);
|
|
||||||
const upToDateContents: string = await response.readBody();
|
|
||||||
const currentContents: string = fs
|
|
||||||
.readFileSync(
|
|
||||||
path.join(__dirname, '..', 'externals', 'install-dotnet.sh')
|
|
||||||
)
|
|
||||||
.toString();
|
|
||||||
expect(normalizeFileContents(currentContents)).toBe(
|
|
||||||
normalizeFileContents(upToDateContents)
|
|
||||||
);
|
|
||||||
},
|
|
||||||
TEST_TIMEOUT
|
|
||||||
);
|
|
||||||
|
|
||||||
it(
|
|
||||||
'Uses an up to date powershell download script',
|
|
||||||
async () => {
|
|
||||||
const httpCallbackClient = new hc.HttpClient(
|
|
||||||
'setup-dotnet-test',
|
|
||||||
[],
|
|
||||||
HTTP_CLIENT_OPTIONS
|
|
||||||
);
|
|
||||||
const response: hc.HttpClientResponse = await httpCallbackClient.get(
|
|
||||||
'https://dot.net/v1/dotnet-install.ps1'
|
|
||||||
);
|
|
||||||
expect(response.message.statusCode).toBe(200);
|
|
||||||
const upToDateContents: string = await response.readBody();
|
|
||||||
const currentContents: string = fs
|
|
||||||
.readFileSync(
|
|
||||||
path.join(__dirname, '..', 'externals', 'install-dotnet.ps1')
|
|
||||||
)
|
|
||||||
.toString();
|
|
||||||
expect(normalizeFileContents(currentContents)).toBe(
|
|
||||||
normalizeFileContents(upToDateContents)
|
|
||||||
);
|
|
||||||
},
|
|
||||||
TEST_TIMEOUT
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
function normalizeFileContents(contents: string): string {
|
|
||||||
return contents
|
|
||||||
.trim()
|
|
||||||
.replace(new RegExp('\r\n', 'g'), '\n')
|
|
||||||
.replace(new RegExp('\r', 'g'), '\n');
|
|
||||||
}
|
|
||||||
@@ -1,443 +1,151 @@
|
|||||||
import each from 'jest-each';
|
import io = require('@actions/io');
|
||||||
import semver from 'semver';
|
import fs = require('fs');
|
||||||
import * as exec from '@actions/exec';
|
import os = require('os');
|
||||||
import * as core from '@actions/core';
|
import path = require('path');
|
||||||
import * as io from '@actions/io';
|
import hc = require('@actions/http-client');
|
||||||
|
|
||||||
|
const toolDir = path.join(__dirname, 'runner', 'tools');
|
||||||
|
const tempDir = path.join(__dirname, 'runner', 'temp');
|
||||||
|
|
||||||
|
process.env['RUNNER_TOOL_CACHE'] = toolDir;
|
||||||
|
process.env['RUNNER_TEMP'] = tempDir;
|
||||||
import * as installer from '../src/installer';
|
import * as installer from '../src/installer';
|
||||||
|
|
||||||
import {IS_WINDOWS} from '../src/utils';
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
import {QualityOptions} from '../src/setup-dotnet';
|
|
||||||
|
|
||||||
describe('installer tests', () => {
|
describe('installer tests', () => {
|
||||||
const env = process.env;
|
beforeAll(async () => {
|
||||||
|
process.env.RUNNER_TOOL_CACHE = toolDir;
|
||||||
beforeEach(() => {
|
process.env.DOTNET_INSTALL_DIR = toolDir;
|
||||||
jest.resetModules();
|
process.env.RUNNER_TEMP = tempDir;
|
||||||
process.env = {...env};
|
process.env.DOTNET_ROOT = '';
|
||||||
|
await io.rmRF(toolDir);
|
||||||
|
await io.rmRF(tempDir);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('DotnetCoreInstaller tests', () => {
|
afterAll(async () => {
|
||||||
const getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
|
try {
|
||||||
const warningSpy = jest.spyOn(core, 'warning');
|
await io.rmRF(toolDir);
|
||||||
const whichSpy = jest.spyOn(io, 'which');
|
await io.rmRF(tempDir);
|
||||||
const maxSatisfyingSpy = jest.spyOn(semver, 'maxSatisfying');
|
} catch {
|
||||||
|
console.log('Failed to remove test directories');
|
||||||
|
}
|
||||||
|
}, 30000);
|
||||||
|
|
||||||
describe('installDotnet() tests', () => {
|
it('Aquires multiple versions of dotnet', async () => {
|
||||||
whichSpy.mockImplementation(() => Promise.resolve('PathToShell'));
|
const versions = ['2.2.207', '3.1.120'];
|
||||||
|
|
||||||
it('should throw the error in case of non-zero exit code of the installation script. The error message should contain logs.', async () => {
|
for (const version of versions) {
|
||||||
const inputVersion = '3.1.100';
|
await getDotnet(version);
|
||||||
const inputQuality = '' as QualityOptions;
|
}
|
||||||
const errorMessage = 'fictitious error message!';
|
expect(fs.existsSync(path.join(toolDir, 'sdk', '2.2.207'))).toBe(true);
|
||||||
getExecOutputSpy.mockImplementation(() => {
|
expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.120'))).toBe(true);
|
||||||
return Promise.resolve({
|
|
||||||
exitCode: 1,
|
|
||||||
stdout: '',
|
|
||||||
stderr: errorMessage
|
|
||||||
});
|
|
||||||
});
|
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
|
||||||
inputVersion,
|
|
||||||
inputQuality
|
|
||||||
);
|
|
||||||
await expect(dotnetInstaller.installDotnet()).rejects.toThrow(
|
|
||||||
`Failed to install dotnet, exit code: 1. ${errorMessage}`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return version of .NET SDK after installation complete', async () => {
|
if (IS_WINDOWS) {
|
||||||
const inputVersion = '3.1.100';
|
expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true);
|
||||||
const inputQuality = '' as QualityOptions;
|
} else {
|
||||||
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
|
expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
|
||||||
getExecOutputSpy.mockImplementation(() => {
|
}
|
||||||
return Promise.resolve({
|
|
||||||
exitCode: 0,
|
|
||||||
stdout: `${stdout}`,
|
|
||||||
stderr: ''
|
|
||||||
});
|
|
||||||
});
|
|
||||||
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
|
||||||
|
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
expect(process.env.DOTNET_ROOT).toBeDefined;
|
||||||
inputVersion,
|
expect(process.env.PATH).toBeDefined;
|
||||||
inputQuality
|
expect(process.env.DOTNET_ROOT).toBe(toolDir);
|
||||||
);
|
expect(process.env.PATH?.startsWith(toolDir)).toBe(true);
|
||||||
const installedVersion = await dotnetInstaller.installDotnet();
|
}, 600000);
|
||||||
|
|
||||||
expect(installedVersion).toBe(inputVersion);
|
it('Acquires version of dotnet if no matching version is installed', async () => {
|
||||||
});
|
await getDotnet('3.1.201');
|
||||||
|
expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.201'))).toBe(true);
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true);
|
||||||
|
} else {
|
||||||
|
expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
|
||||||
|
}
|
||||||
|
|
||||||
it(`should supply 'version' argument to the installation script if supplied version is in A.B.C syntax`, async () => {
|
expect(process.env.DOTNET_ROOT).toBeDefined;
|
||||||
const inputVersion = '6.0.300';
|
expect(process.env.PATH).toBeDefined;
|
||||||
const inputQuality = '' as QualityOptions;
|
expect(process.env.DOTNET_ROOT).toBe(toolDir);
|
||||||
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
|
expect(process.env.PATH?.startsWith(toolDir)).toBe(true);
|
||||||
|
}, 600000); //This needs some time to download on "slower" internet connections
|
||||||
|
|
||||||
getExecOutputSpy.mockImplementation(() => {
|
it('Acquires generic version of dotnet if no matching version is installed', async () => {
|
||||||
return Promise.resolve({
|
await getDotnet('3.1');
|
||||||
exitCode: 0,
|
var directory = fs
|
||||||
stdout: `${stdout}`,
|
.readdirSync(path.join(toolDir, 'sdk'))
|
||||||
stderr: ''
|
.filter(fn => fn.startsWith('3.1.'));
|
||||||
});
|
expect(directory.length > 0).toBe(true);
|
||||||
});
|
if (IS_WINDOWS) {
|
||||||
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true);
|
||||||
|
} else {
|
||||||
|
expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
|
||||||
|
}
|
||||||
|
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
expect(process.env.DOTNET_ROOT).toBeDefined;
|
||||||
inputVersion,
|
expect(process.env.PATH).toBeDefined;
|
||||||
inputQuality
|
expect(process.env.DOTNET_ROOT).toBe(toolDir);
|
||||||
);
|
expect(process.env.PATH?.startsWith(toolDir)).toBe(true);
|
||||||
|
}, 600000); //This needs some time to download on "slower" internet connections
|
||||||
|
|
||||||
await dotnetInstaller.installDotnet();
|
it('Throws if no location contains correct dotnet version', async () => {
|
||||||
|
let thrown = false;
|
||||||
|
try {
|
||||||
|
await getDotnet('1000.0.0');
|
||||||
|
} catch {
|
||||||
|
thrown = true;
|
||||||
|
}
|
||||||
|
expect(thrown).toBe(true);
|
||||||
|
}, 30000);
|
||||||
|
|
||||||
const scriptArguments = (
|
it('Uses an up to date bash download script', async () => {
|
||||||
getExecOutputSpy.mock.calls[0][1] as string[]
|
const httpCallbackClient = new hc.HttpClient('setup-dotnet-test', [], {
|
||||||
).join(' ');
|
allowRetries: true,
|
||||||
const expectedArgument = IS_WINDOWS
|
maxRetries: 3
|
||||||
? `-Version ${inputVersion}`
|
|
||||||
: `--version ${inputVersion}`;
|
|
||||||
|
|
||||||
expect(scriptArguments).toContain(expectedArgument);
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`should warn if the 'quality' input is set and the supplied version is in A.B.C syntax`, async () => {
|
|
||||||
const inputVersion = '6.0.300';
|
|
||||||
const inputQuality = 'ga' as QualityOptions;
|
|
||||||
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
|
|
||||||
getExecOutputSpy.mockImplementation(() => {
|
|
||||||
return Promise.resolve({
|
|
||||||
exitCode: 0,
|
|
||||||
stdout: `${stdout}`,
|
|
||||||
stderr: ''
|
|
||||||
});
|
|
||||||
});
|
|
||||||
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
|
||||||
|
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
|
||||||
inputVersion,
|
|
||||||
inputQuality
|
|
||||||
);
|
|
||||||
|
|
||||||
await dotnetInstaller.installDotnet();
|
|
||||||
|
|
||||||
expect(warningSpy).toHaveBeenCalledWith(
|
|
||||||
`The 'dotnet-quality' input can be used only with .NET SDK version in A.B, A.B.x, A, A.x and A.B.Cxx formats where the major tag is higher than 5. You specified: ${inputVersion}. 'dotnet-quality' input is ignored.`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`should warn if the 'quality' input is set and version isn't in A.B.C syntax but major tag is lower then 6`, async () => {
|
|
||||||
const inputVersion = '3.1';
|
|
||||||
const inputQuality = 'ga' as QualityOptions;
|
|
||||||
const stdout = `Fictitious dotnet version 3.1.100 is installed`;
|
|
||||||
|
|
||||||
getExecOutputSpy.mockImplementation(() => {
|
|
||||||
return Promise.resolve({
|
|
||||||
exitCode: 0,
|
|
||||||
stdout: `${stdout}`,
|
|
||||||
stderr: ''
|
|
||||||
});
|
|
||||||
});
|
|
||||||
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
|
||||||
|
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
|
||||||
inputVersion,
|
|
||||||
inputQuality
|
|
||||||
);
|
|
||||||
|
|
||||||
await dotnetInstaller.installDotnet();
|
|
||||||
|
|
||||||
expect(warningSpy).toHaveBeenCalledWith(
|
|
||||||
`The 'dotnet-quality' input can be used only with .NET SDK version in A.B, A.B.x, A, A.x and A.B.Cxx formats where the major tag is higher than 5. You specified: ${inputVersion}. 'dotnet-quality' input is ignored.`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
each(['6', '6.0', '6.0.x', '6.0.*', '6.0.X']).test(
|
|
||||||
`should supply 'quality' argument to the installation script if quality input is set and version (%s) is not in A.B.C syntax`,
|
|
||||||
async inputVersion => {
|
|
||||||
const inputQuality = 'ga' as QualityOptions;
|
|
||||||
const exitCode = 0;
|
|
||||||
const stdout = `Fictitious dotnet version 6.0.0 is installed`;
|
|
||||||
getExecOutputSpy.mockImplementation(() => {
|
|
||||||
return Promise.resolve({
|
|
||||||
exitCode: exitCode,
|
|
||||||
stdout: `${stdout}`,
|
|
||||||
stderr: ''
|
|
||||||
});
|
|
||||||
});
|
|
||||||
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
|
||||||
|
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
|
||||||
inputVersion,
|
|
||||||
inputQuality
|
|
||||||
);
|
|
||||||
|
|
||||||
await dotnetInstaller.installDotnet();
|
|
||||||
|
|
||||||
const scriptArguments = (
|
|
||||||
getExecOutputSpy.mock.calls[0][1] as string[]
|
|
||||||
).join(' ');
|
|
||||||
const expectedArgument = IS_WINDOWS
|
|
||||||
? `-Quality ${inputQuality}`
|
|
||||||
: `--quality ${inputQuality}`;
|
|
||||||
|
|
||||||
expect(scriptArguments).toContain(expectedArgument);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
each(['6', '6.0', '6.0.x', '6.0.*', '6.0.X']).test(
|
|
||||||
`should supply 'channel' argument to the installation script if version (%s) isn't in A.B.C syntax`,
|
|
||||||
async inputVersion => {
|
|
||||||
const inputQuality = '' as QualityOptions;
|
|
||||||
const exitCode = 0;
|
|
||||||
const stdout = `Fictitious dotnet version 6.0.0 is installed`;
|
|
||||||
getExecOutputSpy.mockImplementation(() => {
|
|
||||||
return Promise.resolve({
|
|
||||||
exitCode: exitCode,
|
|
||||||
stdout: `${stdout}`,
|
|
||||||
stderr: ''
|
|
||||||
});
|
|
||||||
});
|
|
||||||
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
|
||||||
|
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
|
||||||
inputVersion,
|
|
||||||
inputQuality
|
|
||||||
);
|
|
||||||
|
|
||||||
await dotnetInstaller.installDotnet();
|
|
||||||
|
|
||||||
const scriptArguments = (
|
|
||||||
getExecOutputSpy.mock.calls[0][1] as string[]
|
|
||||||
).join(' ');
|
|
||||||
const expectedArgument = IS_WINDOWS
|
|
||||||
? `-Channel 6.0`
|
|
||||||
: `--channel 6.0`;
|
|
||||||
|
|
||||||
expect(scriptArguments).toContain(expectedArgument);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (IS_WINDOWS) {
|
|
||||||
it(`should supply '-ProxyAddress' argument to the installation script if env.variable 'https_proxy' is set`, async () => {
|
|
||||||
process.env['https_proxy'] = 'https://proxy.com';
|
|
||||||
const inputVersion = '6.0.100';
|
|
||||||
const inputQuality = '' as QualityOptions;
|
|
||||||
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
|
|
||||||
|
|
||||||
getExecOutputSpy.mockImplementation(() => {
|
|
||||||
return Promise.resolve({
|
|
||||||
exitCode: 0,
|
|
||||||
stdout: `${stdout}`,
|
|
||||||
stderr: ''
|
|
||||||
});
|
|
||||||
});
|
|
||||||
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
|
||||||
|
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
|
||||||
inputVersion,
|
|
||||||
inputQuality
|
|
||||||
);
|
|
||||||
|
|
||||||
await dotnetInstaller.installDotnet();
|
|
||||||
|
|
||||||
const scriptArguments = (
|
|
||||||
getExecOutputSpy.mock.calls[0][1] as string[]
|
|
||||||
).join(' ');
|
|
||||||
|
|
||||||
expect(scriptArguments).toContain(
|
|
||||||
`-ProxyAddress ${process.env['https_proxy']}`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`should supply '-ProxyBypassList' argument to the installation script if env.variable 'no_proxy' is set`, async () => {
|
|
||||||
process.env['no_proxy'] = 'first.url,second.url';
|
|
||||||
const inputVersion = '6.0.100';
|
|
||||||
const inputQuality = '' as QualityOptions;
|
|
||||||
const stdout = `Fictitious dotnet version 6.0.0 is installed`;
|
|
||||||
|
|
||||||
getExecOutputSpy.mockImplementation(() => {
|
|
||||||
return Promise.resolve({
|
|
||||||
exitCode: 0,
|
|
||||||
stdout: `${stdout}`,
|
|
||||||
stderr: ''
|
|
||||||
});
|
|
||||||
});
|
|
||||||
maxSatisfyingSpy.mockImplementation(() => inputVersion);
|
|
||||||
|
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
|
||||||
inputVersion,
|
|
||||||
inputQuality
|
|
||||||
);
|
|
||||||
|
|
||||||
await dotnetInstaller.installDotnet();
|
|
||||||
|
|
||||||
const scriptArguments = (
|
|
||||||
getExecOutputSpy.mock.calls[0][1] as string[]
|
|
||||||
).join(' ');
|
|
||||||
|
|
||||||
expect(scriptArguments).toContain(
|
|
||||||
`-ProxyBypassList ${process.env['no_proxy']}`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
const response: hc.HttpClientResponse = await httpCallbackClient.get(
|
||||||
|
'https://dot.net/v1/dotnet-install.sh'
|
||||||
|
);
|
||||||
|
expect(response.message.statusCode).toBe(200);
|
||||||
|
const upToDateContents: string = await response.readBody();
|
||||||
|
const currentContents: string = fs
|
||||||
|
.readFileSync(
|
||||||
|
path.join(__dirname, '..', 'externals', 'install-dotnet.sh')
|
||||||
|
)
|
||||||
|
.toString();
|
||||||
|
expect(normalizeFileContents(currentContents)).toBe(
|
||||||
|
normalizeFileContents(upToDateContents)
|
||||||
|
);
|
||||||
|
}, 30000);
|
||||||
|
|
||||||
describe('addToPath() tests', () => {
|
it('Uses an up to date powershell download script', async () => {
|
||||||
it(`should export DOTNET_ROOT env.var with value from DOTNET_INSTALL_DIR env.var`, async () => {
|
var httpCallbackClient = new hc.HttpClient('setup-dotnet-test', [], {
|
||||||
process.env['DOTNET_INSTALL_DIR'] = 'fictitious/dotnet/install/dir';
|
allowRetries: true,
|
||||||
installer.DotnetCoreInstaller.addToPath();
|
maxRetries: 3
|
||||||
const dotnet_root = process.env['DOTNET_ROOT'];
|
|
||||||
expect(dotnet_root).toBe(process.env['DOTNET_INSTALL_DIR']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`should export value from DOTNET_INSTALL_DIR env.var to the PATH`, async () => {
|
|
||||||
process.env['DOTNET_INSTALL_DIR'] = 'fictitious/dotnet/install/dir';
|
|
||||||
installer.DotnetCoreInstaller.addToPath();
|
|
||||||
const path = process.env['PATH'];
|
|
||||||
expect(path).toContain(process.env['DOTNET_INSTALL_DIR']);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
const response: hc.HttpClientResponse = await httpCallbackClient.get(
|
||||||
|
'https://dot.net/v1/dotnet-install.ps1'
|
||||||
describe('DotnetVersionResolver tests', () => {
|
);
|
||||||
describe('createDotNetVersion() tests', () => {
|
expect(response.message.statusCode).toBe(200);
|
||||||
each([
|
const upToDateContents: string = await response.readBody();
|
||||||
'3.1',
|
const currentContents: string = fs
|
||||||
'3.x',
|
.readFileSync(
|
||||||
'3.1.x',
|
path.join(__dirname, '..', 'externals', 'install-dotnet.ps1')
|
||||||
'3.1.*',
|
)
|
||||||
'3.1.X',
|
.toString();
|
||||||
'3.1.2',
|
expect(normalizeFileContents(currentContents)).toBe(
|
||||||
'3.1.0-preview1',
|
normalizeFileContents(upToDateContents)
|
||||||
'6.0.2xx'
|
);
|
||||||
]).test(
|
}, 30000);
|
||||||
'if valid version is supplied (%s), it should return version object with some value',
|
|
||||||
async version => {
|
|
||||||
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
|
||||||
version
|
|
||||||
);
|
|
||||||
const versionObject =
|
|
||||||
await dotnetVersionResolver.createDotNetVersion();
|
|
||||||
|
|
||||||
expect(!!versionObject.value).toBe(true);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
each([
|
|
||||||
'.',
|
|
||||||
'..',
|
|
||||||
' . ',
|
|
||||||
'. ',
|
|
||||||
' .',
|
|
||||||
' . . ',
|
|
||||||
' .. ',
|
|
||||||
' . ',
|
|
||||||
'-1.-1',
|
|
||||||
'-1',
|
|
||||||
'-1.-1.-1',
|
|
||||||
'..3',
|
|
||||||
'1..3',
|
|
||||||
'1..',
|
|
||||||
'.2.3',
|
|
||||||
'.2.x',
|
|
||||||
'*.',
|
|
||||||
'1.2.',
|
|
||||||
'1.2.-abc',
|
|
||||||
'a.b',
|
|
||||||
'a.b.c',
|
|
||||||
'a.b.c-preview',
|
|
||||||
' 0 . 1 . 2 ',
|
|
||||||
'invalid'
|
|
||||||
]).test(
|
|
||||||
'if invalid version is supplied (%s), it should throw',
|
|
||||||
async version => {
|
|
||||||
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
|
||||||
version
|
|
||||||
);
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
async () => await dotnetVersionResolver.createDotNetVersion()
|
|
||||||
).rejects.toThrow();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
each(['3', '3.1', '3.1.x', '3.1.*', '3.1.X', '6.0.2xx']).test(
|
|
||||||
"if version that can be resolved to 'channel' option is supplied (%s), it should set type to 'channel' in version object",
|
|
||||||
async version => {
|
|
||||||
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
|
||||||
version
|
|
||||||
);
|
|
||||||
const versionObject =
|
|
||||||
await dotnetVersionResolver.createDotNetVersion();
|
|
||||||
|
|
||||||
expect(versionObject.type.toLowerCase().includes('channel')).toBe(
|
|
||||||
true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
each(['6.0', '6.0.x', '6.0.*', '6.0.X', '6.0.2xx']).test(
|
|
||||||
"if version that can be resolved to 'channel' option is supplied and its major tag is >= 6 (%s), it should set type to 'channel' and qualityFlag to 'true' in version object",
|
|
||||||
async version => {
|
|
||||||
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
|
||||||
version
|
|
||||||
);
|
|
||||||
const versionObject =
|
|
||||||
await dotnetVersionResolver.createDotNetVersion();
|
|
||||||
|
|
||||||
expect(versionObject.type.toLowerCase().includes('channel')).toBe(
|
|
||||||
true
|
|
||||||
);
|
|
||||||
expect(versionObject.qualityFlag).toBe(true);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
each(['3.1.2', '3.1.0-preview1']).test(
|
|
||||||
"if version that can be resolved to 'version' option is supplied (%s), it should set quality flag to 'false' and type to 'version' in version object",
|
|
||||||
async version => {
|
|
||||||
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
|
||||||
version
|
|
||||||
);
|
|
||||||
const versionObject =
|
|
||||||
await dotnetVersionResolver.createDotNetVersion();
|
|
||||||
|
|
||||||
expect(versionObject.type.toLowerCase().includes('version')).toBe(
|
|
||||||
true
|
|
||||||
);
|
|
||||||
expect(versionObject.qualityFlag).toBe(false);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
each(['3.1.2', '3.1']).test(
|
|
||||||
'it should create proper line arguments for powershell/bash installation scripts',
|
|
||||||
async version => {
|
|
||||||
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
|
||||||
version
|
|
||||||
);
|
|
||||||
const versionObject =
|
|
||||||
await dotnetVersionResolver.createDotNetVersion();
|
|
||||||
const windowsRegEx = new RegExp(/^-(Version|Channel)/);
|
|
||||||
const nonWindowsRegEx = new RegExp(/^--(version|channel)/);
|
|
||||||
|
|
||||||
if (IS_WINDOWS) {
|
|
||||||
expect(windowsRegEx.test(versionObject.type)).toBe(true);
|
|
||||||
expect(nonWindowsRegEx.test(versionObject.type)).toBe(false);
|
|
||||||
} else {
|
|
||||||
expect(nonWindowsRegEx.test(versionObject.type)).toBe(true);
|
|
||||||
expect(windowsRegEx.test(versionObject.type)).toBe(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
it(`should throw if dotnet-version is supplied in A.B.Cxx syntax with major tag lower that 5`, async () => {
|
|
||||||
const version = '3.0.1xx';
|
|
||||||
const dotnetVersionResolver = new installer.DotnetVersionResolver(
|
|
||||||
version
|
|
||||||
);
|
|
||||||
await expect(
|
|
||||||
async () => await dotnetVersionResolver.createDotNetVersion()
|
|
||||||
).rejects.toThrow(
|
|
||||||
`'dotnet-version' was supplied in invalid format: ${version}! The A.B.Cxx syntax is available since the .NET 5.0 release.`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function normalizeFileContents(contents: string): string {
|
||||||
|
return contents
|
||||||
|
.trim()
|
||||||
|
.replace(new RegExp('\r\n', 'g'), '\n')
|
||||||
|
.replace(new RegExp('\r', 'g'), '\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getDotnet(version: string): Promise<void> {
|
||||||
|
const dotnetInstaller = new installer.DotnetCoreInstaller(version);
|
||||||
|
await dotnetInstaller.installDotnet();
|
||||||
|
installer.DotnetCoreInstaller.addToPath();
|
||||||
|
}
|
||||||
|
|||||||
15
__tests__/sample-csproj/Program.cs
Normal file
15
__tests__/sample-csproj/Program.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace sample_csproj
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void TestMethod1()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Hello, World!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
__tests__/sample-csproj/sample.csproj
Normal file
18
__tests__/sample-csproj/sample.csproj
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFrameworks>netcoreapp3.1;netcoreapp3.0;netcoreapp2.2</TargetFrameworks>
|
||||||
|
<RootNamespace>sample_csproj</RootNamespace>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<!-- These packages will be downloaded over the network for testing proxy settings -->
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||||
|
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
|
||||||
|
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
|
||||||
|
<PackageReference Include="coverlet.collector" Version="1.2.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -1,173 +1,71 @@
|
|||||||
import * as core from '@actions/core';
|
import io = require('@actions/io');
|
||||||
import fs from 'fs';
|
import fs = require('fs');
|
||||||
import semver from 'semver';
|
import os = require('os');
|
||||||
import * as auth from '../src/authutil';
|
import path = require('path');
|
||||||
|
|
||||||
|
const toolDir = path.join(__dirname, 'runner', 'tools2');
|
||||||
|
const tempDir = path.join(__dirname, 'runner', 'temp2');
|
||||||
|
|
||||||
import * as setup from '../src/setup-dotnet';
|
import * as setup from '../src/setup-dotnet';
|
||||||
import {DotnetCoreInstaller} from '../src/installer';
|
import * as dotnetInstaller from '../src/installer';
|
||||||
|
|
||||||
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
|
|
||||||
describe('setup-dotnet tests', () => {
|
describe('setup-dotnet tests', () => {
|
||||||
const inputs = {} as any;
|
beforeAll(async () => {
|
||||||
|
process.env.RUNNER_TOOL_CACHE = toolDir;
|
||||||
const getInputSpy = jest.spyOn(core, 'getInput');
|
process.env.DOTNET_INSTALL_DIR = toolDir;
|
||||||
const getMultilineInputSpy = jest.spyOn(core, 'getMultilineInput');
|
process.env.RUNNER_TEMP = tempDir;
|
||||||
const setFailedSpy = jest.spyOn(core, 'setFailed');
|
process.env['INPUT_INCLUDE-PRERELEASE'] = 'false';
|
||||||
const warningSpy = jest.spyOn(core, 'warning');
|
await io.rmRF(toolDir);
|
||||||
const debugSpy = jest.spyOn(core, 'debug');
|
await io.rmRF(tempDir);
|
||||||
const infoSpy = jest.spyOn(core, 'info');
|
|
||||||
const setOutputSpy = jest.spyOn(core, 'setOutput');
|
|
||||||
|
|
||||||
const existsSyncSpy = jest.spyOn(fs, 'existsSync');
|
|
||||||
|
|
||||||
const maxSatisfyingSpy = jest.spyOn(semver, 'maxSatisfying');
|
|
||||||
|
|
||||||
const installDotnetSpy = jest.spyOn(
|
|
||||||
DotnetCoreInstaller.prototype,
|
|
||||||
'installDotnet'
|
|
||||||
);
|
|
||||||
const addToPathSpy = jest.spyOn(DotnetCoreInstaller, 'addToPath');
|
|
||||||
|
|
||||||
const configAuthenticationSpy = jest.spyOn(auth, 'configAuthentication');
|
|
||||||
|
|
||||||
describe('run() tests', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
getMultilineInputSpy.mockImplementation(input => inputs[input as string]);
|
|
||||||
getInputSpy.mockImplementation(input => inputs[input as string]);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
jest.clearAllMocks();
|
|
||||||
jest.resetAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fail the action if global-json-file input is present, but the file does not exist in the file system', async () => {
|
|
||||||
inputs['global-json-file'] = 'fictitious.json';
|
|
||||||
inputs['dotnet-version'] = [];
|
|
||||||
|
|
||||||
const expectedErrorMessage = `The specified global.json file '${inputs['global-json-file']}' does not exist`;
|
|
||||||
|
|
||||||
await setup.run();
|
|
||||||
expect(setFailedSpy).toHaveBeenCalledWith(expectedErrorMessage);
|
|
||||||
});
|
|
||||||
|
|
||||||
test(`if 'dotnet-version' and 'global-json-file' inputs aren't present, should log into debug output, try to find global.json in the repo root, fail and log message into info output`, async () => {
|
|
||||||
inputs['global-json-file'] = '';
|
|
||||||
inputs['dotnet-version'] = [];
|
|
||||||
|
|
||||||
maxSatisfyingSpy.mockImplementation(() => null);
|
|
||||||
setOutputSpy.mockImplementation(() => {});
|
|
||||||
|
|
||||||
const expectedDebugMessage =
|
|
||||||
'No version found, trying to find version from global.json';
|
|
||||||
const expectedInfoMessage = `The global.json wasn't found in the root directory. No .NET version will be installed.`;
|
|
||||||
|
|
||||||
await setup.run();
|
|
||||||
|
|
||||||
expect(debugSpy).toHaveBeenCalledWith(expectedDebugMessage);
|
|
||||||
expect(existsSyncSpy).toHaveBeenCalled();
|
|
||||||
expect(infoSpy).toHaveBeenCalledWith(expectedInfoMessage);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fail the action if quality is supplied but its value is not supported', async () => {
|
|
||||||
inputs['global-json-file'] = '';
|
|
||||||
inputs['dotnet-version'] = ['6.0'];
|
|
||||||
inputs['dotnet-quality'] = 'fictitiousQuality';
|
|
||||||
|
|
||||||
const expectedErrorMessage = `Value '${inputs['dotnet-quality']}' is not supported for the 'dotnet-quality' option. Supported values are: daily, signed, validated, preview, ga.`;
|
|
||||||
|
|
||||||
await setup.run();
|
|
||||||
expect(setFailedSpy).toHaveBeenCalledWith(expectedErrorMessage);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call installDotnet() multiple times if dotnet-version multiline input is provided', async () => {
|
|
||||||
inputs['global-json-file'] = '';
|
|
||||||
inputs['dotnet-version'] = ['6.0', '7.0'];
|
|
||||||
inputs['dotnet-quality'] = '';
|
|
||||||
|
|
||||||
installDotnetSpy.mockImplementation(() => Promise.resolve(''));
|
|
||||||
|
|
||||||
await setup.run();
|
|
||||||
expect(installDotnetSpy).toHaveBeenCalledTimes(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call addToPath() after installation complete', async () => {
|
|
||||||
inputs['global-json-file'] = '';
|
|
||||||
inputs['dotnet-version'] = ['6.0', '7.0'];
|
|
||||||
inputs['dotnet-quality'] = '';
|
|
||||||
|
|
||||||
installDotnetSpy.mockImplementation(() => Promise.resolve(''));
|
|
||||||
addToPathSpy.mockImplementation(() => {});
|
|
||||||
|
|
||||||
await setup.run();
|
|
||||||
expect(addToPathSpy).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call auth.configAuthentication() if source-url input is provided', async () => {
|
|
||||||
inputs['global-json-file'] = '';
|
|
||||||
inputs['dotnet-version'] = [];
|
|
||||||
inputs['dotnet-quality'] = '';
|
|
||||||
inputs['source-url'] = 'fictitious.source.url';
|
|
||||||
|
|
||||||
configAuthenticationSpy.mockImplementation(() => {});
|
|
||||||
|
|
||||||
await setup.run();
|
|
||||||
expect(configAuthenticationSpy).toHaveBeenCalledWith(
|
|
||||||
inputs['source-url'],
|
|
||||||
undefined
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call auth.configAuthentication() with proper parameters if source-url and config-file inputs are provided', async () => {
|
|
||||||
inputs['global-json-file'] = '';
|
|
||||||
inputs['dotnet-version'] = [];
|
|
||||||
inputs['dotnet-quality'] = '';
|
|
||||||
inputs['source-url'] = 'fictitious.source.url';
|
|
||||||
inputs['config-file'] = 'fictitious.path';
|
|
||||||
|
|
||||||
configAuthenticationSpy.mockImplementation(() => {});
|
|
||||||
setOutputSpy.mockImplementation(() => {});
|
|
||||||
|
|
||||||
await setup.run();
|
|
||||||
expect(configAuthenticationSpy).toHaveBeenCalledWith(
|
|
||||||
inputs['source-url'],
|
|
||||||
inputs['config-file']
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call setOutput() after installation complete successfully', async () => {
|
|
||||||
inputs['dotnet-version'] = ['6.0.300'];
|
|
||||||
|
|
||||||
installDotnetSpy.mockImplementation(() =>
|
|
||||||
Promise.resolve(`${inputs['dotnet-version']}`)
|
|
||||||
);
|
|
||||||
addToPathSpy.mockImplementation(() => {});
|
|
||||||
|
|
||||||
await setup.run();
|
|
||||||
expect(setOutputSpy).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`shouldn't call setOutput() if parsing dotnet-installer logs failed`, async () => {
|
|
||||||
inputs['dotnet-version'] = ['6.0.300'];
|
|
||||||
const warningMessage = `Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.`;
|
|
||||||
|
|
||||||
installDotnetSpy.mockImplementation(() => Promise.resolve(null));
|
|
||||||
addToPathSpy.mockImplementation(() => {});
|
|
||||||
|
|
||||||
await setup.run();
|
|
||||||
expect(warningSpy).toHaveBeenCalledWith(warningMessage);
|
|
||||||
expect(setOutputSpy).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`shouldn't call setOutput() if actions didn't install .NET`, async () => {
|
|
||||||
inputs['dotnet-version'] = [];
|
|
||||||
const warningMessage = `The 'dotnet-version' output will not be set.`;
|
|
||||||
|
|
||||||
addToPathSpy.mockImplementation(() => {});
|
|
||||||
|
|
||||||
await setup.run();
|
|
||||||
|
|
||||||
expect(infoSpy).toHaveBeenCalledWith(warningMessage);
|
|
||||||
expect(setOutputSpy).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
try {
|
||||||
|
await io.rmRF(path.join(process.cwd(), 'global.json'));
|
||||||
|
await io.rmRF(toolDir);
|
||||||
|
await io.rmRF(tempDir);
|
||||||
|
} catch {
|
||||||
|
console.log('Failed to remove test directories');
|
||||||
|
}
|
||||||
|
}, 30000);
|
||||||
|
|
||||||
|
it('Acquires version of dotnet from global.json if no matching version is installed', async () => {
|
||||||
|
const globalJsonPath = path.join(process.cwd(), 'global.json');
|
||||||
|
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "3.1.201"${os.EOL}}${os.EOL}}`;
|
||||||
|
if (!fs.existsSync(globalJsonPath)) {
|
||||||
|
fs.writeFileSync(globalJsonPath, jsonContents);
|
||||||
|
}
|
||||||
|
await setup.run();
|
||||||
|
|
||||||
|
expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.201'))).toBe(true);
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true);
|
||||||
|
} else {
|
||||||
|
expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
|
||||||
|
}
|
||||||
|
}, 400000);
|
||||||
|
|
||||||
|
it('Acquires version of dotnet from global.json with rollForward option, install the latest patch', async () => {
|
||||||
|
const globalJsonPath = path.join(process.cwd(), 'global.json');
|
||||||
|
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version":"3.1.201",${os.EOL}"rollForward":"latestFeature"${os.EOL}}${os.EOL}}`;
|
||||||
|
if (!fs.existsSync(globalJsonPath)) {
|
||||||
|
fs.writeFileSync(globalJsonPath, jsonContents);
|
||||||
|
}
|
||||||
|
|
||||||
|
const version = '3.1';
|
||||||
|
const installer = new dotnetInstaller.DotnetCoreInstaller(version);
|
||||||
|
const patchVersion = await installer.resolveVersion(
|
||||||
|
new dotnetInstaller.DotNetVersionInfo(version)
|
||||||
|
);
|
||||||
|
await setup.run();
|
||||||
|
|
||||||
|
expect(fs.existsSync(path.join(toolDir, 'sdk', patchVersion))).toBe(true);
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true);
|
||||||
|
} else {
|
||||||
|
expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
|
||||||
|
}
|
||||||
|
}, 400000);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,117 +1,73 @@
|
|||||||
<#
|
if (!$args[0])
|
||||||
.DESCRIPTION
|
{
|
||||||
Verifies that installed on the machine .NET SDK versions match the input patterns.
|
throw "Must supply dotnet version argument"
|
||||||
Optionally checks that the nuget.config file is generated correctly.
|
|
||||||
|
|
||||||
.PARAMETER Patterns
|
|
||||||
Specifies the regular expression patterns that should be matched with the installed
|
|
||||||
on the machine .NET SDK versions. The number of patterns should be equal to the number
|
|
||||||
of installed .NET versions.
|
|
||||||
|
|
||||||
.PARAMETER CheckNugetConfig
|
|
||||||
Switches the check for the existence of the nuget.config file.
|
|
||||||
|
|
||||||
.EXAMPLE
|
|
||||||
PS> .\verify-dotnet.ps1 -Paterns "^3.1.200$", "^6.0" -CheckNugetConfig
|
|
||||||
#>
|
|
||||||
|
|
||||||
param(
|
|
||||||
[ValidateNotNullOrEmpty()]
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[string[]]$Patterns,
|
|
||||||
[switch]$CheckNugetConfig
|
|
||||||
)
|
|
||||||
|
|
||||||
$PatternsList = [System.Collections.ArrayList]($Patterns)
|
|
||||||
|
|
||||||
if ($CheckNugetConfig.IsPresent -and !(Test-Path "../nuget.config")) {
|
|
||||||
throw "The nuget.config file is not generated correctly."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "These patterns were supplied to the script: $($PatternsList -join ', ')."
|
|
||||||
$dotnet = Get-Command dotnet | Select-Object -First 1 | ForEach-Object { $_.Path }
|
$dotnet = Get-Command dotnet | Select-Object -First 1 | ForEach-Object { $_.Path }
|
||||||
Write-Host "Found: '$dotnet'"
|
Write-Host "Found '$dotnet'"
|
||||||
|
|
||||||
# SDKs are listed on multiple lines with the path afterwards in square brackets
|
if($args.count -eq 1)
|
||||||
$Versions = & $dotnet --list-sdks | ForEach-Object { $_.SubString(0, $_.IndexOf('[')).Trim() }
|
|
||||||
Write-Host "Found installed versions: $($Versions -join ', ')."
|
|
||||||
$InstalledVersionCount = $Versions.Count
|
|
||||||
|
|
||||||
foreach($version in $Versions)
|
|
||||||
{
|
{
|
||||||
foreach($pattern in $PatternsList)
|
$version = & $dotnet --version | Out-String | ForEach-Object { $_.Trim() }
|
||||||
|
Write-Host "Version $version"
|
||||||
|
if (-not ($version.StartsWith($args[0].ToString())))
|
||||||
{
|
{
|
||||||
if ($version -match $pattern)
|
Write-Host "PATH='$env:PATH'"
|
||||||
{
|
throw "Unexpected version"
|
||||||
$PatternsList.Remove($pattern)
|
}
|
||||||
$InstalledVersionCount--
|
}
|
||||||
break
|
|
||||||
|
if ($args[1])
|
||||||
|
{
|
||||||
|
# SDKs are listed on multiple lines with the path afterwards in square brackets
|
||||||
|
$versions = & $dotnet --list-sdks | ForEach-Object { $_.SubString(0, $_.IndexOf('[')).Trim() }
|
||||||
|
Write-Host "Installed versions: $versions"
|
||||||
|
$InstalledVersionCount = 0
|
||||||
|
foreach($arg in $args){
|
||||||
|
foreach ($version in $versions)
|
||||||
|
{
|
||||||
|
if ($version.StartsWith($arg.ToString()))
|
||||||
|
{
|
||||||
|
$InstalledVersionCount++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if ( $InstalledVersionCount -ne $args.Count)
|
||||||
|
{
|
||||||
|
Write-Host "PATH='$env:PATH'"
|
||||||
|
throw "Unexpected version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $InstalledVersionCount -ne 0)
|
Write-Host "Building sample csproj"
|
||||||
|
& $dotnet build __tests__/sample-csproj/ --no-cache
|
||||||
|
if ($LASTEXITCODE -ne 0)
|
||||||
{
|
{
|
||||||
throw "An unexpected version of Dotnet is found on the machine, please check the correctness of the -Patterns input."
|
throw "Unexpected exit code $LASTEXITCODE"
|
||||||
}
|
}
|
||||||
|
|
||||||
$workingDir = Get-Location
|
Write-Host "Testing compiled app"
|
||||||
$testProjectDir = "./__tests__/e2e-test-csproj"
|
$sample_output = "$(dotnet test __tests__/sample-csproj/ --no-build)"
|
||||||
Write-Host "Changing directory to the $testProjectDir"
|
Write-Host "Sample output: $sample_output"
|
||||||
Set-Location $testProjectDir
|
# For Side-by-Side installs we want to run the tests twice, for a single install the tests will run once
|
||||||
|
if ($args[1])
|
||||||
$targetFrameworkVersionMap = @{
|
|
||||||
"1.0" = "netcoreapp1.0";
|
|
||||||
"1.1" = "netcoreapp1.1";
|
|
||||||
"2.0" = "netcoreapp2.0";
|
|
||||||
"2.1" = "netcoreapp2.1";
|
|
||||||
"2.2" = "netcoreapp2.2";
|
|
||||||
"3.0" = "netcoreapp3.0";
|
|
||||||
"3.1" = "netcoreapp3.1";
|
|
||||||
"5.0" = "net5.0";
|
|
||||||
"6.0" = "net6.0";
|
|
||||||
"7.0" = "net7.0";
|
|
||||||
"8.0" = "net8.0";
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($version in $Versions)
|
|
||||||
{
|
{
|
||||||
# Creating temporary global.json file inside e2e-test-csproj dir and setting exact version of .NET inside allows to override default behavior of .NET and run build and tests on that exact version.
|
if ($sample_output -notlike "*Test Run Successful.*Test Run Successful.*")
|
||||||
Write-Host "Creating temporary global.json file for $version .NET version."
|
|
||||||
& $dotnet new globaljson --sdk-version $version --force | Out-Null
|
|
||||||
if (!(Test-Path "./global.json"))
|
|
||||||
{
|
{
|
||||||
throw "An error occured while creating the global.json file. Exit code: $LASTEXITCODE"
|
throw "Unexpected output"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($args[2])
|
||||||
|
{
|
||||||
|
if ($sample_output -notlike "*Test Run Successful.*Test Run Successful.*Test Run Successful.*")
|
||||||
|
{
|
||||||
|
throw "Unexpected output"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ($sample_output -notlike "*Test Run Successful.*")
|
||||||
|
{
|
||||||
|
throw "Unexpected output"
|
||||||
}
|
}
|
||||||
Write-Host "The global.json file for the version $version is created. Currently used .NET version is: $(& $dotnet --version)."
|
|
||||||
|
|
||||||
# Environment variable TEST_TARGET_FRAMEWORK is used inside the test.csproj file to target required framework version
|
|
||||||
$version -match "^(?<key>\d+\.\d+)" | Out-Null
|
|
||||||
if (!($targetFrameworkVersionMap.ContainsKey($Matches.key)))
|
|
||||||
{
|
|
||||||
throw "The map with the framework targets doesn't contain a target name for the version $version."
|
|
||||||
}
|
|
||||||
Write-Host "Setting the TEST_TARGET_FRAMEWORK environment variable to $($targetFrameworkVersionMap[$Matches.key])"
|
|
||||||
[Environment]::SetEnvironmentVariable('TEST_TARGET_FRAMEWORK', $($targetFrameworkVersionMap[$Matches.key]))
|
|
||||||
|
|
||||||
Write-Host "Building test C# project with $version .NET version."
|
|
||||||
& $dotnet build --no-cache
|
|
||||||
if ($LASTEXITCODE -ne 0)
|
|
||||||
{
|
|
||||||
throw "Building process is not successful, exit code: $LASTEXITCODE"
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host "Testing compiled C# project with $version .NET version."
|
|
||||||
& $dotnet test --no-build
|
|
||||||
if ($LASTEXITCODE -ne 0)
|
|
||||||
{
|
|
||||||
throw "Testing process is not successful, exit code: $LASTEXITCODE"
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host "Tests are completed successfully!"
|
|
||||||
|
|
||||||
Write-Host "Removing temporary global.json file."
|
|
||||||
Remove-Item ./global.json
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Set-Location $workingDir
|
|
||||||
44
__tests__/verify-dotnet.sh
Executable file
44
__tests__/verify-dotnet.sh
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "Must supply dotnet version argument"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "../nuget.config" ]; then
|
||||||
|
echo "nuget file not generated correctly"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
dotnet_version="$(dotnet --version)"
|
||||||
|
echo "Found dotnet version '$dotnet_version'"
|
||||||
|
if [ -z "$(echo $dotnet_version | grep $1)" ]; then
|
||||||
|
echo "Unexpected version"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$2" ]; then
|
||||||
|
dotnet_version="$(dotnet --list-sdks)"
|
||||||
|
echo "Found dotnet version '$dotnet_version'"
|
||||||
|
if [ -z "$(echo $dotnet_version | grep $2)" ]; then
|
||||||
|
echo "Unexpected version"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Building sample csproj"
|
||||||
|
dotnet build __tests__/sample-csproj/ --no-cache || exit 1
|
||||||
|
|
||||||
|
echo "Testing compiled app"
|
||||||
|
sample_output=$(dotnet test __tests__/sample-csproj/ --no-build)
|
||||||
|
echo "Sample output: $sample_output"
|
||||||
|
# For Side-by-Side installs we want to run the tests twice, for a single install the tests will run once
|
||||||
|
if [ -n "$2" ]; then
|
||||||
|
if [ -z "$(echo $sample_output | grep "Test Run Successful.*Test Run Successful.")" ]; then
|
||||||
|
echo "Unexpected output"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [ -z "$(echo $sample_output | grep "Test Run Successful.")" ]; then
|
||||||
|
echo "Unexpected output"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
17
__tests__/verify-no-unstaged-changes.sh
Executable file
17
__tests__/verify-no-unstaged-changes.sh
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ "$(git status --porcelain)" != "" ]]; then
|
||||||
|
echo ----------------------------------------
|
||||||
|
echo git status
|
||||||
|
echo ----------------------------------------
|
||||||
|
git status
|
||||||
|
echo ----------------------------------------
|
||||||
|
echo git diff
|
||||||
|
echo ----------------------------------------
|
||||||
|
git diff
|
||||||
|
echo ----------------------------------------
|
||||||
|
echo Troubleshooting
|
||||||
|
echo ----------------------------------------
|
||||||
|
echo "::error::Unstaged changes detected. Locally try running: git clean -ffdx && npm ci && npm run pre-checkin"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
91
__tests__/versionutil.test.ts
Normal file
91
__tests__/versionutil.test.ts
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
import each from 'jest-each';
|
||||||
|
import * as installer from '../src/installer';
|
||||||
|
|
||||||
|
describe('version tests', () => {
|
||||||
|
each(['3.1.999', '3.1.101-preview.3']).test(
|
||||||
|
"Exact version '%s' should be the same",
|
||||||
|
vers => {
|
||||||
|
let versInfo = new installer.DotNetVersionInfo(vers);
|
||||||
|
|
||||||
|
expect(versInfo.isExactVersion()).toBe(true);
|
||||||
|
expect(versInfo.version()).toBe(vers);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
each([
|
||||||
|
['3.x', '3.x'],
|
||||||
|
['3.*', '3.*'],
|
||||||
|
['3.1.x', '3.1'],
|
||||||
|
['1.1.*', '1.1'],
|
||||||
|
['2.0', '2.0']
|
||||||
|
]).test("Generic version '%s' should be '%s'", (vers, resVers) => {
|
||||||
|
let versInfo = new installer.DotNetVersionInfo(vers);
|
||||||
|
|
||||||
|
expect(versInfo.isExactVersion()).toBe(false);
|
||||||
|
expect(versInfo.version()).toBe(resVers);
|
||||||
|
});
|
||||||
|
|
||||||
|
each([
|
||||||
|
'',
|
||||||
|
'.',
|
||||||
|
'..',
|
||||||
|
' . ',
|
||||||
|
'. ',
|
||||||
|
' .',
|
||||||
|
' . . ',
|
||||||
|
' .. ',
|
||||||
|
' . ',
|
||||||
|
'-1.-1',
|
||||||
|
'-1',
|
||||||
|
'-1.-1.-1',
|
||||||
|
'..3',
|
||||||
|
'1..3',
|
||||||
|
'1..',
|
||||||
|
'.2.3',
|
||||||
|
'.2.x',
|
||||||
|
'1',
|
||||||
|
'*.*.1',
|
||||||
|
'*.1',
|
||||||
|
'*.',
|
||||||
|
'1.2.',
|
||||||
|
'1.2.-abc',
|
||||||
|
'a.b',
|
||||||
|
'a.b.c',
|
||||||
|
'a.b.c-preview',
|
||||||
|
' 0 . 1 . 2 '
|
||||||
|
]).test("Malformed version '%s' should throw", vers => {
|
||||||
|
expect(() => new installer.DotNetVersionInfo(vers)).toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
each([
|
||||||
|
['3.1.x', '3.1.'],
|
||||||
|
['3.1.*', '3.1.'],
|
||||||
|
['3.1', '3.1.'],
|
||||||
|
['5.0.0-preview.6', '5.0.0-preview.6'],
|
||||||
|
['3.1.201', '3.1.201']
|
||||||
|
]).test(
|
||||||
|
"Resolving version '%s' as '%s'",
|
||||||
|
async (input, expectedVersion) => {
|
||||||
|
const dotnetInstaller = new installer.DotnetCoreInstaller(input);
|
||||||
|
let versInfo = await dotnetInstaller.resolveVersion(
|
||||||
|
new installer.DotNetVersionInfo(input)
|
||||||
|
);
|
||||||
|
console.log(versInfo);
|
||||||
|
|
||||||
|
expect(versInfo.startsWith(expectedVersion));
|
||||||
|
},
|
||||||
|
100000
|
||||||
|
);
|
||||||
|
|
||||||
|
it('Resolving a nonexistent generic version fails', async () => {
|
||||||
|
const dotnetInstaller = new installer.DotnetCoreInstaller('999.1.x');
|
||||||
|
try {
|
||||||
|
await dotnetInstaller.resolveVersion(
|
||||||
|
new installer.DotNetVersionInfo('999.1.x')
|
||||||
|
);
|
||||||
|
fail();
|
||||||
|
} catch {
|
||||||
|
expect(true);
|
||||||
|
}
|
||||||
|
}, 100000);
|
||||||
|
});
|
||||||
11
action.yml
11
action.yml
@@ -6,9 +6,7 @@ branding:
|
|||||||
color: green
|
color: green
|
||||||
inputs:
|
inputs:
|
||||||
dotnet-version:
|
dotnet-version:
|
||||||
description: 'Optional SDK version(s) to use. If not provided, will install global.json version when available. Examples: 2.2.104, 3.1, 3.1.x, 3.x, 6.0.2xx'
|
description: 'Optional SDK version(s) to use. If not provided, will install global.json version when available. Examples: 2.2.104, 3.1, 3.1.x'
|
||||||
dotnet-quality:
|
|
||||||
description: 'Optional quality of the build. The possible values are: daily, signed, validated, preview, ga.'
|
|
||||||
global-json-file:
|
global-json-file:
|
||||||
description: 'Optional global.json location, if your global.json isn''t located in the root of the repo.'
|
description: 'Optional global.json location, if your global.json isn''t located in the root of the repo.'
|
||||||
source-url:
|
source-url:
|
||||||
@@ -17,9 +15,10 @@ inputs:
|
|||||||
description: 'Optional OWNER for using packages from GitHub Package Registry organizations/users other than the current repository''s owner. Only used if a GPR URL is also provided in source-url'
|
description: 'Optional OWNER for using packages from GitHub Package Registry organizations/users other than the current repository''s owner. Only used if a GPR URL is also provided in source-url'
|
||||||
config-file:
|
config-file:
|
||||||
description: 'Optional NuGet.config location, if your NuGet.config isn''t located in the root of the repo.'
|
description: 'Optional NuGet.config location, if your NuGet.config isn''t located in the root of the repo.'
|
||||||
outputs:
|
include-prerelease:
|
||||||
dotnet-version:
|
description: 'Whether prerelease versions should be matched with non-exact versions (for example 5.0.0-preview.6 being matched by 5, 5.0, 5.x or 5.0.x). Defaults to false if not provided.'
|
||||||
description: 'Contains the installed by action .NET SDK version for reuse.'
|
required: False
|
||||||
|
default: 'false'
|
||||||
runs:
|
runs:
|
||||||
using: 'node16'
|
using: 'node16'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
|
|||||||
11648
dist/index.js
vendored
11648
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
@@ -61,13 +61,12 @@ Pull requests are the easiest way to contribute changes to git repos at GitHub.
|
|||||||
|
|
||||||
- To implement new features or fix bugs, you need to make changes to the `.ts` files, which are located in the `src` folder
|
- To implement new features or fix bugs, you need to make changes to the `.ts` files, which are located in the `src` folder
|
||||||
- To comply with the code style, **you need to run the `format` script**
|
- To comply with the code style, **you need to run the `format` script**
|
||||||
- To lint the code, **you need to run the `lint:fix` script**
|
|
||||||
- To transpile source code to `javascript` we use [NCC](https://github.com/vercel/ncc). **It is very important to run the `build` script after making changes**, otherwise your changes will not get into the final `javascript` build
|
- To transpile source code to `javascript` we use [NCC](https://github.com/vercel/ncc). **It is very important to run the `build` script after making changes**, otherwise your changes will not get into the final `javascript` build
|
||||||
|
|
||||||
**Learn more about how to implement tests:**
|
**Learn more about how to implement tests:**
|
||||||
|
|
||||||
Adding or changing tests is an integral part of making a change to the code.
|
Adding or changing tests is an integral part of making a change to the code.
|
||||||
Unit tests are in the `__tests__` folder, and end-to-end tests are in the `workflows` folder, particularly in the [e2e-tests.yml](https://github.com/actions/setup-dotnet/blob/main/.github/workflows/e2e-tests.yml).
|
Unit tests are in the `__tests__` folder, and end-to-end tests are in the `workflows` folder, particularly in the [workflow.yml](https://github.com/actions/setup-dotnet/blob/main/.github/workflows/workflow.yml).
|
||||||
|
|
||||||
- The contributor can add various types of tests (like unit tests or end-to-end tests), which, in his opinion, will be necessary and sufficient for testing new or changed functionality
|
- The contributor can add various types of tests (like unit tests or end-to-end tests), which, in his opinion, will be necessary and sufficient for testing new or changed functionality
|
||||||
- Tests should cover a successful execution, as well as some edge cases and possible errors
|
- Tests should cover a successful execution, as well as some edge cases and possible errors
|
||||||
|
|||||||
3119
externals/install-dotnet.ps1
vendored
3119
externals/install-dotnet.ps1
vendored
File diff suppressed because it is too large
Load Diff
298
externals/install-dotnet.sh
vendored
298
externals/install-dotnet.sh
vendored
@@ -298,11 +298,20 @@ get_machine_architecture() {
|
|||||||
if command -v uname > /dev/null; then
|
if command -v uname > /dev/null; then
|
||||||
CPUName=$(uname -m)
|
CPUName=$(uname -m)
|
||||||
case $CPUName in
|
case $CPUName in
|
||||||
|
armv1*|armv2*|armv3*|armv4*|armv5*|armv6*)
|
||||||
|
echo "armv6-or-below"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
armv*l)
|
armv*l)
|
||||||
echo "arm"
|
echo "arm"
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
aarch64|arm64)
|
aarch64|arm64)
|
||||||
|
if [ "$(getconf LONG_BIT)" -lt 64 ]; then
|
||||||
|
# This is 32-bit OS running on 64-bit CPU (for example Raspberry Pi OS)
|
||||||
|
echo "arm"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
echo "arm64"
|
echo "arm64"
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
@@ -310,6 +319,22 @@ get_machine_architecture() {
|
|||||||
echo "s390x"
|
echo "s390x"
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
|
ppc64le)
|
||||||
|
echo "ppc64le"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
loongarch64)
|
||||||
|
echo "loongarch64"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
riscv64)
|
||||||
|
echo "riscv64"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
powerpc|ppc)
|
||||||
|
echo "ppc"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -326,7 +351,13 @@ get_normalized_architecture_from_architecture() {
|
|||||||
local architecture="$(to_lowercase "$1")"
|
local architecture="$(to_lowercase "$1")"
|
||||||
|
|
||||||
if [[ $architecture == \<auto\> ]]; then
|
if [[ $architecture == \<auto\> ]]; then
|
||||||
echo "$(get_machine_architecture)"
|
machine_architecture="$(get_machine_architecture)"
|
||||||
|
if [[ "$machine_architecture" == "armv6-or-below" ]]; then
|
||||||
|
say_err "Architecture \`$machine_architecture\` not supported. If you think this is a bug, report it at https://github.com/dotnet/install-scripts/issues"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo $machine_architecture
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -347,6 +378,14 @@ get_normalized_architecture_from_architecture() {
|
|||||||
echo "s390x"
|
echo "s390x"
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
|
ppc64le)
|
||||||
|
echo "ppc64le"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
loongarch64)
|
||||||
|
echo "loongarch64"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
say_err "Architecture \`$architecture\` not supported. If you think this is a bug, report it at https://github.com/dotnet/install-scripts/issues"
|
say_err "Architecture \`$architecture\` not supported. If you think this is a bug, report it at https://github.com/dotnet/install-scripts/issues"
|
||||||
@@ -384,11 +423,17 @@ get_normalized_architecture_for_specific_sdk_version() {
|
|||||||
# args:
|
# args:
|
||||||
# version or channel - $1
|
# version or channel - $1
|
||||||
is_arm64_supported() {
|
is_arm64_supported() {
|
||||||
#any channel or version that starts with the specified versions
|
# Extract the major version by splitting on the dot
|
||||||
case "$1" in
|
major_version="${1%%.*}"
|
||||||
( "1"* | "2"* | "3"* | "4"* | "5"*)
|
|
||||||
echo false
|
# Check if the major version is a valid number and less than 6
|
||||||
return 0
|
case "$major_version" in
|
||||||
|
[0-9]*)
|
||||||
|
if [ "$major_version" -lt 6 ]; then
|
||||||
|
echo false
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
echo true
|
echo true
|
||||||
@@ -407,8 +452,13 @@ get_normalized_os() {
|
|||||||
echo "$osname"
|
echo "$osname"
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
|
macos)
|
||||||
|
osname='osx'
|
||||||
|
echo "$osname"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
say_err "'$user_defined_os' is not a supported value for --os option, supported values are: osx, linux, linux-musl, freebsd, rhel.6. If you think this is a bug, report it at https://github.com/dotnet/install-scripts/issues."
|
say_err "'$user_defined_os' is not a supported value for --os option, supported values are: osx, macos, linux, linux-musl, freebsd, rhel.6. If you think this is a bug, report it at https://github.com/dotnet/install-scripts/issues."
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -538,6 +588,40 @@ is_dotnet_package_installed() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# args:
|
||||||
|
# downloaded file - $1
|
||||||
|
# remote_file_size - $2
|
||||||
|
validate_remote_local_file_sizes()
|
||||||
|
{
|
||||||
|
eval $invocation
|
||||||
|
|
||||||
|
local downloaded_file="$1"
|
||||||
|
local remote_file_size="$2"
|
||||||
|
local file_size=''
|
||||||
|
|
||||||
|
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||||
|
file_size="$(stat -c '%s' "$downloaded_file")"
|
||||||
|
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
|
# hardcode in order to avoid conflicts with GNU stat
|
||||||
|
file_size="$(/usr/bin/stat -f '%z' "$downloaded_file")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$file_size" ]; then
|
||||||
|
say "Downloaded file size is $file_size bytes."
|
||||||
|
|
||||||
|
if [ -n "$remote_file_size" ] && [ -n "$file_size" ]; then
|
||||||
|
if [ "$remote_file_size" -ne "$file_size" ]; then
|
||||||
|
say "The remote and local file sizes are not equal. The remote file size is $remote_file_size bytes and the local size is $file_size bytes. The local package may be corrupted."
|
||||||
|
else
|
||||||
|
say "The remote and local file sizes are equal."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
say "Either downloaded or local package size can not be measured. One of them may be corrupted."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# args:
|
# args:
|
||||||
# azure_feed - $1
|
# azure_feed - $1
|
||||||
# channel - $2
|
# channel - $2
|
||||||
@@ -872,6 +956,37 @@ get_absolute_path() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# args:
|
||||||
|
# override - $1 (boolean, true or false)
|
||||||
|
get_cp_options() {
|
||||||
|
eval $invocation
|
||||||
|
|
||||||
|
local override="$1"
|
||||||
|
local override_switch=""
|
||||||
|
|
||||||
|
if [ "$override" = false ]; then
|
||||||
|
override_switch="-n"
|
||||||
|
|
||||||
|
# create temporary files to check if 'cp -u' is supported
|
||||||
|
tmp_dir="$(mktemp -d)"
|
||||||
|
tmp_file="$tmp_dir/testfile"
|
||||||
|
tmp_file2="$tmp_dir/testfile2"
|
||||||
|
|
||||||
|
touch "$tmp_file"
|
||||||
|
|
||||||
|
# use -u instead of -n if it's available
|
||||||
|
if cp -u "$tmp_file" "$tmp_file2" 2>/dev/null; then
|
||||||
|
override_switch="-u"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# clean up
|
||||||
|
rm -f "$tmp_file" "$tmp_file2"
|
||||||
|
rm -rf "$tmp_dir"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$override_switch"
|
||||||
|
}
|
||||||
|
|
||||||
# args:
|
# args:
|
||||||
# input_files - stdin
|
# input_files - stdin
|
||||||
# root_path - $1
|
# root_path - $1
|
||||||
@@ -883,15 +998,7 @@ copy_files_or_dirs_from_list() {
|
|||||||
local root_path="$(remove_trailing_slash "$1")"
|
local root_path="$(remove_trailing_slash "$1")"
|
||||||
local out_path="$(remove_trailing_slash "$2")"
|
local out_path="$(remove_trailing_slash "$2")"
|
||||||
local override="$3"
|
local override="$3"
|
||||||
local osname="$(get_current_os_name)"
|
local override_switch="$(get_cp_options "$override")"
|
||||||
local override_switch=$(
|
|
||||||
if [ "$override" = false ]; then
|
|
||||||
if [ "$osname" = "linux-musl" ]; then
|
|
||||||
printf -- "-u";
|
|
||||||
else
|
|
||||||
printf -- "-n";
|
|
||||||
fi
|
|
||||||
fi)
|
|
||||||
|
|
||||||
cat | uniq | while read -r file_path; do
|
cat | uniq | while read -r file_path; do
|
||||||
local path="$(remove_beginning_slash "${file_path#$root_path}")"
|
local path="$(remove_beginning_slash "${file_path#$root_path}")"
|
||||||
@@ -906,14 +1013,39 @@ copy_files_or_dirs_from_list() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# args:
|
||||||
|
# zip_uri - $1
|
||||||
|
get_remote_file_size() {
|
||||||
|
local zip_uri="$1"
|
||||||
|
|
||||||
|
if machine_has "curl"; then
|
||||||
|
file_size=$(curl -sI "$zip_uri" | grep -i content-length | awk '{ num = $2 + 0; print num }')
|
||||||
|
elif machine_has "wget"; then
|
||||||
|
file_size=$(wget --spider --server-response -O /dev/null "$zip_uri" 2>&1 | grep -i 'Content-Length:' | awk '{ num = $2 + 0; print num }')
|
||||||
|
else
|
||||||
|
say "Neither curl nor wget is available on this system."
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$file_size" ]; then
|
||||||
|
say "Remote file $zip_uri size is $file_size bytes."
|
||||||
|
echo "$file_size"
|
||||||
|
else
|
||||||
|
say_verbose "Content-Length header was not extracted for $zip_uri."
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# args:
|
# args:
|
||||||
# zip_path - $1
|
# zip_path - $1
|
||||||
# out_path - $2
|
# out_path - $2
|
||||||
|
# remote_file_size - $3
|
||||||
extract_dotnet_package() {
|
extract_dotnet_package() {
|
||||||
eval $invocation
|
eval $invocation
|
||||||
|
|
||||||
local zip_path="$1"
|
local zip_path="$1"
|
||||||
local out_path="$2"
|
local out_path="$2"
|
||||||
|
local remote_file_size="$3"
|
||||||
|
|
||||||
local temp_out_path="$(mktemp -d "$temporary_file_template")"
|
local temp_out_path="$(mktemp -d "$temporary_file_template")"
|
||||||
|
|
||||||
@@ -923,9 +1055,13 @@ extract_dotnet_package() {
|
|||||||
local folders_with_version_regex='^.*/[0-9]+\.[0-9]+[^/]+/'
|
local folders_with_version_regex='^.*/[0-9]+\.[0-9]+[^/]+/'
|
||||||
find "$temp_out_path" -type f | grep -Eo "$folders_with_version_regex" | sort | copy_files_or_dirs_from_list "$temp_out_path" "$out_path" false
|
find "$temp_out_path" -type f | grep -Eo "$folders_with_version_regex" | sort | copy_files_or_dirs_from_list "$temp_out_path" "$out_path" false
|
||||||
find "$temp_out_path" -type f | grep -Ev "$folders_with_version_regex" | copy_files_or_dirs_from_list "$temp_out_path" "$out_path" "$override_non_versioned_files"
|
find "$temp_out_path" -type f | grep -Ev "$folders_with_version_regex" | copy_files_or_dirs_from_list "$temp_out_path" "$out_path" "$override_non_versioned_files"
|
||||||
|
|
||||||
|
validate_remote_local_file_sizes "$zip_path" "$remote_file_size"
|
||||||
|
|
||||||
rm -rf "$temp_out_path"
|
rm -rf "$temp_out_path"
|
||||||
rm -f "$zip_path" && say_verbose "Temporary zip file $zip_path was removed"
|
if [ -z ${keep_zip+x} ]; then
|
||||||
|
rm -f "$zip_path" && say_verbose "Temporary archive file $zip_path was removed"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$failed" = true ]; then
|
if [ "$failed" = true ]; then
|
||||||
say_err "Extraction failed"
|
say_err "Extraction failed"
|
||||||
@@ -1136,6 +1272,61 @@ downloadwget() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extract_stem() {
|
||||||
|
local url="$1"
|
||||||
|
# extract the protocol
|
||||||
|
proto="$(echo $1 | grep :// | sed -e's,^\(.*://\).*,\1,g')"
|
||||||
|
# remove the protocol
|
||||||
|
url="${1/$proto/}"
|
||||||
|
# extract the path (if any) - since we know all of our feeds have a first path segment, we can skip the first one. otherwise we'd use -f2- to get the full path
|
||||||
|
full_path="$(echo $url | grep / | cut -d/ -f2-)"
|
||||||
|
path="$(echo $full_path | cut -d/ -f2-)"
|
||||||
|
echo $path
|
||||||
|
}
|
||||||
|
|
||||||
|
check_url_exists() {
|
||||||
|
eval $invocation
|
||||||
|
local url="$1"
|
||||||
|
|
||||||
|
local code=""
|
||||||
|
if machine_has "curl"
|
||||||
|
then
|
||||||
|
code=$(curl --head -o /dev/null -w "%{http_code}" -s --fail "$url");
|
||||||
|
elif machine_has "wget"
|
||||||
|
then
|
||||||
|
# get the http response, grab the status code
|
||||||
|
server_response=$(wget -qO- --method=HEAD --server-response "$url" 2>&1)
|
||||||
|
code=$(echo "$server_response" | grep "HTTP/" | awk '{print $2}')
|
||||||
|
fi
|
||||||
|
if [ $code = "200" ]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
sanitize_redirect_url() {
|
||||||
|
eval $invocation
|
||||||
|
|
||||||
|
local url_stem
|
||||||
|
url_stem=$(extract_stem "$1")
|
||||||
|
say_verbose "Checking configured feeds for the asset at ${yellow:-}$url_stem${normal:-}"
|
||||||
|
|
||||||
|
for feed in "${feeds[@]}"
|
||||||
|
do
|
||||||
|
local trial_url="$feed/$url_stem"
|
||||||
|
say_verbose "Checking ${yellow:-}$trial_url${normal:-}"
|
||||||
|
if check_url_exists "$trial_url"; then
|
||||||
|
say_verbose "Found a match at ${yellow:-}$trial_url${normal:-}"
|
||||||
|
echo "$trial_url"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
say_verbose "No match at ${yellow:-}$trial_url${normal:-}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
get_download_link_from_aka_ms() {
|
get_download_link_from_aka_ms() {
|
||||||
eval $invocation
|
eval $invocation
|
||||||
|
|
||||||
@@ -1172,6 +1363,12 @@ get_download_link_from_aka_ms() {
|
|||||||
http_codes=$( echo "$response" | awk '$1 ~ /^HTTP/ {print $2}' )
|
http_codes=$( echo "$response" | awk '$1 ~ /^HTTP/ {print $2}' )
|
||||||
# They all need to be 301, otherwise some links are broken (except for the last, which is not a redirect but 200 or 404).
|
# They all need to be 301, otherwise some links are broken (except for the last, which is not a redirect but 200 or 404).
|
||||||
broken_redirects=$( echo "$http_codes" | sed '$d' | grep -v '301' )
|
broken_redirects=$( echo "$http_codes" | sed '$d' | grep -v '301' )
|
||||||
|
# The response may end without final code 2xx/4xx/5xx somehow, e.g. network restrictions on www.bing.com causes redirecting to bing.com fails with connection refused.
|
||||||
|
# In this case it should not exclude the last.
|
||||||
|
last_http_code=$( echo "$http_codes" | tail -n 1 )
|
||||||
|
if ! [[ $last_http_code =~ ^(2|4|5)[0-9][0-9]$ ]]; then
|
||||||
|
broken_redirects=$( echo "$http_codes" | grep -v '301' )
|
||||||
|
fi
|
||||||
|
|
||||||
# All HTTP codes are 301 (Moved Permanently), the redirect link exists.
|
# All HTTP codes are 301 (Moved Permanently), the redirect link exists.
|
||||||
if [[ -z "$broken_redirects" ]]; then
|
if [[ -z "$broken_redirects" ]]; then
|
||||||
@@ -1182,6 +1379,11 @@ get_download_link_from_aka_ms() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
sanitized_redirect_url=$(sanitize_redirect_url "$aka_ms_download_link")
|
||||||
|
if [[ -n "$sanitized_redirect_url" ]]; then
|
||||||
|
aka_ms_download_link="$sanitized_redirect_url"
|
||||||
|
fi
|
||||||
|
|
||||||
say_verbose "The redirect location retrieved: '$aka_ms_download_link'."
|
say_verbose "The redirect location retrieved: '$aka_ms_download_link'."
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
@@ -1193,23 +1395,16 @@ get_download_link_from_aka_ms() {
|
|||||||
get_feeds_to_use()
|
get_feeds_to_use()
|
||||||
{
|
{
|
||||||
feeds=(
|
feeds=(
|
||||||
"https://dotnetcli.azureedge.net/dotnet"
|
"https://builds.dotnet.microsoft.com/dotnet"
|
||||||
"https://dotnetbuilds.azureedge.net/public"
|
"https://ci.dot.net/public"
|
||||||
)
|
)
|
||||||
|
|
||||||
if [[ -n "$azure_feed" ]]; then
|
if [[ -n "$azure_feed" ]]; then
|
||||||
feeds=("$azure_feed")
|
feeds=("$azure_feed")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$no_cdn" == "true" ]]; then
|
if [[ -n "$uncached_feed" ]]; then
|
||||||
feeds=(
|
feeds=("$uncached_feed")
|
||||||
"https://dotnetcli.blob.core.windows.net/dotnet"
|
|
||||||
"https://dotnetbuilds.blob.core.windows.net/public"
|
|
||||||
)
|
|
||||||
|
|
||||||
if [[ -n "$uncached_feed" ]]; then
|
|
||||||
feeds=("$uncached_feed")
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1341,7 +1536,7 @@ generate_regular_links() {
|
|||||||
link_types+=("legacy")
|
link_types+=("legacy")
|
||||||
else
|
else
|
||||||
legacy_download_link=""
|
legacy_download_link=""
|
||||||
say_verbose "Cound not construct a legacy_download_link; omitting..."
|
say_verbose "Could not construct a legacy_download_link; omitting..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if the SDK version is already installed.
|
# Check if the SDK version is already installed.
|
||||||
@@ -1419,10 +1614,11 @@ install_dotnet() {
|
|||||||
eval $invocation
|
eval $invocation
|
||||||
local download_failed=false
|
local download_failed=false
|
||||||
local download_completed=false
|
local download_completed=false
|
||||||
|
local remote_file_size=0
|
||||||
|
|
||||||
mkdir -p "$install_root"
|
mkdir -p "$install_root"
|
||||||
zip_path="$(mktemp "$temporary_file_template")"
|
zip_path="${zip_path:-$(mktemp "$temporary_file_template")}"
|
||||||
say_verbose "Zip path: $zip_path"
|
say_verbose "Archive path: $zip_path"
|
||||||
|
|
||||||
for link_index in "${!download_links[@]}"
|
for link_index in "${!download_links[@]}"
|
||||||
do
|
do
|
||||||
@@ -1443,10 +1639,10 @@ install_dotnet() {
|
|||||||
say "The resource at $link_type link '$download_link' is not available."
|
say "The resource at $link_type link '$download_link' is not available."
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
say "Failed to download $link_type link '$download_link': $download_error_msg"
|
say "Failed to download $link_type link '$download_link': $http_code $download_error_msg"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
rm -f "$zip_path" 2>&1 && say_verbose "Temporary zip file $zip_path was removed"
|
rm -f "$zip_path" 2>&1 && say_verbose "Temporary archive file $zip_path was removed"
|
||||||
else
|
else
|
||||||
download_completed=true
|
download_completed=true
|
||||||
break
|
break
|
||||||
@@ -1459,8 +1655,10 @@ install_dotnet() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
say "Extracting zip from $download_link"
|
remote_file_size="$(get_remote_file_size "$download_link")"
|
||||||
extract_dotnet_package "$zip_path" "$install_root" || return 1
|
|
||||||
|
say "Extracting archive from $download_link"
|
||||||
|
extract_dotnet_package "$zip_path" "$install_root" "$remote_file_size" || return 1
|
||||||
|
|
||||||
# Check if the SDK version is installed; if not, fail the installation.
|
# Check if the SDK version is installed; if not, fail the installation.
|
||||||
# if the version contains "RTM" or "servicing"; check if a 'release-type' SDK version is installed.
|
# if the version contains "RTM" or "servicing"; check if a 'release-type' SDK version is installed.
|
||||||
@@ -1502,7 +1700,6 @@ install_dir="<auto>"
|
|||||||
architecture="<auto>"
|
architecture="<auto>"
|
||||||
dry_run=false
|
dry_run=false
|
||||||
no_path=false
|
no_path=false
|
||||||
no_cdn=false
|
|
||||||
azure_feed=""
|
azure_feed=""
|
||||||
uncached_feed=""
|
uncached_feed=""
|
||||||
feed_credential=""
|
feed_credential=""
|
||||||
@@ -1575,10 +1772,6 @@ do
|
|||||||
verbose=true
|
verbose=true
|
||||||
non_dynamic_parameters+=" $name"
|
non_dynamic_parameters+=" $name"
|
||||||
;;
|
;;
|
||||||
--no-cdn|-[Nn]o[Cc]dn)
|
|
||||||
no_cdn=true
|
|
||||||
non_dynamic_parameters+=" $name"
|
|
||||||
;;
|
|
||||||
--azure-feed|-[Aa]zure[Ff]eed)
|
--azure-feed|-[Aa]zure[Ff]eed)
|
||||||
shift
|
shift
|
||||||
azure_feed="$1"
|
azure_feed="$1"
|
||||||
@@ -1610,10 +1803,22 @@ do
|
|||||||
override_non_versioned_files=false
|
override_non_versioned_files=false
|
||||||
non_dynamic_parameters+=" $name"
|
non_dynamic_parameters+=" $name"
|
||||||
;;
|
;;
|
||||||
|
--keep-zip|-[Kk]eep[Zz]ip)
|
||||||
|
keep_zip=true
|
||||||
|
non_dynamic_parameters+=" $name"
|
||||||
|
;;
|
||||||
|
--zip-path|-[Zz]ip[Pp]ath)
|
||||||
|
shift
|
||||||
|
zip_path="$1"
|
||||||
|
;;
|
||||||
-?|--?|-h|--help|-[Hh]elp)
|
-?|--?|-h|--help|-[Hh]elp)
|
||||||
script_name="$(basename "$0")"
|
script_name="dotnet-install.sh"
|
||||||
echo ".NET Tools Installer"
|
echo ".NET Tools Installer"
|
||||||
echo "Usage: $script_name [-c|--channel <CHANNEL>] [-v|--version <VERSION>] [-p|--prefix <DESTINATION>]"
|
echo "Usage:"
|
||||||
|
echo " # Install a .NET SDK of a given Quality from a given Channel"
|
||||||
|
echo " $script_name [-c|--channel <CHANNEL>] [-q|--quality <QUALITY>]"
|
||||||
|
echo " # Install a .NET SDK of a specific public version"
|
||||||
|
echo " $script_name [-v|--version <VERSION>]"
|
||||||
echo " $script_name -h|-?|--help"
|
echo " $script_name -h|-?|--help"
|
||||||
echo ""
|
echo ""
|
||||||
echo "$script_name is a simple command line interface for obtaining dotnet cli."
|
echo "$script_name is a simple command line interface for obtaining dotnet cli."
|
||||||
@@ -1655,7 +1860,7 @@ do
|
|||||||
echo " -InstallDir"
|
echo " -InstallDir"
|
||||||
echo " --architecture <ARCHITECTURE> Architecture of dotnet binaries to be installed, Defaults to \`$architecture\`."
|
echo " --architecture <ARCHITECTURE> Architecture of dotnet binaries to be installed, Defaults to \`$architecture\`."
|
||||||
echo " --arch,-Architecture,-Arch"
|
echo " --arch,-Architecture,-Arch"
|
||||||
echo " Possible values: x64, arm, arm64 and s390x"
|
echo " Possible values: x64, arm, arm64, s390x, ppc64le and loongarch64"
|
||||||
echo " --os <system> Specifies operating system to be used when selecting the installer."
|
echo " --os <system> Specifies operating system to be used when selecting the installer."
|
||||||
echo " Overrides the OS determination approach used by the script. Supported values: osx, linux, linux-musl, freebsd, rhel.6."
|
echo " Overrides the OS determination approach used by the script. Supported values: osx, linux, linux-musl, freebsd, rhel.6."
|
||||||
echo " In case any other value is provided, the platform will be determined by the script based on machine configuration."
|
echo " In case any other value is provided, the platform will be determined by the script based on machine configuration."
|
||||||
@@ -1671,15 +1876,14 @@ do
|
|||||||
echo " --verbose,-Verbose Display diagnostics information."
|
echo " --verbose,-Verbose Display diagnostics information."
|
||||||
echo " --azure-feed,-AzureFeed For internal use only."
|
echo " --azure-feed,-AzureFeed For internal use only."
|
||||||
echo " Allows using a different storage to download SDK archives from."
|
echo " Allows using a different storage to download SDK archives from."
|
||||||
echo " This parameter is only used if --no-cdn is false."
|
|
||||||
echo " --uncached-feed,-UncachedFeed For internal use only."
|
echo " --uncached-feed,-UncachedFeed For internal use only."
|
||||||
echo " Allows using a different storage to download SDK archives from."
|
echo " Allows using a different storage to download SDK archives from."
|
||||||
echo " This parameter is only used if --no-cdn is true."
|
|
||||||
echo " --skip-non-versioned-files Skips non-versioned files if they already exist, such as the dotnet executable."
|
echo " --skip-non-versioned-files Skips non-versioned files if they already exist, such as the dotnet executable."
|
||||||
echo " -SkipNonVersionedFiles"
|
echo " -SkipNonVersionedFiles"
|
||||||
echo " --no-cdn,-NoCdn Disable downloading from the Azure CDN, and use the uncached feed directly."
|
|
||||||
echo " --jsonfile <JSONFILE> Determines the SDK version from a user specified global.json file."
|
echo " --jsonfile <JSONFILE> Determines the SDK version from a user specified global.json file."
|
||||||
echo " Note: global.json must have a value for 'SDK:Version'"
|
echo " Note: global.json must have a value for 'SDK:Version'"
|
||||||
|
echo " --keep-zip,-KeepZip If set, downloaded file is kept."
|
||||||
|
echo " --zip-path, -ZipPath If set, downloaded file is stored at the specified path."
|
||||||
echo " -?,--?,-h,--help,-Help Shows this help message"
|
echo " -?,--?,-h,--help,-Help Shows this help message"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Install Location:"
|
echo "Install Location:"
|
||||||
|
|||||||
2549
package-lock.json
generated
2549
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
28
package.json
28
package.json
@@ -1,17 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "setup-dotnet",
|
"name": "setup-dotnet",
|
||||||
"version": "3.0.2",
|
"version": "2.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "setup dotnet action",
|
"description": "setup dotnet action",
|
||||||
"main": "lib/setup-dotnet.js",
|
"main": "lib/setup-dotnet.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc && ncc build",
|
"build": "tsc && ncc build",
|
||||||
"format": "prettier --no-error-on-unmatched-pattern --config ./.prettierrc.js --write \"**/*.{ts,yml,yaml}\"",
|
"format": "prettier --write **/*.ts",
|
||||||
"format-check": "prettier --no-error-on-unmatched-pattern --config ./.prettierrc.js --check \"**/*.{ts,yml,yaml}\"",
|
"format-check": "prettier --check **/*.ts",
|
||||||
"lint": "eslint --config ./.eslintrc.js \"**/*.ts\"",
|
|
||||||
"lint:fix": "eslint --config ./.eslintrc.js \"**/*.ts\" --fix",
|
|
||||||
"prepare": "husky install",
|
"prepare": "husky install",
|
||||||
"test": "jest --coverage --config ./jest.config.js",
|
"test": "jest",
|
||||||
"update-installers": "nwget https://dot.net/v1/dotnet-install.ps1 -O externals/install-dotnet.ps1 && nwget https://dot.net/v1/dotnet-install.sh -O externals/install-dotnet.sh"
|
"update-installers": "nwget https://dot.net/v1/dotnet-install.ps1 -O externals/install-dotnet.ps1 && nwget https://dot.net/v1/dotnet-install.sh -O externals/install-dotnet.sh"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -26,30 +24,26 @@
|
|||||||
"author": "GitHub",
|
"author": "GitHub",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^1.6.0",
|
||||||
"@actions/exec": "^1.0.4",
|
"@actions/exec": "^1.0.4",
|
||||||
"@actions/github": "^1.1.0",
|
"@actions/github": "^1.1.0",
|
||||||
"@actions/http-client": "^2.0.1",
|
"@actions/http-client": "^1.0.8",
|
||||||
"@actions/io": "^1.0.2",
|
"@actions/io": "^1.0.2",
|
||||||
"fast-xml-parser": "^4.0.10",
|
"fast-xml-parser": "^3.15.1",
|
||||||
"semver": "^6.3.0"
|
"semver": "^6.3.0",
|
||||||
|
"xmlbuilder": "^13.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^27.0.2",
|
"@types/jest": "^27.0.2",
|
||||||
"@types/node": "^16.11.25",
|
"@types/node": "^16.11.25",
|
||||||
"@types/semver": "^6.2.2",
|
"@types/semver": "^6.2.2",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
|
||||||
"@typescript-eslint/parser": "^5.54.0",
|
|
||||||
"@vercel/ncc": "^0.33.4",
|
"@vercel/ncc": "^0.33.4",
|
||||||
"eslint": "^8.35.0",
|
|
||||||
"eslint-config-prettier": "^8.6.0",
|
|
||||||
"eslint-plugin-jest": "^27.2.1",
|
|
||||||
"husky": "^8.0.1",
|
"husky": "^8.0.1",
|
||||||
"jest": "^27.2.5",
|
"jest": "^27.2.5",
|
||||||
"jest-circus": "^27.2.5",
|
"jest-circus": "^27.2.5",
|
||||||
"prettier": "^2.8.4",
|
"prettier": "^1.19.1",
|
||||||
"ts-jest": "^27.0.5",
|
"ts-jest": "^27.0.5",
|
||||||
"typescript": "^4.8.4",
|
"typescript": "^3.9.7",
|
||||||
"wget-improved": "^3.2.1"
|
"wget-improved": "^3.2.1"
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
|
|||||||
351
src/authutil.ts
351
src/authutil.ts
@@ -1,196 +1,155 @@
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as github from '@actions/github';
|
import * as github from '@actions/github';
|
||||||
import {XMLParser, XMLBuilder} from 'fast-xml-parser';
|
import * as xmlbuilder from 'xmlbuilder';
|
||||||
|
import * as xmlParser from 'fast-xml-parser';
|
||||||
export function configAuthentication(
|
import {ProcessEnvOptions} from 'child_process';
|
||||||
feedUrl: string,
|
|
||||||
existingFileLocation = '',
|
export function configAuthentication(
|
||||||
processRoot: string = process.cwd()
|
feedUrl: string,
|
||||||
) {
|
existingFileLocation: string = '',
|
||||||
const existingNuGetConfig: string = path.resolve(
|
processRoot: string = process.cwd()
|
||||||
processRoot,
|
) {
|
||||||
existingFileLocation === ''
|
const existingNuGetConfig: string = path.resolve(
|
||||||
? getExistingNugetConfig(processRoot)
|
processRoot,
|
||||||
: existingFileLocation
|
existingFileLocation === ''
|
||||||
);
|
? getExistingNugetConfig(processRoot)
|
||||||
|
: existingFileLocation
|
||||||
const tempNuGetConfig: string = path.resolve(
|
);
|
||||||
processRoot,
|
|
||||||
'../',
|
const tempNuGetConfig: string = path.resolve(
|
||||||
'nuget.config'
|
processRoot,
|
||||||
);
|
'../',
|
||||||
|
'nuget.config'
|
||||||
writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig);
|
);
|
||||||
}
|
|
||||||
|
writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig);
|
||||||
function isValidKey(key: string): boolean {
|
}
|
||||||
return /^[\w\-.]+$/i.test(key);
|
|
||||||
}
|
function isValidKey(key: string): boolean {
|
||||||
|
return /^[\w\-\.]+$/i.test(key);
|
||||||
function getExistingNugetConfig(processRoot: string) {
|
}
|
||||||
const defaultConfigName = 'nuget.config';
|
|
||||||
const configFileNames = fs
|
function getExistingNugetConfig(processRoot: string) {
|
||||||
.readdirSync(processRoot)
|
const defaultConfigName = 'nuget.config';
|
||||||
.filter(filename => filename.toLowerCase() === defaultConfigName);
|
const configFileNames = fs
|
||||||
if (configFileNames.length) {
|
.readdirSync(processRoot)
|
||||||
return configFileNames[0];
|
.filter(filename => filename.toLowerCase() === defaultConfigName);
|
||||||
}
|
if (configFileNames.length) {
|
||||||
return defaultConfigName;
|
return configFileNames[0];
|
||||||
}
|
}
|
||||||
|
return defaultConfigName;
|
||||||
function writeFeedToFile(
|
}
|
||||||
feedUrl: string,
|
|
||||||
existingFileLocation: string,
|
function writeFeedToFile(
|
||||||
tempFileLocation: string
|
feedUrl: string,
|
||||||
) {
|
existingFileLocation: string,
|
||||||
core.info(
|
tempFileLocation: string
|
||||||
`dotnet-auth: Finding any source references in ${existingFileLocation}, writing a new temporary configuration file with credentials to ${tempFileLocation}`
|
) {
|
||||||
);
|
console.log(
|
||||||
const sourceKeys: string[] = [];
|
`dotnet-auth: Finding any source references in ${existingFileLocation}, writing a new temporary configuration file with credentials to ${tempFileLocation}`
|
||||||
let owner: string = core.getInput('owner');
|
);
|
||||||
const sourceUrl: string = feedUrl;
|
let xml: xmlbuilder.XMLElement;
|
||||||
if (!owner) {
|
let sourceKeys: string[] = [];
|
||||||
owner = github.context.repo.owner;
|
let owner: string = core.getInput('owner');
|
||||||
}
|
let sourceUrl: string = feedUrl;
|
||||||
|
if (!owner) {
|
||||||
if (!process.env.NUGET_AUTH_TOKEN) {
|
owner = github.context.repo.owner;
|
||||||
throw new Error(
|
}
|
||||||
'The NUGET_AUTH_TOKEN environment variable was not provided. In this step, add the following: \r\nenv:\r\n NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}'
|
|
||||||
);
|
if (!process.env.NUGET_AUTH_TOKEN || process.env.NUGET_AUTH_TOKEN == '') {
|
||||||
}
|
throw new Error(
|
||||||
|
'The NUGET_AUTH_TOKEN environment variable was not provided. In this step, add the following: \r\nenv:\r\n NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}'
|
||||||
if (fs.existsSync(existingFileLocation)) {
|
);
|
||||||
// get key from existing NuGet.config so NuGet/dotnet can match credentials
|
}
|
||||||
const curContents: string = fs.readFileSync(existingFileLocation, 'utf8');
|
|
||||||
|
if (fs.existsSync(existingFileLocation)) {
|
||||||
const parserOptions = {
|
// get key from existing NuGet.config so NuGet/dotnet can match credentials
|
||||||
ignoreAttributes: false
|
const curContents: string = fs.readFileSync(existingFileLocation, 'utf8');
|
||||||
};
|
var json = xmlParser.parse(curContents, {ignoreAttributes: false});
|
||||||
const parser = new XMLParser(parserOptions);
|
|
||||||
const json = parser.parse(curContents);
|
if (typeof json.configuration == 'undefined') {
|
||||||
|
throw new Error(`The provided NuGet.config seems invalid.`);
|
||||||
if (typeof json.configuration === 'undefined') {
|
}
|
||||||
throw new Error(`The provided NuGet.config seems invalid.`);
|
if (typeof json.configuration.packageSources != 'undefined') {
|
||||||
}
|
if (typeof json.configuration.packageSources.add != 'undefined') {
|
||||||
if (json.configuration?.packageSources?.add) {
|
// file has at least one <add>
|
||||||
const packageSources = json.configuration.packageSources.add;
|
if (typeof json.configuration.packageSources.add[0] == 'undefined') {
|
||||||
|
// file has only one <add>
|
||||||
if (Array.isArray(packageSources)) {
|
if (
|
||||||
packageSources.forEach(source => {
|
json.configuration.packageSources.add['@_value']
|
||||||
const value = source['@_value'];
|
.toLowerCase()
|
||||||
core.debug(`source '${value}'`);
|
.includes(feedUrl.toLowerCase())
|
||||||
if (value.toLowerCase().includes(feedUrl.toLowerCase())) {
|
) {
|
||||||
const key = source['@_key'];
|
let key = json.configuration.packageSources.add['@_key'];
|
||||||
sourceKeys.push(key);
|
sourceKeys.push(key);
|
||||||
core.debug(`Found a URL with key ${key}`);
|
core.debug(`Found a URL with key ${key}`);
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
} else {
|
// file has 2+ <add>
|
||||||
if (
|
for (
|
||||||
packageSources['@_value']
|
let i = 0;
|
||||||
.toLowerCase()
|
i < json.configuration.packageSources.add.length;
|
||||||
.includes(feedUrl.toLowerCase())
|
i++
|
||||||
) {
|
) {
|
||||||
const key = packageSources['@_key'];
|
const source = json.configuration.packageSources.add[i];
|
||||||
sourceKeys.push(key);
|
const value = source['@_value'];
|
||||||
core.debug(`Found a URL with key ${key}`);
|
core.debug(`source '${value}'`);
|
||||||
}
|
if (value.toLowerCase().includes(feedUrl.toLowerCase())) {
|
||||||
}
|
let key = source['@_key'];
|
||||||
}
|
sourceKeys.push(key);
|
||||||
}
|
core.debug(`Found a URL with key ${key}`);
|
||||||
|
}
|
||||||
const xmlSource: any[] = [
|
}
|
||||||
{
|
}
|
||||||
'?xml': [
|
}
|
||||||
{
|
}
|
||||||
'#text': ''
|
}
|
||||||
}
|
|
||||||
],
|
xml = xmlbuilder
|
||||||
':@': {
|
.create('configuration')
|
||||||
'@_version': '1.0'
|
.ele('config')
|
||||||
}
|
.ele('add', {key: 'defaultPushSource', value: sourceUrl})
|
||||||
},
|
.up()
|
||||||
{
|
.up();
|
||||||
configuration: [
|
|
||||||
{
|
if (sourceKeys.length == 0) {
|
||||||
config: [
|
let keystring = 'Source';
|
||||||
{
|
xml = xml
|
||||||
add: [],
|
.ele('packageSources')
|
||||||
':@': {
|
.ele('add', {key: keystring, value: sourceUrl})
|
||||||
'@_key': 'defaultPushSource',
|
.up()
|
||||||
'@_value': sourceUrl
|
.up();
|
||||||
}
|
sourceKeys.push(keystring);
|
||||||
}
|
}
|
||||||
]
|
xml = xml.ele('packageSourceCredentials');
|
||||||
}
|
|
||||||
]
|
sourceKeys.forEach(key => {
|
||||||
}
|
if (!isValidKey(key)) {
|
||||||
];
|
throw new Error(
|
||||||
|
"Source name can contain letters, numbers, and '-', '_', '.' symbols only. Please, fix source name in NuGet.config and try again."
|
||||||
if (!sourceKeys.length) {
|
);
|
||||||
const keystring = 'Source';
|
}
|
||||||
|
|
||||||
xmlSource[1].configuration.push({
|
xml = xml
|
||||||
packageSources: [
|
.ele(key)
|
||||||
{
|
.ele('add', {key: 'Username', value: owner})
|
||||||
add: [],
|
.up()
|
||||||
':@': {
|
.ele('add', {
|
||||||
'@_key': keystring,
|
key: 'ClearTextPassword',
|
||||||
'@_value': sourceUrl
|
value: process.env.NUGET_AUTH_TOKEN
|
||||||
}
|
})
|
||||||
}
|
.up()
|
||||||
]
|
.up();
|
||||||
});
|
});
|
||||||
|
|
||||||
sourceKeys.push(keystring);
|
// If NuGet fixes itself such that on Linux it can look for environment variables in the config file (it doesn't seem to work today),
|
||||||
}
|
// use this for the value above
|
||||||
|
// process.platform == 'win32'
|
||||||
const packageSourceCredentials: any[] = [];
|
// ? '%NUGET_AUTH_TOKEN%'
|
||||||
sourceKeys.forEach(key => {
|
// : '$NUGET_AUTH_TOKEN'
|
||||||
if (!isValidKey(key)) {
|
|
||||||
throw new Error(
|
var output = xml.end({pretty: true});
|
||||||
"Source name can contain letters, numbers, and '-', '_', '.' symbols only. Please, fix source name in NuGet.config and try again."
|
fs.writeFileSync(tempFileLocation, output);
|
||||||
);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
packageSourceCredentials.push({
|
|
||||||
[key]: [
|
|
||||||
{
|
|
||||||
add: [],
|
|
||||||
':@': {
|
|
||||||
'@_key': 'Username',
|
|
||||||
'@_value': owner
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
add: [],
|
|
||||||
':@': {
|
|
||||||
'@_key': 'ClearTextPassword',
|
|
||||||
'@_value': process.env.NUGET_AUTH_TOKEN
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
xmlSource[1].configuration.push({
|
|
||||||
packageSourceCredentials
|
|
||||||
});
|
|
||||||
|
|
||||||
const xmlBuilderOptions = {
|
|
||||||
format: true,
|
|
||||||
ignoreAttributes: false,
|
|
||||||
preserveOrder: true,
|
|
||||||
allowBooleanAttributes: true,
|
|
||||||
suppressBooleanAttributes: true,
|
|
||||||
suppressEmptyNode: true
|
|
||||||
};
|
|
||||||
|
|
||||||
const builder = new XMLBuilder(xmlBuilderOptions);
|
|
||||||
|
|
||||||
const output = builder.build(xmlSource).trim();
|
|
||||||
|
|
||||||
fs.writeFileSync(tempFileLocation, output);
|
|
||||||
}
|
|
||||||
|
|||||||
582
src/installer.ts
582
src/installer.ts
@@ -1,278 +1,304 @@
|
|||||||
// Load tempDirectory before it gets wiped by tool-cache
|
// Load tempDirectory before it gets wiped by tool-cache
|
||||||
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 * as hc from '@actions/http-client';
|
import hc = require('@actions/http-client');
|
||||||
import {chmodSync} from 'fs';
|
import {chmodSync} from 'fs';
|
||||||
import path from 'path';
|
import * as path from 'path';
|
||||||
import os from 'os';
|
import {ExecOptions} from '@actions/exec/lib/interfaces';
|
||||||
import semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import {IS_LINUX, IS_WINDOWS} from './utils';
|
|
||||||
import {QualityOptions} from './setup-dotnet';
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
|
|
||||||
export interface DotnetVersion {
|
/**
|
||||||
type: string;
|
* Represents the inputted version information
|
||||||
value: string;
|
*/
|
||||||
qualityFlag: boolean;
|
export class DotNetVersionInfo {
|
||||||
}
|
public inputVersion: string;
|
||||||
|
private fullversion: string;
|
||||||
const QUALITY_INPUT_MINIMAL_MAJOR_TAG = 6;
|
private isExactVersionSet: boolean = false;
|
||||||
const LATEST_PATCH_SYNTAX_MINIMAL_MAJOR_TAG = 5;
|
|
||||||
export class DotnetVersionResolver {
|
constructor(version: string) {
|
||||||
private inputVersion: string;
|
this.inputVersion = version;
|
||||||
private resolvedArgument: DotnetVersion;
|
|
||||||
|
// Check for exact match
|
||||||
constructor(version: string) {
|
if (semver.valid(semver.clean(version) || '') != null) {
|
||||||
this.inputVersion = version.trim();
|
this.fullversion = semver.clean(version) as string;
|
||||||
this.resolvedArgument = {type: '', value: '', qualityFlag: false};
|
this.isExactVersionSet = true;
|
||||||
}
|
|
||||||
|
return;
|
||||||
private async resolveVersionInput(): Promise<void> {
|
}
|
||||||
if (!semver.validRange(this.inputVersion) && !this.isLatestPatchSyntax()) {
|
|
||||||
throw new Error(
|
const parts: string[] = version.split('.');
|
||||||
`The 'dotnet-version' was supplied in invalid format: ${this.inputVersion}! Supported syntax: A.B.C, A.B, A.B.x, A, A.x, A.B.Cxx`
|
|
||||||
);
|
if (parts.length < 2 || parts.length > 3) this.throwInvalidVersionFormat();
|
||||||
}
|
|
||||||
if (semver.valid(this.inputVersion)) {
|
if (parts.length == 3 && parts[2] !== 'x' && parts[2] !== '*') {
|
||||||
this.createVersionArgument();
|
this.throwInvalidVersionFormat();
|
||||||
} else {
|
}
|
||||||
await this.createChannelArgument();
|
|
||||||
}
|
const major = this.getVersionNumberOrThrow(parts[0]);
|
||||||
}
|
const minor = ['x', '*'].includes(parts[1])
|
||||||
|
? parts[1]
|
||||||
private isNumericTag(versionTag): boolean {
|
: this.getVersionNumberOrThrow(parts[1]);
|
||||||
return /^\d+$/.test(versionTag);
|
|
||||||
}
|
this.fullversion = major + '.' + minor;
|
||||||
|
}
|
||||||
private isLatestPatchSyntax() {
|
|
||||||
const majorTag = this.inputVersion.match(
|
private getVersionNumberOrThrow(input: string): number {
|
||||||
/^(?<majorTag>\d+)\.\d+\.\d{1}x{2}$/
|
try {
|
||||||
)?.groups?.majorTag;
|
if (!input || input.trim() === '') this.throwInvalidVersionFormat();
|
||||||
if (
|
|
||||||
majorTag &&
|
let number = Number(input);
|
||||||
parseInt(majorTag) < LATEST_PATCH_SYNTAX_MINIMAL_MAJOR_TAG
|
|
||||||
) {
|
if (Number.isNaN(number) || number < 0) this.throwInvalidVersionFormat();
|
||||||
throw new Error(
|
|
||||||
`The 'dotnet-version' was supplied in invalid format: ${this.inputVersion}! The A.B.Cxx syntax is available since the .NET 5.0 release.`
|
return number;
|
||||||
);
|
} catch {
|
||||||
}
|
this.throwInvalidVersionFormat();
|
||||||
return majorTag ? true : false;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private createVersionArgument() {
|
|
||||||
this.resolvedArgument.type = 'version';
|
private throwInvalidVersionFormat() {
|
||||||
this.resolvedArgument.value = this.inputVersion;
|
throw new Error(
|
||||||
}
|
'Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*'
|
||||||
|
);
|
||||||
private async createChannelArgument() {
|
}
|
||||||
this.resolvedArgument.type = 'channel';
|
|
||||||
const [major, minor] = this.inputVersion.split('.');
|
/**
|
||||||
if (this.isLatestPatchSyntax()) {
|
* If true exacatly one version should be resolved
|
||||||
this.resolvedArgument.value = this.inputVersion;
|
*/
|
||||||
} else if (this.isNumericTag(major) && this.isNumericTag(minor)) {
|
public isExactVersion(): boolean {
|
||||||
this.resolvedArgument.value = `${major}.${minor}`;
|
return this.isExactVersionSet;
|
||||||
} else if (this.isNumericTag(major)) {
|
}
|
||||||
this.resolvedArgument.value = await this.getLatestByMajorTag(major);
|
|
||||||
} else {
|
public version(): string {
|
||||||
// If "dotnet-version" is specified as *, x or X resolve latest version of .NET explicitly from LTS channel. The version argument will default to "latest" by install-dotnet script.
|
return this.fullversion;
|
||||||
this.resolvedArgument.value = 'LTS';
|
}
|
||||||
}
|
}
|
||||||
this.resolvedArgument.qualityFlag =
|
|
||||||
parseInt(major) >= QUALITY_INPUT_MINIMAL_MAJOR_TAG ? true : false;
|
export class DotnetCoreInstaller {
|
||||||
}
|
constructor(version: string, includePrerelease: boolean = false) {
|
||||||
|
this.version = version;
|
||||||
public async createDotNetVersion(): Promise<DotnetVersion> {
|
this.includePrerelease = includePrerelease;
|
||||||
await this.resolveVersionInput();
|
}
|
||||||
if (!this.resolvedArgument.type) {
|
|
||||||
return this.resolvedArgument;
|
public async installDotnet() {
|
||||||
}
|
let output = '';
|
||||||
if (IS_WINDOWS) {
|
let resultCode = 0;
|
||||||
this.resolvedArgument.type =
|
|
||||||
this.resolvedArgument.type === 'channel' ? '-Channel' : '-Version';
|
let calculatedVersion = await this.resolveVersion(
|
||||||
} else {
|
new DotNetVersionInfo(this.version)
|
||||||
this.resolvedArgument.type =
|
);
|
||||||
this.resolvedArgument.type === 'channel' ? '--channel' : '--version';
|
|
||||||
}
|
var envVariables: {[key: string]: string} = {};
|
||||||
return this.resolvedArgument;
|
for (let key in process.env) {
|
||||||
}
|
if (process.env[key]) {
|
||||||
|
let value: any = process.env[key];
|
||||||
private async getLatestByMajorTag(majorTag: string): Promise<string> {
|
envVariables[key] = value;
|
||||||
const httpClient = new hc.HttpClient('actions/setup-dotnet', [], {
|
}
|
||||||
allowRetries: true,
|
}
|
||||||
maxRetries: 3
|
if (IS_WINDOWS) {
|
||||||
});
|
let escapedScript = path
|
||||||
const response = await httpClient.getJson<any>(
|
.join(__dirname, '..', 'externals', 'install-dotnet.ps1')
|
||||||
DotnetVersionResolver.DotNetCoreIndexUrl
|
.replace(/'/g, "''");
|
||||||
);
|
let command = `& '${escapedScript}'`;
|
||||||
const result = response.result || {};
|
if (calculatedVersion) {
|
||||||
const releasesInfo: any[] = result['releases-index'];
|
command += ` -Version ${calculatedVersion}`;
|
||||||
|
}
|
||||||
const releaseInfo = releasesInfo.find(info => {
|
if (process.env['https_proxy'] != null) {
|
||||||
const sdkParts: string[] = info['channel-version'].split('.');
|
command += ` -ProxyAddress ${process.env['https_proxy']}`;
|
||||||
return sdkParts[0] === majorTag;
|
}
|
||||||
});
|
// This is not currently an option
|
||||||
|
if (process.env['no_proxy'] != null) {
|
||||||
if (!releaseInfo) {
|
command += ` -ProxyBypassList ${process.env['no_proxy']}`;
|
||||||
throw new Error(
|
}
|
||||||
`Could not find info for version with major tag: "${majorTag}" at ${DotnetVersionResolver.DotNetCoreIndexUrl}`
|
|
||||||
);
|
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
|
||||||
}
|
const powershellPath =
|
||||||
|
(await io.which('pwsh', false)) || (await io.which('powershell', true));
|
||||||
return releaseInfo['channel-version'];
|
|
||||||
}
|
var options: ExecOptions = {
|
||||||
|
listeners: {
|
||||||
static DotNetCoreIndexUrl =
|
stdout: (data: Buffer) => {
|
||||||
'https://dotnetcli.azureedge.net/dotnet/release-metadata/releases-index.json';
|
output += data.toString();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
export class DotnetCoreInstaller {
|
env: envVariables
|
||||||
private version: string;
|
};
|
||||||
private quality: QualityOptions;
|
|
||||||
|
resultCode = await exec.exec(
|
||||||
static {
|
`"${powershellPath}"`,
|
||||||
const installationDirectoryWindows = path.join(
|
[
|
||||||
process.env['PROGRAMFILES'] + '',
|
'-NoLogo',
|
||||||
'dotnet'
|
'-Sta',
|
||||||
);
|
'-NoProfile',
|
||||||
const installationDirectoryLinux = '/usr/share/dotnet';
|
'-NonInteractive',
|
||||||
const installationDirectoryMac = path.join(
|
'-ExecutionPolicy',
|
||||||
process.env['HOME'] + '',
|
'Unrestricted',
|
||||||
'.dotnet'
|
'-Command',
|
||||||
);
|
command
|
||||||
const dotnetInstallDir: string | undefined =
|
],
|
||||||
process.env['DOTNET_INSTALL_DIR'];
|
options
|
||||||
if (dotnetInstallDir) {
|
);
|
||||||
process.env['DOTNET_INSTALL_DIR'] =
|
} else {
|
||||||
this.convertInstallPathToAbsolute(dotnetInstallDir);
|
let escapedScript = path
|
||||||
} else {
|
.join(__dirname, '..', 'externals', 'install-dotnet.sh')
|
||||||
if (IS_WINDOWS) {
|
.replace(/'/g, "''");
|
||||||
process.env['DOTNET_INSTALL_DIR'] = installationDirectoryWindows;
|
chmodSync(escapedScript, '777');
|
||||||
} else {
|
|
||||||
process.env['DOTNET_INSTALL_DIR'] = IS_LINUX
|
const scriptPath = await io.which(escapedScript, true);
|
||||||
? installationDirectoryLinux
|
|
||||||
: installationDirectoryMac;
|
let scriptArguments: string[] = [];
|
||||||
}
|
if (calculatedVersion) {
|
||||||
}
|
scriptArguments.push('--version', calculatedVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(version: string, quality: QualityOptions) {
|
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
|
||||||
this.version = version;
|
resultCode = await exec.exec(`"${scriptPath}"`, scriptArguments, {
|
||||||
this.quality = quality;
|
listeners: {
|
||||||
}
|
stdout: (data: Buffer) => {
|
||||||
|
output += data.toString();
|
||||||
private static convertInstallPathToAbsolute(installDir: string): string {
|
}
|
||||||
let transformedPath;
|
},
|
||||||
if (path.isAbsolute(installDir)) {
|
env: envVariables
|
||||||
transformedPath = installDir;
|
});
|
||||||
} else {
|
}
|
||||||
transformedPath = installDir.startsWith('~')
|
|
||||||
? path.join(os.homedir(), installDir.slice(1))
|
if (resultCode != 0) {
|
||||||
: (transformedPath = path.join(process.cwd(), installDir));
|
throw new Error(`Failed to install dotnet ${resultCode}. ${output}`);
|
||||||
}
|
}
|
||||||
return path.normalize(transformedPath);
|
}
|
||||||
}
|
|
||||||
|
static addToPath() {
|
||||||
static addToPath() {
|
if (process.env['DOTNET_INSTALL_DIR']) {
|
||||||
core.addPath(process.env['DOTNET_INSTALL_DIR']!);
|
core.addPath(process.env['DOTNET_INSTALL_DIR']);
|
||||||
core.exportVariable('DOTNET_ROOT', process.env['DOTNET_INSTALL_DIR']);
|
core.exportVariable('DOTNET_ROOT', process.env['DOTNET_INSTALL_DIR']);
|
||||||
}
|
} else {
|
||||||
|
if (IS_WINDOWS) {
|
||||||
private setQuality(
|
// This is the default set in install-dotnet.ps1
|
||||||
dotnetVersion: DotnetVersion,
|
core.addPath(
|
||||||
scriptArguments: string[]
|
path.join(process.env['LocalAppData'] + '', 'Microsoft', 'dotnet')
|
||||||
): void {
|
);
|
||||||
const option = IS_WINDOWS ? '-Quality' : '--quality';
|
core.exportVariable(
|
||||||
if (dotnetVersion.qualityFlag) {
|
'DOTNET_ROOT',
|
||||||
scriptArguments.push(option, this.quality);
|
path.join(process.env['LocalAppData'] + '', 'Microsoft', 'dotnet')
|
||||||
} else {
|
);
|
||||||
core.warning(
|
} else {
|
||||||
`The 'dotnet-quality' input can be used only with .NET SDK version in A.B, A.B.x, A, A.x and A.B.Cxx formats where the major tag is higher than 5. You specified: ${this.version}. 'dotnet-quality' input is ignored.`
|
// This is the default set in install-dotnet.sh
|
||||||
);
|
core.addPath(path.join(process.env['HOME'] + '', '.dotnet'));
|
||||||
}
|
core.exportVariable(
|
||||||
}
|
'DOTNET_ROOT',
|
||||||
|
path.join(process.env['HOME'] + '', '.dotnet')
|
||||||
public async installDotnet(): Promise<string | null> {
|
);
|
||||||
const windowsDefaultOptions = [
|
}
|
||||||
'-NoLogo',
|
}
|
||||||
'-Sta',
|
|
||||||
'-NoProfile',
|
console.log(process.env['PATH']);
|
||||||
'-NonInteractive',
|
}
|
||||||
'-ExecutionPolicy',
|
|
||||||
'Unrestricted',
|
// versionInfo - versionInfo of the SDK/Runtime
|
||||||
'-Command'
|
async resolveVersion(versionInfo: DotNetVersionInfo): Promise<string> {
|
||||||
];
|
if (versionInfo.isExactVersion()) {
|
||||||
const scriptName = IS_WINDOWS ? 'install-dotnet.ps1' : 'install-dotnet.sh';
|
return versionInfo.version();
|
||||||
const escapedScript = path
|
}
|
||||||
.join(__dirname, '..', 'externals', scriptName)
|
|
||||||
.replace(/'/g, "''");
|
const httpClient = new hc.HttpClient('actions/setup-dotnet', [], {
|
||||||
let scriptArguments: string[];
|
allowRetries: true,
|
||||||
let scriptPath = '';
|
maxRetries: 3
|
||||||
|
});
|
||||||
const versionResolver = new DotnetVersionResolver(this.version);
|
|
||||||
const dotnetVersion = await versionResolver.createDotNetVersion();
|
const releasesJsonUrl: string = await this.getReleasesJsonUrl(
|
||||||
|
httpClient,
|
||||||
if (IS_WINDOWS) {
|
versionInfo.version().split('.')
|
||||||
scriptArguments = ['&', `'${escapedScript}'`];
|
);
|
||||||
|
|
||||||
if (dotnetVersion.type) {
|
const releasesResponse = await httpClient.getJson<any>(releasesJsonUrl);
|
||||||
scriptArguments.push(dotnetVersion.type, dotnetVersion.value);
|
const releasesResult = releasesResponse.result || {};
|
||||||
}
|
let releasesInfo: any[] = releasesResult['releases'];
|
||||||
|
releasesInfo = releasesInfo.filter((releaseInfo: any) => {
|
||||||
if (this.quality) {
|
return (
|
||||||
this.setQuality(dotnetVersion, scriptArguments);
|
semver.satisfies(releaseInfo['sdk']['version'], versionInfo.version(), {
|
||||||
}
|
includePrerelease: this.includePrerelease
|
||||||
|
}) ||
|
||||||
if (process.env['https_proxy'] != null) {
|
semver.satisfies(
|
||||||
scriptArguments.push(`-ProxyAddress ${process.env['https_proxy']}`);
|
releaseInfo['sdk']['version-display'],
|
||||||
}
|
versionInfo.version(),
|
||||||
// This is not currently an option
|
{
|
||||||
if (process.env['no_proxy'] != null) {
|
includePrerelease: this.includePrerelease
|
||||||
scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`);
|
}
|
||||||
}
|
)
|
||||||
|
);
|
||||||
scriptPath =
|
});
|
||||||
(await io.which('pwsh', false)) || (await io.which('powershell', true));
|
|
||||||
scriptArguments = windowsDefaultOptions.concat(scriptArguments);
|
// Exclude versions that are newer than the latest if using not exact
|
||||||
} else {
|
let latestSdk: string = releasesResult['latest-sdk'];
|
||||||
chmodSync(escapedScript, '777');
|
|
||||||
scriptPath = await io.which(escapedScript, true);
|
releasesInfo = releasesInfo.filter((releaseInfo: any) =>
|
||||||
scriptArguments = [];
|
semver.lte(releaseInfo['sdk']['version'], latestSdk, {
|
||||||
|
includePrerelease: this.includePrerelease
|
||||||
if (dotnetVersion.type) {
|
})
|
||||||
scriptArguments.push(dotnetVersion.type, dotnetVersion.value);
|
);
|
||||||
}
|
|
||||||
|
// Sort for latest version
|
||||||
if (this.quality) {
|
releasesInfo = releasesInfo.sort((a, b) =>
|
||||||
this.setQuality(dotnetVersion, scriptArguments);
|
semver.rcompare(a['sdk']['version'], b['sdk']['version'], {
|
||||||
}
|
includePrerelease: this.includePrerelease
|
||||||
}
|
})
|
||||||
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
|
);
|
||||||
const getExecOutputOptions = {
|
|
||||||
ignoreReturnCode: true,
|
if (releasesInfo.length == 0) {
|
||||||
env: process.env as {string: string}
|
throw new Error(
|
||||||
};
|
`Could not find dotnet core version. Please ensure that specified version ${versionInfo.inputVersion} is valid.`
|
||||||
const {exitCode, stdout, stderr} = await exec.getExecOutput(
|
);
|
||||||
`"${scriptPath}"`,
|
}
|
||||||
scriptArguments,
|
|
||||||
getExecOutputOptions
|
let release = releasesInfo[0];
|
||||||
);
|
return release['sdk']['version'];
|
||||||
if (exitCode) {
|
}
|
||||||
throw new Error(
|
|
||||||
`Failed to install dotnet, exit code: ${exitCode}. ${stderr}`
|
private async getReleasesJsonUrl(
|
||||||
);
|
httpClient: hc.HttpClient,
|
||||||
}
|
versionParts: string[]
|
||||||
|
): Promise<string> {
|
||||||
return this.parseInstalledVersion(stdout);
|
const response = await httpClient.getJson<any>(DotNetCoreIndexUrl);
|
||||||
}
|
const result = response.result || {};
|
||||||
|
let releasesInfo: any[] = result['releases-index'];
|
||||||
private parseInstalledVersion(stdout: string): string | null {
|
|
||||||
const regex = /(?<version>\d+\.\d+\.\d+[a-z0-9._-]*)/gm;
|
releasesInfo = releasesInfo.filter((info: any) => {
|
||||||
const matchedResult = regex.exec(stdout);
|
// channel-version is the first 2 elements of the version (e.g. 2.1), filter out versions that don't match 2.1.x.
|
||||||
|
const sdkParts: string[] = info['channel-version'].split('.');
|
||||||
if (!matchedResult) {
|
if (
|
||||||
core.warning(`Failed to parse installed by the script version of .NET`);
|
versionParts.length >= 2 &&
|
||||||
return null;
|
!(versionParts[1] == 'x' || versionParts[1] == '*')
|
||||||
}
|
) {
|
||||||
return matchedResult.groups!.version;
|
return versionParts[0] == sdkParts[0] && versionParts[1] == sdkParts[1];
|
||||||
}
|
}
|
||||||
}
|
return versionParts[0] == sdkParts[0];
|
||||||
|
});
|
||||||
|
|
||||||
|
if (releasesInfo.length === 0) {
|
||||||
|
throw new Error(
|
||||||
|
`Could not find info for version ${versionParts.join(
|
||||||
|
'.'
|
||||||
|
)} at ${DotNetCoreIndexUrl}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const releaseInfo = releasesInfo[0];
|
||||||
|
if (releaseInfo['support-phase'] === 'eol') {
|
||||||
|
core.warning(
|
||||||
|
`${releaseInfo['product']} ${releaseInfo['channel-version']} is no longer supported and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the .NET support policy.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return releaseInfo['releases.json'];
|
||||||
|
}
|
||||||
|
|
||||||
|
private version: string;
|
||||||
|
private includePrerelease: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const DotNetCoreIndexUrl: string =
|
||||||
|
'https://builds.dotnet.microsoft.com/dotnet/release-metadata/releases-index.json';
|
||||||
|
|||||||
@@ -1,20 +1,9 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import {DotnetCoreInstaller} from './installer';
|
import * as installer from './installer';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import path from 'path';
|
import * as path from 'path';
|
||||||
import semver from 'semver';
|
|
||||||
import * as auth from './authutil';
|
import * as auth from './authutil';
|
||||||
|
|
||||||
const qualityOptions = [
|
|
||||||
'daily',
|
|
||||||
'signed',
|
|
||||||
'validated',
|
|
||||||
'preview',
|
|
||||||
'ga'
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
export type QualityOptions = (typeof qualityOptions)[number];
|
|
||||||
|
|
||||||
export async function run() {
|
export async function run() {
|
||||||
try {
|
try {
|
||||||
//
|
//
|
||||||
@@ -26,12 +15,11 @@ export async function run() {
|
|||||||
// If a valid version still can't be identified, nothing will be installed.
|
// If a valid version still can't be identified, nothing will be installed.
|
||||||
// Proxy, auth, (etc) are still set up, even if no version is identified
|
// Proxy, auth, (etc) are still set up, even if no version is identified
|
||||||
//
|
//
|
||||||
const versions = core.getMultilineInput('dotnet-version');
|
let versions = core.getMultilineInput('dotnet-version');
|
||||||
const installedDotnetVersions: (string | null)[] = [];
|
|
||||||
|
|
||||||
const globalJsonFileInput = core.getInput('global-json-file');
|
const globalJsonFileInput = core.getInput('global-json-file');
|
||||||
if (globalJsonFileInput) {
|
if (globalJsonFileInput) {
|
||||||
const globalJsonPath = path.resolve(process.cwd(), globalJsonFileInput);
|
const globalJsonPath = path.join(process.cwd(), globalJsonFileInput);
|
||||||
if (!fs.existsSync(globalJsonPath)) {
|
if (!fs.existsSync(globalJsonPath)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`The specified global.json file '${globalJsonFileInput}' does not exist`
|
`The specified global.json file '${globalJsonFileInput}' does not exist`
|
||||||
@@ -46,30 +34,22 @@ export async function run() {
|
|||||||
const globalJsonPath = path.join(process.cwd(), 'global.json');
|
const globalJsonPath = path.join(process.cwd(), 'global.json');
|
||||||
if (fs.existsSync(globalJsonPath)) {
|
if (fs.existsSync(globalJsonPath)) {
|
||||||
versions.push(getVersionFromGlobalJson(globalJsonPath));
|
versions.push(getVersionFromGlobalJson(globalJsonPath));
|
||||||
} else {
|
|
||||||
core.info(
|
|
||||||
`The global.json wasn't found in the root directory. No .NET version will be installed.`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (versions.length) {
|
if (versions.length) {
|
||||||
const quality = core.getInput('dotnet-quality') as QualityOptions;
|
const includePrerelease: boolean = core.getBooleanInput(
|
||||||
|
'include-prerelease'
|
||||||
if (quality && !qualityOptions.includes(quality)) {
|
);
|
||||||
throw new Error(
|
let dotnetInstaller!: installer.DotnetCoreInstaller;
|
||||||
`Value '${quality}' is not supported for the 'dotnet-quality' option. Supported values are: daily, signed, validated, preview, ga.`
|
for (const version of new Set<string>(versions)) {
|
||||||
|
dotnetInstaller = new installer.DotnetCoreInstaller(
|
||||||
|
version,
|
||||||
|
includePrerelease
|
||||||
);
|
);
|
||||||
|
await dotnetInstaller.installDotnet();
|
||||||
}
|
}
|
||||||
|
installer.DotnetCoreInstaller.addToPath();
|
||||||
let dotnetInstaller: DotnetCoreInstaller;
|
|
||||||
const uniqueVersions = new Set<string>(versions);
|
|
||||||
for (const version of uniqueVersions) {
|
|
||||||
dotnetInstaller = new DotnetCoreInstaller(version, quality);
|
|
||||||
const installedVersion = await dotnetInstaller.installDotnet();
|
|
||||||
installedDotnetVersions.push(installedVersion);
|
|
||||||
}
|
|
||||||
DotnetCoreInstaller.addToPath();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const sourceUrl: string = core.getInput('source-url');
|
const sourceUrl: string = core.getInput('source-url');
|
||||||
@@ -78,17 +58,15 @@ export async function run() {
|
|||||||
auth.configAuthentication(sourceUrl, configFile);
|
auth.configAuthentication(sourceUrl, configFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
outputInstalledVersion(installedDotnetVersions, globalJsonFileInput);
|
|
||||||
|
|
||||||
const matchersPath = path.join(__dirname, '..', '.github');
|
const matchersPath = path.join(__dirname, '..', '.github');
|
||||||
core.info(`##[add-matcher]${path.join(matchersPath, 'csc.json')}`);
|
console.log(`##[add-matcher]${path.join(matchersPath, 'csc.json')}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getVersionFromGlobalJson(globalJsonPath: string): string {
|
function getVersionFromGlobalJson(globalJsonPath: string): string {
|
||||||
let version = '';
|
let version: string = '';
|
||||||
const globalJson = JSON.parse(
|
const globalJson = JSON.parse(
|
||||||
// .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649
|
// .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649
|
||||||
fs.readFileSync(globalJsonPath, {encoding: 'utf8'}).trim()
|
fs.readFileSync(globalJsonPath, {encoding: 'utf8'}).trim()
|
||||||
@@ -104,37 +82,4 @@ function getVersionFromGlobalJson(globalJsonPath: string): string {
|
|||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
function outputInstalledVersion(
|
|
||||||
installedVersions: (string | null)[],
|
|
||||||
globalJsonFileInput: string
|
|
||||||
): void {
|
|
||||||
if (!installedVersions.length) {
|
|
||||||
core.info(`The 'dotnet-version' output will not be set.`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (installedVersions.includes(null)) {
|
|
||||||
core.warning(
|
|
||||||
`Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.`
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (globalJsonFileInput) {
|
|
||||||
const versionToOutput = installedVersions.at(-1); // .NET SDK version parsed from the global.json file is installed last
|
|
||||||
core.setOutput('dotnet-version', versionToOutput);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const versionToOutput = semver.maxSatisfying(
|
|
||||||
installedVersions as string[],
|
|
||||||
'*',
|
|
||||||
{
|
|
||||||
includePrerelease: true
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
core.setOutput('dotnet-version', versionToOutput);
|
|
||||||
}
|
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
export const IS_WINDOWS = process.platform === 'win32';
|
|
||||||
export const IS_LINUX = process.platform === 'linux';
|
|
||||||
@@ -35,7 +35,6 @@
|
|||||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||||
|
|
||||||
/* Additional Checks */
|
/* Additional Checks */
|
||||||
"useUnknownInCatchVariables": false, /* Type catch clause variables as 'unknown' instead of 'any'. */
|
|
||||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||||
@@ -49,8 +48,7 @@
|
|||||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||||
// "types": [], /* Type declaration files to be included in compilation. */
|
// "types": [], /* Type declaration files to be included in compilation. */
|
||||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||||
"resolveJsonModule": true, /* Allows importing modules with a '.json' extension, which is a common practice in node projects. */
|
|
||||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user