Skip to content

Commit

Permalink
Add support for IGitHubPluginUpdates
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Mar 17, 2024
1 parent 3999196 commit f2209dd
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 13 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,23 @@ jobs:
# We prefer to use zip on OS X as 7z implementation on that OS doesn't handle file permissions (chmod +x)
if command -v zip >/dev/null; then
(
cd "${GITHUB_WORKSPACE}/out/plugin"
zip -q -r $zip_args "../${PLUGIN_NAME}.zip" .
cd "${GITHUB_WORKSPACE}/out/plugin/${PLUGIN_NAME}"
zip -q -r $zip_args "../../${PLUGIN_NAME}.zip" .
)
elif command -v 7z >/dev/null; then
7z a -bd -slp -tzip -mm=Deflate $seven_zip_args "out/${PLUGIN_NAME}.zip" "${GITHUB_WORKSPACE}/out/plugin/*"
7z a -bd -slp -tzip -mm=Deflate $seven_zip_args "out/${PLUGIN_NAME}.zip" "${GITHUB_WORKSPACE}/out/plugin/${PLUGIN_NAME}/*"
else
echo "ERROR: No supported zip tool!"
return 1
fi
;;
*)
if command -v 7z >/dev/null; then
7z a -bd -slp -tzip -mm=Deflate $seven_zip_args "out/${PLUGIN_NAME}.zip" "${GITHUB_WORKSPACE}/out/plugin/*"
7z a -bd -slp -tzip -mm=Deflate $seven_zip_args "out/${PLUGIN_NAME}.zip" "${GITHUB_WORKSPACE}/out/plugin/${PLUGIN_NAME}/*"
elif command -v zip >/dev/null; then
(
cd "${GITHUB_WORKSPACE}/out/plugin"
zip -q -r $zip_args "../${PLUGIN_NAME}.zip" .
cd "${GITHUB_WORKSPACE}/out/plugin/${PLUGIN_NAME}"
zip -q -r $zip_args "../../${PLUGIN_NAME}.zip" .
)
else
echo "ERROR: No supported zip tool!"
Expand Down Expand Up @@ -127,7 +127,7 @@ jobs:
}
# Create the final zip file
7z a -bd -slp -tzip -mm=Deflate $compressionArgs "out\$env:PLUGIN_NAME.zip" "$env:GITHUB_WORKSPACE\out\plugin\*"
7z a -bd -slp -tzip -mm=Deflate $compressionArgs "out\$env:PLUGIN_NAME.zip" "$env:GITHUB_WORKSPACE\out\plugin\$env:PLUGIN_NAME\*"
if ($LastExitCode -ne 0) {
throw "Last command failed."
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "ArchiSteamFarm"]
path = ArchiSteamFarm
url = https://github.com/JustArchiNET/ArchiSteamFarm.git
branch = 6.0.0.3
branch = 6.0.1.2
2 changes: 1 addition & 1 deletion ArchiSteamFarm
Submodule ArchiSteamFarm updated 266 files
3 changes: 2 additions & 1 deletion MyAwesomePlugin/MyAwesomePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ namespace MyAwesomePlugin;

#pragma warning disable CA1812 // ASF uses this class during runtime
[UsedImplicitly]
internal sealed class MyAwesomePlugin : IPlugin {
internal sealed class MyAwesomePlugin : IGitHubPluginUpdates {
public string Name => nameof(MyAwesomePlugin);
public string RepositoryName => "JustArchiNET/ASF-PluginTemplate";
public Version Version => typeof(MyAwesomePlugin).Assembly.GetName().Version ?? throw new InvalidOperationException(nameof(Version));

public Task OnLoaded() {
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ In theory, you don't need to do anything special further, just edit **[`MyAwesom
## What's included

- Sample `MyAwesomePlugin` ASF plugin project with `ArchiSteamFarm` reference in git subtree.
- Project structure supporting `IGitHubPluginUpdates` ASF interface, allowing for convenient plugin updates.
- Seamless hook into the ASF build process, which simplifies the project structure, as you effectively inherit the default settings official ASF projects are built with. Of course, free to override.
- GitHub actions CI script, which verifies whether your project is possible to build. You can easily enhance it with unit tests when/if you'll have any.
- GitHub actions publish script, heavily inspired by ASF build process. Publish script allows you to `git tag` and `git push` selected tag, while CI will build, pack, create release on GitHub and upload the resulting artifacts, automatically.
Expand All @@ -48,6 +49,7 @@ In theory, you don't need to do anything special further, just edit **[`MyAwesom

Here we list steps that are **not mandatory**, but worthy to consider after using this repo as a template. While we'd recommend to cover all of those, it's totally alright if you don't. We ordered those according to our recommended priority.

- If you want to use automatic plugin updates, ensure **[`RepositoryName`](https://github.com/JustArchiNET/ASF-PluginTemplate/blob/main/MyAwesomePlugin/MyAwesomePlugin.cs#L13)** property matches your target repo, this is covered by default in our **[`rename.sh`](https://github.com/JustArchiNET/ASF-PluginTemplate/blob/main/tools/rename.sh)** script. If you want to opt out of that feature, replace **[`IGitHubPluginUpdates`](https://github.com/JustArchiNET/ASF-PluginTemplate/blob/main/MyAwesomePlugin/MyAwesomePlugin.cs#L11)** interface back to its base `IPlugin` one, and remove **[`RepositoryName`](https://github.com/JustArchiNET/ASF-PluginTemplate/blob/main/MyAwesomePlugin/MyAwesomePlugin.cs#L13)** property instead.
- Choose license based on which you want to share your work. If you'd like to use the same one we do, so Apache 2.0, then you don't need to do anything as the plugin template comes with it. If you'd like to use different one, remove **[`LICENSE.txt`](https://github.com/JustArchiNET/ASF-PluginTemplate/blob/main/LICENSE.txt)** file and provide your own. If you've decided to use different license, it's probably also a good idea to update `PackageLicenseExpression` in **[`Directory.Build.props`](https://github.com/JustArchiNET/ASF-PluginTemplate/blob/main/Directory.Build.props#L17)**.
- Change this **[`README.md`](https://github.com/JustArchiNET/ASF-PluginTemplate/blob/main/README.md)** in any way you want to. You can check **[ASF's README](https://github.com/JustArchiNET/ArchiSteamFarm/blob/main/README.md)** for some inspiration. We recommend at least a short description of what your plugin can do. Updating `<Description>` in **[`Directory.Build.props`](https://github.com/JustArchiNET/ASF-PluginTemplate/blob/main/Directory.Build.props#L15)** also sounds like a good idea.
- Fill **[`SUPPORT.md`](https://github.com/JustArchiNET/ASF-PluginTemplate/blob/main/.github/SUPPORT.md)** file, so your users can learn where they can ask for help in regards to your plugin.
Expand Down Expand Up @@ -78,7 +80,7 @@ You might be interested in renaming `MyAwesomePlugin` project into the one that

If for any reason you'd prefer to rename manually, we've tried to keep the minimum amount of references, and we're listing here all of the places you should keep in mind:
- **[`MyAwesomePlugin.csproj`](https://github.com/JustArchiNET/ASF-PluginTemplate/blob/main/MyAwesomePlugin/MyAwesomePlugin.csproj)**, renaming should be enough.
- **[`MyAwesomePlugin.cs`](https://github.com/JustArchiNET/ASF-PluginTemplate/blob/main/MyAwesomePlugin/MyAwesomePlugin.cs#L6-L16)**, along with the update of `MyAwesomePlugin` class name (and included references to it).
- **[`MyAwesomePlugin.cs`](https://github.com/JustArchiNET/ASF-PluginTemplate/blob/main/MyAwesomePlugin/MyAwesomePlugin.cs#L7-L14)**, rename along with `RepositoryName` property, `MyAwesomePlugin` class name and included references to it.
- **[`MyAwesomePlugin`](https://github.com/JustArchiNET/ASF-PluginTemplate/tree/main/MyAwesomePlugin)** directory, which holds above files.
- **[`MyAwesomePlugin.sln`](https://github.com/JustArchiNET/ASF-PluginTemplate/blob/main/MyAwesomePlugin.sln#L6)**, along with the update of `MyAwesomePlugin` reference in the `sln` file.
- **[`MyAwesomePlugin.sln.DotSettings`](https://github.com/JustArchiNET/ASF-PluginTemplate/blob/main/MyAwesomePlugin.sln.DotSettings)**, renaming to match the `sln` file above should be enough.
Expand Down
44 changes: 42 additions & 2 deletions tools/rename.sh
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,46 @@ else
from_plugin_name="$(GET_INPUT_STRING "OK, from what plugin name you want to rename?" "MyAwesomePlugin")"
fi

default_github_repo="JustArchiNET/ASF-PluginTemplate"
default_github_username="JustArchi"

if command -v git >/dev/null; then
git_potential_username="$(git config --get remote.origin.url | sed 's/https:\/\/github\.com\///g' | cut -d '/' -f 1)"
git_potential_repo="$(git config --get remote.origin.url | sed 's/https:\/\/github\.com\///g' | sed 's/\.git//g')"

if [ -n "$git_potential_repo" ]; then
default_github_repo="$git_potential_repo"
fi

git_potential_username="$(echo "$git_potential_repo" | cut -d '/' -f 1)"

if [ -n "$git_potential_username" ]; then
default_github_username="$git_potential_username"
fi
fi

from_github_repo=""

if [ -f "../${from_plugin_name}/${from_plugin_name}.cs" ]; then
from_github_repo="$(grep -F "public string RepositoryName => " "../${from_plugin_name}/${from_plugin_name}.cs" | cut -d '"' -f 2)"

if [ -n "$from_github_repo" ]; then
INFO "Detected current GitHub repo: ${from_github_repo}"
else
WARN "Could not detect GitHub repo from ${from_plugin_name}/${from_plugin_name}.cs, have you removed RepositoryName property?"
fi
else
WARN "Couldn't find ${from_plugin_name}/${from_plugin_name}.cs, have you changed core project structure?"
fi

if [ -z "$from_github_repo" ]; then
if ! GET_INPUT_BOOL "This warning is not fatal, are you sure you want to continue?" "Y"; then
INFO "OK, as you wish!"
exit 0
fi

from_github_repo="$(GET_INPUT_STRING "OK, from what GitHub repository you want to rename?" "$default_github_repo")"
fi

from_github_username=""

if [ -f "../.github/renovate.json5" ]; then
Expand All @@ -205,15 +235,25 @@ if [ -z "$from_github_username" ]; then
fi

to_plugin_name="$(GET_INPUT_STRING "Please type target plugin name that you want to use, we recommend PascalCase" "MyAwesomePlugin")"
to_github_repo="$(GET_INPUT_STRING "Please type your GitHub repo" "$default_github_repo")"
to_github_username="$(GET_INPUT_STRING "Please type your GitHub username" "$default_github_username")"

if ! GET_INPUT_BOOL "Confirm rename: ${from_plugin_name} -> ${to_plugin_name} and ${from_github_username} -> ${to_github_username}:" "Y"; then
if ! GET_INPUT_BOOL "Confirm rename: ${from_plugin_name} -> ${to_plugin_name}, ${from_github_repo} -> ${to_github_repo} and ${from_github_username} -> ${to_github_username}:" "Y"; then
INFO "OK, as you wish!"
exit 0
fi

INFO "Please wait..."

if [ "$from_github_repo" != "$to_github_repo" ]; then
if [ -f "../${from_plugin_name}/${from_plugin_name}.cs" ]; then
INFO "Processing ${from_plugin_name}/${from_plugin_name}.cs..."
SED_REPLACE_FILE "${from_github_repo}" "${to_github_repo}" "../${from_plugin_name}/${from_plugin_name}.cs"
else
WARN "Couldn't find ${from_plugin_name}/${from_plugin_name}.cs, moving on..."
fi
fi

if [ "$from_github_username" != "$to_github_username" ]; then
if [ -f "../.github/renovate.json5" ]; then
INFO "Processing .github/renovate.json5..."
Expand Down

0 comments on commit f2209dd

Please sign in to comment.