hoplik / Firehose-Finder

Однокнопочная программа с GUI для подбора программера (firehose) к определённым моделям телефонов на базе процессоров Qualcomm.
MIT License
73 stars 19 forks source link

some question about github-ci #40

Closed 8MiYile closed 2 months ago

8MiYile commented 2 months ago

https://github.com/8MiYile/Firehose-Finder/actions/runs/8763466905/job/24052378368 I tried to use GitHub's Actions to automatically compile the But I've encountered an incomprehensible error

Resource/bot.txt

What's this?

hoplik commented 2 months ago

What's this?

The github security policy provides a warning about the non-placement of passwords in the public domain. This file contains the password for accessing the telegram bot. Therefore, it is placed in a separate file and is forbidden to export. When creating a fork, you need to agree to one of two options: 1. Rem all functions related to sending data by the bot to the telegram channel; 2. Create your own channel in telegram, your bot, make it the channel administrator, fix the channel and bot id in the code (if you don't figure out where exactly, I'll tell you) and create a file bot.txt in Resources with an access password to control this bot to send data to the channel.

8MiYile commented 2 months ago

oh i just help you make auto build you can look my pull request i think you can use Action Secret to save telegram bot's pass

hoplik commented 2 months ago

auto build

Thank you. I'm building a project in Visual Studio. For your fork, in order for the build to work, you can create an empty bot.txt file by yourself (or with any content). The project will have to be assembled without errors, but then sending information to the telegram channel will not take place due to an incorrect password.

hoplik commented 2 months ago

i think you can use Action Secret to save telegram bot's pass

I've already broken my whole head. I don't understand how to access UserSecrets on GitHub from a local project via Visual Studio. I've already looked at a bunch of examples. using Microsoft.Extensions.Configuration; public partial class Formfhf : Form {
//Подтягиваем секреты private readonly static IConfiguration bottokenconfig = new ConfigurationBuilder() .AddUserSecrets<Formfhf>() .Build(); TelegramBotClient mybot = new TelegramBotClient(bottokenconfig["bottoken"]); } After such a code, the value is "null", and there should be a text string. This is what I added to the auto-assembler. - name: Build and Publish App run: msbuild FirehoseFinder.sln /p:Configuration=Release /p:DeployOnBuild=true /p:PublishProfile=FolderProfile env: bottoken: ${{ secrets.BOT }} Can you help me with this?

8MiYile commented 2 months ago

为什么不尝试使用类似如下Linux的指令呢 Why not try a command similar to the following linux

echo ${{ secret.TELEGRAM_BOT }} > resource/bot.txt

当然,这是个老方法,你的方法我还在研究 Of course, it's an old-fashioned way. I'm still working on yours

hoplik commented 2 months ago

为什么不尝试使用类似如下Linux的指令呢

Linux根本不适合这里。 自动汇编程序使用的工作正常,至少没有错误。 问题出在应用程序端。 当Visual Studio构建一个项目时,它应该从GitHub Secrets中获取信息,但在我看来,即使请求也不会去那里,因为结果为null。

8MiYile commented 2 months ago

I know, but I'm just saying, it's bot.txt, so before MSBuild, we'll run a string output to bot.txt and then execute it.

And if you're using the read environment variable, why isn't that the case?

Environment.GetEnvironmentVariable("TELEGRAM_BOT_TOKEN")`;
hoplik commented 2 months ago

why isn't that the case?

When implemented via UserSecrets, i generally didn't use bot.txt. Then there is simply no need for this, because the token lies elsewhere, on GitHub. I'll try to reach him through Environment, simply i didn`t see such release in examples.

8MiYile commented 2 months ago

If you want to read from environment variables instead of having Actions read from the secret and generate a file and then having the compilation environment read the file, then you can use the https://chat.openai.com/share/5301c332-db0d-4914-a482-58d884b3f21c I tried to ask ChatGPT and this is the answer he gave you, you can open it and see if it doesn't open, if it doesn't open I can translate what's in it for you.

hoplik commented 2 months ago

it doesn't open

Буфер обмена_04-24-2024_01

8MiYile commented 2 months ago

https://chat.openai.com/share/5301c332-db0d-4914-a482-58d884b3f21c

如何让MSBuild在编译C#的时候 自动把某个环境变量编译进常量内

你可以通过在项目文件(.csproj)中使用 元素来设置编译时的常量。你可以使用 DefineConstants 属性来定义常量,并在其中包含你想要的环境变量。

例如,假设你的环境变量名为 MY_ENV_VARIABLE,你可以像这样在项目文件中设置:

<PropertyGroup>
  <DefineConstants>$(DefineConstants);MY_ENV_VARIABLE</DefineConstants>
</PropertyGroup>

这样做会将 MY_ENV_VARIABLE 环境变量的值编译进你的 C# 代码中作为常量,你可以在代码中通过 #if MY_ENV_VARIABLE 来检查是否定义了这个常量。

如果你希望在编译时直接将环境变量的值作为字符串常量引入到代码中,你可以像这样使用

<PropertyGroup>
  <DefineConstants>$(DefineConstants);MY_ENV_VARIABLE="$(MY_ENV_VARIABLE)"</DefineConstants>
</PropertyGroup>

这样做会将环境变量的值作为字符串常量传递给编译器。

hoplik commented 2 months ago

我为这样的实验做了一个测试存储库。 我们可以去那里,因为到目前为止没有成功。 https://github.com/hoplik/duplotest

hoplik commented 2 months ago
Environment.GetEnvironmentVariable("TELEGRAM_BOT_TOKEN")`;

这个解决方案还没有工作。 我无法在本地构建时传递额外的参数。 输出了很多参数,但没有GH_TOKEN,因为我还不明白在本地构建项目时如何传递它。 #if GH_TOKEN try { string Text = string.Empty; IDictionary project = Environment.GetEnvironmentVariables(); foreach (DictionaryEntry property in project) { if (property.Key.ToString().Contains("T")) { Text += string.Format("Ключ {0} = значение {1}", property.Key, property.Value) + Environment.NewLine; } } MessageBox.Show(Text); } catch (Exception ex) { Text = "Ошибка: " + ex.Message; MessageBox.Show(Text); } #endif label1.Text = Settings.Default.sectok; } image

hoplik commented 2 months ago
<PropertyGroup>
  <DefineConstants>$(DefineConstants);MY_ENV_VARIABLE="$(MY_ENV_VARIABLE)"</DefineConstants>
</PropertyGroup>

这是一个很好的解决方案,但它也不起作用。 自动汇编程序将参数作为变量获取(这在日志中可见),但我无法检查可执行文件,因为它在GitHub.服务器上 image

在本地构建时,参数不能与值一起传递,即它仅作为布尔值在代码中起作用。 #if GH_TOKEN *** #endif 一般来说,我还没有找到解决方案。 我还在看书。 可能可以在局部装配期间将变量传递给AssemblyInfo。

hoplik commented 2 months ago
echo ${{ secret.TELEGRAM_BOT }} > resource/bot.txt

最后,这是必须完成的。 我想不出还有比这更漂亮的了。