Skip to content
This repository has been archived by the owner on Jul 9, 2023. It is now read-only.

Commit

Permalink
default branch to main
Browse files Browse the repository at this point in the history
closes #10
  • Loading branch information
andyshinn committed Apr 2, 2022
1 parent 2a6a2a7 commit e915bc9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -6,7 +6,7 @@ You can use the bot in the #bot channel of the WLED Disord server: https://disco

## Commands

There are two primary commands. If `version` is not specified it defaults to the current `master` branch:
There are two primary commands. If `version` is not specified it defaults to the current `main` branch:

### `./build builtin <environment> [version]`

Expand All @@ -18,7 +18,7 @@ The `builtin` command builds a firmware based on existing environments defined i

### `./build custom [version]`

The `custom` command builds a PlatformIO configuration snippet. This can help build firmware with specific supported usermods, custom pins, or other settings defined in macros. For example, the following will build a firmware for the QuinLED-Dig-Uno with temperature sensor usermod based the `master` branch:
The `custom` command builds a PlatformIO configuration snippet. This can help build firmware with specific supported usermods, custom pins, or other settings defined in macros. For example, the following will build a firmware for the QuinLED-Dig-Uno with temperature sensor usermod based the `main` branch:

```
./build custom
Expand Down
1 change: 1 addition & 0 deletions job.hcl.tpl
Expand Up @@ -98,6 +98,7 @@ job "wbld" {
env {
SENTRY_DSN = "${sentry_dsn}"
STORAGE_DIR = "/root/wbld"
DEFAULT_BRANCH = "main"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion wbld/bot.py
Expand Up @@ -10,6 +10,7 @@
TOKEN = os.getenv("DISCORD_TOKEN")
PING_URL = os.getenv("PING_URL")
PREFIXES = [os.getenv("DISCORD_PREFIX", "./")]
DEFAULT_BRANCH = os.getenv("DEFAULT_BRANCH", "main")


class Bot(commands.Bot):
Expand All @@ -32,7 +33,7 @@ async def on_ready(self):
if TOKEN:
if PING_URL:
bot.add_cog(Health(bot, PING_URL))
bot.add_cog(WbldCog(bot, BASE_URL))
bot.add_cog(WbldCog(bot, BASE_URL, DEFAULT_BRANCH))
bot.run(TOKEN)
else:
logger.error("Please set your DISCORD_TOKEN.")
23 changes: 14 additions & 9 deletions wbld/cogs/wbld.py
Expand Up @@ -32,19 +32,18 @@ def __init__(self, ctx: commands.Context, build: BuildModel, base_url: str, **kw
self.add_field(name="log", value=f"[combined.txt]({base_url}/data/{build.build_id}/combined.txt)")
else:
self.add_field(name="version", value=build.version)
self.add_field(
name="commit", value=f"[{build.sha1}](https://github.com/Aircoookie/WLED/commit/{build.sha1})"
)
self.add_field(name="commit", value=f"[{build.sha1}](https://github.com/Aircoookie/WLED/commit/{build.sha1})")


class WbldCog(commands.Cog, name="Builder"):
"""
Commands to build and work with WLED firmware.
"""

def __init__(self, bot, base_url: str):
def __init__(self, bot, base_url: str, default_branch: str):
self.bot = bot
self.base_url = base_url
self.default_branch = default_branch

async def _build_firmware(self, ctx: commands.Context, version, env_or_snippet, builder, clone=None):
try:
Expand All @@ -54,7 +53,7 @@ async def _build_firmware(self, ctx: commands.Context, version, env_or_snippet,

with builder(clone, env_or_snippet) as build:
await ctx.send(
f"Sure thing. Building env `{build.build.env}` as `{build.build.build_id}`. This will take a minute or two.",
f"Sure thing. Building env `{build.build.env}` as `{build.build.build_id}`. This will take a moment.",
embed=WbldEmbed(ctx, build.build, self.base_url),
)
build.build.author = ctx.author
Expand All @@ -66,12 +65,12 @@ async def _build_firmware(self, ctx: commands.Context, version, env_or_snippet,
await ctx.send(
embed=WbldEmbed(ctx, build.build, self.base_url),
file=dfile,
content=f"Good news, {ctx.author.mention}! Your build `{build.build.build_id}` for `{build.build.env}` has succeeded.",
content=f"Good news, {ctx.author.mention}! Your build `{build.build.build_id}` for `{build.build.env}` has succeeded.", # noqa: E501
)
else:
await ctx.send(
embed=WbldEmbed(ctx, build.build, self.base_url),
content=f"Sorry, {ctx.author.mention}. There was a problem building. See logs with: `{ctx.prefix}build log {build.build.build_id}`",
content=f"Sorry, {ctx.author.mention}. There was a problem building. See logs with: `{ctx.prefix}build log {build.build.build_id}`", # noqa: E501
)
logger.error(f"Error building firmware for `{build.build.env}` against `{version}`.")
except ReferenceException as error:
Expand Down Expand Up @@ -156,19 +155,22 @@ async def build(self, ctx):

@commands.max_concurrency(1, per=commands.BucketType.user)
@build.command()
async def builtin(self, ctx, env, version="master"):
async def builtin(self, ctx, env, version=None):
"""
Builds and returns a firmware file for an environment which already exists in the WLED PlatformIO configuration.
Example:
./build builtin d1_mini
"""
if not version:
version = self.default_branch

await self._build_firmware(ctx, version, env, Builder)

@commands.max_concurrency(1, per=commands.BucketType.user)
@build.command()
async def custom(self, ctx, version="master"):
async def custom(self, ctx, version=None):
"""
Builds and returns firmware for a custom configuration snippet that you provide.
Expand All @@ -188,6 +190,9 @@ async def custom(self, ctx, version="master"):
ESPAsyncUDP
"""

if not version:
version = self.default_branch

def check_author(author, channel):
def inner_check(message):
return message.author == author and message.channel == channel
Expand Down

0 comments on commit e915bc9

Please sign in to comment.