Skip to content

Commit 2cce4a6

Browse files
authored
Merge pull request #1 from Tilation/development
First release
2 parents 7a9e7df + 91153a4 commit 2cce4a6

File tree

8 files changed

+267
-1
lines changed

8 files changed

+267
-1
lines changed

.github/workflows/main.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: ROR
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
regex:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout
12+
uses: actions/[email protected]
13+
14+
- name: Regex On Repo
15+
id: regex
16+
uses: ./ # replace ver with version number
17+
with:
18+
github: ${{ github.repository }}
19+
ref: 'development'
20+
token: ${{ secrets.GITHUB_TOKEN }}
21+
regex: '`([^`\W]+)`'
22+
file: 'README.md'
23+
debug: true

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/.vs
2+
**/bin
3+
**/obj

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Set the base image as the .NET 6.0 SDK (this includes the runtime)
2+
FROM mcr.microsoft.com/dotnet/sdk:6.0 as build-env
3+
4+
# Copy everything and publish the release (publish implicitly restores and builds)
5+
WORKDIR /app
6+
COPY . ./
7+
RUN dotnet publish ./regex-on-repo.csproj -c Release -o out --no-self-contained
8+
9+
# Relayer the .NET SDK, anew with the build output
10+
FROM mcr.microsoft.com/dotnet/sdk:6.0
11+
COPY --from=build-env /app/out .
12+
ENTRYPOINT [ "dotnet", "/regex-on-repo.dll" ]

Program.cs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using CommandLine;
2+
using Octokit;
3+
using System;
4+
using System.Linq;
5+
using System.Text.RegularExpressions;
6+
using System.Threading.Tasks;
7+
using System.Collections.Generic;
8+
using System.Text;
9+
10+
namespace updater
11+
{
12+
partial class Program
13+
{
14+
class Options
15+
{
16+
[Option('g', "github",
17+
Required = true,
18+
HelpText = "The owner and repository name combination, example \"the-owner/and-the-repository\"")]
19+
public string Repo { get; set; }
20+
21+
[Option('r', "ref",
22+
Required = true,
23+
HelpText = "The reference to use for getting the file, can be a commit sha, branch name, or tag.")]
24+
public string Ref { get; set; }
25+
26+
[Option('t', "token",
27+
Required = true,
28+
HelpText = "A github token that has read access to the repository.")]
29+
public string GithubToken { get; set; }
30+
31+
[Option('x', "regex",
32+
Required = true,
33+
HelpText = "The regex match string")]
34+
public string RegexString { get; set; }
35+
36+
[Option('f', "file",
37+
Required = true,
38+
HelpText = "The relative directory to the file to read")]
39+
public string FilePath { get; set; }
40+
41+
[Option('d', "debug",
42+
Required = false,
43+
HelpText = "Debug output toggle")]
44+
public bool Debug { get; set; }
45+
}
46+
47+
static void Main(string[] args)
48+
{
49+
string outputFile = Environment.GetEnvironmentVariable("GITHUB_OUTPUT");
50+
51+
Options options = null;
52+
var options_result = CommandLine.Parser.Default.ParseArguments<Options>(args);
53+
if (options_result.Errors.Any()) throw new Exception("There are errors on the parameters.");
54+
else if (options_result.Value != null) options = options_result.Value;
55+
56+
Octokit.GitHubClient client = new GitHubClient(new ProductHeaderValue("regex-on-repo"));
57+
client.Credentials = new Credentials(options.GithubToken);
58+
59+
string _owner = options.Repo.Split('/')[0];
60+
string _repo = options.Repo.Split('/')[1];
61+
62+
Repository repo = Task.Run(() => client.Repository.Get(_owner, _repo)).Result;
63+
64+
Regex reg = new Regex(options.RegexString, RegexOptions.Compiled);
65+
66+
var content = Task.Run(() => client.Repository.Content.GetAllContentsByRef(repo.Id, options.FilePath, options.Ref)).Result[0];
67+
68+
var matches = reg.Matches(content.Content);
69+
70+
var sb = new StringBuilder();
71+
sb.AppendLine($"matches={matches.Count}");
72+
for(int i = 0; i < matches.Count; i++)
73+
{
74+
var match = matches[i];
75+
sb.AppendLine($"match_{i}_groups={match.Groups.Count}");
76+
for (int j = 0; j < match.Groups.Count; j++)
77+
{
78+
var group = match.Groups[j];
79+
sb.AppendLine($"match_{i}_group_{j}={group.Value}");
80+
}
81+
}
82+
if (options.Debug)
83+
{
84+
Console.WriteLine("DEBUG OUTPUT START");
85+
Console.WriteLine(sb.ToString());
86+
Console.WriteLine("DEBUG OUTPUT END");
87+
}
88+
File.WriteAllText(outputFile, sb.ToString());
89+
}
90+
}
91+
}

README.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,55 @@
1-
# regex-on-repo
1+
# Regex on Repo
2+
Or simply `ror` is a github action that does that.
3+
4+
This action only works on: `ubuntu` as it is a docker image.
5+
6+
### Example usage
7+
8+
```yaml
9+
on:
10+
push:
11+
branches:
12+
- 'main'
13+
14+
jobs:
15+
regex:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Regex On Repo
20+
id: regex
21+
uses: tilation/regex-on-repo@ver # replace ver with version number
22+
with:
23+
github: 'tilation/regex-on-repo' # can use ${{ github.repository }}
24+
ref: 'main' # can use ${{ github.ref }}
25+
token: ${{ secrets.GITHUB_TOKEN }}
26+
regex: '`([^`\W]+)`'
27+
file: 'README.MD'
28+
debug: true
29+
```
30+
31+
32+
### Parameters:
33+
34+
| Parameter name | Parameter Type |Required | Parameter description | Examples |
35+
|--- |--- |--- |--- |---|
36+
| `github` | string | true | The owner and repository that owns the file. | `"tilation/regex-on-repo"` |
37+
| `ref` | string | true | The reference to use for getting the file, can be a commit sha, branch name, or tag.| `"main"` or `"v1.5.3.2"` or a commit SHA |
38+
| `token` | string | true | A github token that has read access to the repository.| `${{ secrets.GITHUB_TOKEN }}` |
39+
| `regex` | string | true | The regex match string. | `"(\d+)\.(\d+)\.(\d+)\.(\d+)"` |
40+
| `file` | string | true | The directory to the file to read, relative to the root of the specified repository | `"README.MD"` |
41+
| `debug` | boolean | false | Debug output toggle, will output to the console all the matches with every group. `false` by default. | `true` |
42+
43+
44+
### Ouput Variables
45+
46+
The output is exported completely, matches and groups, and its like this:
47+
48+
I highly recommend playing arround with the `debug` flag set to true.
49+
50+
| Variable | Description | Example | Variable Type|
51+
|---|---|---|---|
52+
| matches | The amount of matches | | `int`
53+
| match_X_groups | The amount of groups found in the Xth match, where X is a number starting from 0 (inclusive) | match_0_groups | `int`
54+
| match_X_group_Y | The value for the Yth group of the Xth match, where X and Y are numbers starting from 0 (inclusive) | match_0_group_0 | `string`
55+

action.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: 'Read Assembly Version'
2+
description: 'Lee la verison del assembly'
3+
branding:
4+
icon: activity
5+
color: orange
6+
7+
inputs:
8+
github:
9+
description: 'The repository to search for, example "username/repo"'
10+
required: true
11+
ref:
12+
description: 'Commit sha, branch name, or tag.'
13+
required: true
14+
token:
15+
description: 'The github token for the action'
16+
required: true
17+
regex:
18+
description: 'The regex match string'
19+
required: true
20+
file:
21+
description: 'The relative directory to the file to read'
22+
required: true
23+
debug:
24+
description: 'Debug output variables'
25+
required: false
26+
27+
runs:
28+
using: 'docker'
29+
image: 'Dockerfile'
30+
args:
31+
- '-g'
32+
- ${{ inputs.github }}
33+
- '-r'
34+
- ${{ inputs.ref }}
35+
- '-t'
36+
- ${{ inputs.token }}
37+
- '-x'
38+
- ${{ inputs.regex }}
39+
- '-f'
40+
- ${{ inputs.file }}
41+
- '-d'
42+
- ${{ inputs.debug }}

regex-on-repo.csproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<RootNamespace>read_assembly_version</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="CommandLineParser" Version="2.9.1" />
13+
<PackageReference Include="Octokit" Version="4.0.2" />
14+
</ItemGroup>
15+
16+
</Project>

regex-on-repo.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.4.33205.214
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "regex-on-repo", "regex-on-repo.csproj", "{0E6AE295-8B66-4160-A549-6F4D9891E99E}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{0E6AE295-8B66-4160-A549-6F4D9891E99E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{0E6AE295-8B66-4160-A549-6F4D9891E99E}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{0E6AE295-8B66-4160-A549-6F4D9891E99E}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{0E6AE295-8B66-4160-A549-6F4D9891E99E}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {46CC96E6-A870-45C1-BD79-8E0F4BE45E3D}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)