generated from Templates/Dotnet_Library
ci: add initial implementation of update runner action, ref: A24-10
This commit is contained in:
parent
e03afad8e6
commit
8cb14caff1
32
.gitea/workflows/update_level_inputs.yml
Normal file
32
.gitea/workflows/update_level_inputs.yml
Normal file
@ -0,0 +1,32 @@
|
||||
name: Update Level Inputs
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
env:
|
||||
SKIP_MAKE_SETUP_CHECK: 'true'
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '15 8 1-25 12 *'
|
||||
|
||||
# Allows you to run this workflow manually from the Actions tab
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
run:
|
||||
needs: release
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up dotnet
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: '9.0.X'
|
||||
- name: Update inputs and publish
|
||||
env:
|
||||
SESSION_COOKIE: ${{ secrets.AOC_SESSION_COOKIE }}
|
||||
run: |
|
||||
dotnet run --project LevelInputUpdateRunner/LevelInputUpdateRunner.csproj
|
||||
git add ./LevelInputProvider/input/*
|
||||
git commit -m "feat(inputs): add current inputs, ref: NOISSUE"
|
||||
make release
|
15
LevelInputUpdateRunner/LevelInputUpdateRunner.csproj
Normal file
15
LevelInputUpdateRunner/LevelInputUpdateRunner.csproj
Normal file
@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommandLineParser" Version="2.9.1" />
|
||||
<PackageReference Include="AoCAPI" Version="2.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
87
LevelInputUpdateRunner/Program.cs
Normal file
87
LevelInputUpdateRunner/Program.cs
Normal file
@ -0,0 +1,87 @@
|
||||
using CommandLine;
|
||||
using AoC.API;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
const string levelFilePathTemplate = "{0}/inputs/{1}/{2}/input.txt";
|
||||
|
||||
// find git repo base path
|
||||
DirectoryInfo? gitParentDirectory = new FileInfo(
|
||||
Path.GetDirectoryName(Assembly.GetAssembly(typeof(Options)).Location)).Directory;
|
||||
|
||||
while(gitParentDirectory != null && !gitParentDirectory.ToString().EndsWith("LevelInputProvider"))
|
||||
{
|
||||
gitParentDirectory = gitParentDirectory?.Parent;
|
||||
}
|
||||
|
||||
string gitBasePath = gitParentDirectory?.ToString() + Path.DirectorySeparatorChar + "LevelInputProvider";
|
||||
|
||||
Parser.Default.ParseArguments<Options>(args)
|
||||
.WithParsed<Options>(o =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(o.Cookie))
|
||||
{
|
||||
var env_cookie = System.Environment.GetEnvironmentVariable("SESSION_COOKIE");
|
||||
if(string.IsNullOrEmpty(env_cookie))
|
||||
{
|
||||
throw new Exception("A session cookie must be provided!");
|
||||
}
|
||||
o.Cookie = env_cookie;
|
||||
}
|
||||
|
||||
EntryPoint(o);
|
||||
});
|
||||
|
||||
bool InputAlreadyExists(int year, int day)
|
||||
{
|
||||
return File.Exists(string.Format(levelFilePathTemplate, gitBasePath, year, day));
|
||||
}
|
||||
|
||||
void EnsureDirectoryExists(string filePath)
|
||||
{
|
||||
FileInfo fi = new FileInfo(filePath);
|
||||
if (!fi.Directory.Exists)
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(fi.DirectoryName);
|
||||
}
|
||||
}
|
||||
|
||||
void EntryPoint(Options o)
|
||||
{
|
||||
var currentYear = DateTime.Now.Year;
|
||||
var currentMonth = DateTime.Now.Month;
|
||||
var currentDay = DateTime.Now.Day;
|
||||
|
||||
if(currentMonth != 12)
|
||||
{
|
||||
throw new Exception("Tsk Tsk, it isn't even December yet!");
|
||||
}
|
||||
|
||||
for(int i = 1; i <= currentDay; i++)
|
||||
{
|
||||
Console.WriteLine("Attempt to get input " + i + " for year " + currentYear + "");
|
||||
if(InputAlreadyExists(currentYear, i))
|
||||
{
|
||||
Console.WriteLine("Input " + i + " already exists!");
|
||||
continue;
|
||||
}
|
||||
|
||||
var client = new Session(o.Cookie, currentYear, i);
|
||||
var inputTextTask = client.GetInputTextAsync();
|
||||
string inputText = inputTextTask.Result;
|
||||
var fileName = string.Format(levelFilePathTemplate, gitBasePath, currentYear, i);
|
||||
EnsureDirectoryExists(fileName);
|
||||
using(var sw = new StreamWriter(fileName))
|
||||
{
|
||||
sw.Write(inputText);
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("Finished input fetching!");
|
||||
}
|
||||
|
||||
public class Options
|
||||
{
|
||||
[Option('c', "cookie", Required = false, HelpText = "The AoC session cookie to use.")]
|
||||
public string Cookie { get; set; } = "";
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user