Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AraHaan committed Jul 22, 2021
0 parents commit 0d7e834
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 0 deletions.
104 changes: 104 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Els_kom

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# setup-latest-dotnet
A github action to install the latest daily build of the .NET SDK.

```yml

- uses: Elskom/setup-latest-dotnet@main
with:
# major version of the .NET SDK to look for the newest version on in the feeds.
version-major: '6'
# minor version of the .NET SDK to look for the newest version on in the feeds.
version-minor: '0'
```
21 changes: 21 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Setup latest .NET SDKs
author: Els_kom
description: Github Action to install the daily builds of the .NET SDK.

inputs:
version-major:
description: Major version of the .NET SDK to install.
required: false
default: '6'
version-minor:
description: Minor version of the .NET SDK to install.
required: true
default: '0'

runs:
using: node12
main: index.js

branding:
icon: download-cloud
color: blue
85 changes: 85 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const https = require("https"),
fs = require("fs")

class Action
{
constructor()
{
this.versionMajor = process.env.version-major
this.versionMinor = process.env.version-minor
}

_printErrorAndExit(msg)
{
console.log(`##[error]😭 ${msg}`)
throw new Error(msg)
}

_executeCommand(cmd, options)
{
const INPUT = cmd.split(" "), TOOL = INPUT[0], ARGS = INPUT.slice(1)
return spawnSync(TOOL, ARGS, options)
}

downloadInstallScript(url, dest)
{
return new Promise((resolve, reject) => {
const file = fs.createWriteStream(dest, { flags: "wx" })
const request = https.get(url, response => {
if (response.statusCode === 200) {
response.pipe(file)
} else {
file.close()
fs.unlink(dest, () => {}) // Delete temp file
this._printErrorAndExit(`Server responded with ${response.statusCode}: ${response.statusMessage}`)
}
})

request.on("error", err => {
file.close()
fs.unlink(dest, () => {}) // Delete temp file
this._printErrorAndExit(err.message)
})

file.on("finish", () => {
resolve()
})

file.on("error", err => {
file.close()
if (err.code === "EEXIST") {
this._printErrorAndExit("File already exists")
} else {
fs.unlink(dest, () => {}) // Delete temp file
this._printErrorAndExit(err.message)
}
})
})
}

run()
{
console.log('Downloading .NET Install script.')
if (process.platform === 'win32')
{
// Download install script first for Windows.
this.downloadInstallScript('https://raw.githubusercontent.com/dotnet/install-scripts/main/src/dotnet-install.ps1', './dotnet-install.ps1')
console.log('Download Complete.')

// Windows.
this._executeCommand(`./dotnet-install.ps1 -Channel ${this.versionMajor}.${this.versionMinor} -Quality daily`)
}
else
{
// Download install script first for Linux and MacOS.
this.downloadInstallScript('https://raw.githubusercontent.com/dotnet/install-scripts/main/src/dotnet-install.sh', './dotnet-install.sh')
console.log('Download Complete.')

// Linux and MacOS.
this._executeCommand(`./dotnet-install.sh --channel ${this.versionMajor}.${this.versionMinor} --quality daily`)
}
}
}

const action = new Action();
action.run()

0 comments on commit 0d7e834

Please sign in to comment.