Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 0 additions & 63 deletions .github/workflows/build_binaries.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

steps:
- name: Checkout Repository
uses: actions/checkout@v4
uses: actions/checkout@v6

- name: Set Up Go Environment
uses: actions/setup-go@v5
Expand Down
88 changes: 88 additions & 0 deletions .github/workflows/release-binaries.yml
Comment thread
MykytaPimonovTD marked this conversation as resolved.
Comment thread
Vladyslav-Kuksiuk marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Releases binaries when application version changes.
name: Release Binaries
Comment thread
Vladyslav-Kuksiuk marked this conversation as resolved.

on:
push:
branches: [ master ]

permissions:
contents: write

# Keep only the newest release run for the same ref. This avoids competing
# release attempts when several pushes land close together.
concurrency:
group: release-binaries-${{ github.ref }}
cancel-in-progress: true

jobs:

release:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- name: Checkout Repository
uses: actions/checkout@v6
with:
fetch-depth: 0

# Use the same Go version as the project, declared in go.mod.
- name: Set Up Go Environment
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

# Reads the app version from the `VERSION` file.
# It must be a plain MAJOR.MINOR.PATCH value, such as 1.2.3.
- name: Read Version
id: version
shell: bash
run: |
version="$(< VERSION)"
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Version must use MAJOR.MINOR.PATCH format, found: $version" >&2
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "tag=v$version" >> "$GITHUB_OUTPUT"

# Compares the release version with current app version.
# If current app version already exist in release, emits a warning, but flow counts as passed.
- name: Check Release Version
id: release
shell: bash
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ steps.version.outputs.tag }}
run: |
if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then
echo "::warning title=Release already exists::Release $RELEASE_TAG already exists. Bump VERSION to publish a new release."
echo "publish=false" >> "$GITHUB_OUTPUT"
else
echo "publish=true" >> "$GITHUB_OUTPUT"
fi

# Build binaries only for new releases.
- name: Build Binaries
if: steps.release.outputs.publish == 'true'
shell: bash
run: |
mkdir -p dist
GOOS=windows GOARCH=amd64 go build -trimpath -o dist/embed-code-windows.exe main.go

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's create bash script for it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need separate Bash script files for such tiny scripts of only 4–7 lines.

GOOS=linux GOARCH=amd64 go build -trimpath -o dist/embed-code-linux main.go
GOOS=darwin GOARCH=amd64 go build -trimpath -o dist/embed-code-macos main.go
chmod +x dist/embed-code-linux dist/embed-code-macos

# Create the release for the current commit and attach all generated binaries.
- name: Publish GitHub Release
if: steps.release.outputs.publish == 'true'
shell: bash
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ steps.version.outputs.tag }}
run: |
release_notes="$(printf 'Embed Code %s\n\nThis release contains pre-built Embed Code binaries for macOS, Linux, and Windows.' "$RELEASE_TAG")"
gh release create "$RELEASE_TAG" dist/* \
--target "$GITHUB_SHA" \
--title "embed-code $RELEASE_TAG" \
--notes "$release_notes"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ coverage.out

# Built 'main' application
main
embed-code
embed-code.exe
1 change: 0 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ agent operating policy and repository-wide rules.
## Repository Hygiene

- Do not revert unrelated user changes.
- Do not edit generated binaries under `bin/` unless explicitly requested.
- Do not add temporary repo files, local binaries, IDE metadata, coverage
output, or build artifacts to the intended change set.
- Keep changes narrowly scoped and make unrelated cleanup a separate task.
14 changes: 5 additions & 9 deletions PROJECT.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,9 @@ This repository is configured with these GitHub workflows:

- `check`: runs linting, the normal Go test suite, and the showcase end-to-end
tests across supported platforms.
- `build_binaries`: builds binaries on pushes to `master`.
- `release-binaries`: reads `VERSION`, builds Linux, macOS, and Windows
binaries, and creates the matching GitHub Release on pushes to `master`.

`build_binaries` uses a deploy key instead of the default GitHub Actions bot so
it can push through branch protection. If it must be rotated:

1. Generate an SSH key pair for GitHub:
`ssh -i ~/.ssh/workflow_deploy_key -T git@github.com`.
2. Add `workflow_deploy_key.pub` as a GitHub deploy key with write access.
3. Add `workflow_deploy_key` as a repository secret named
`WORKFLOW_DEPLOY_KEY`.
The release tag is `v<version>` from `VERSION`. When the release already exists,
the workflow emits a warning and finishes successfully without rebuilding or
uploading binaries.
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,25 @@ failures, and runnable examples.

## Run

Use a prebuilt binary from [GitHub Releases][releases]:
Download the asset for your platform from [GitHub Releases][releases].

On Linux, for example:

```bash
./bin/embed-code-linux -mode=check -config-path=showcase/embedding/embed-code.yml
./embed-code-linux -mode=check -config-path=showcase/embedding/embed-code.yml
```

> It may be necessary to give the executable permission with `chmod +x` on Unix-like systems:
> ```bash
> chmod +x embed-code-linux
> ```

> Since binary file for macOS is not signed, it may be necessary
> to change its attributes to allow execution:
> ```bash
> xattr -d com.apple.quarantine embed-code-macos
> ```

Or run it with Go:

```bash
Expand All @@ -48,8 +61,7 @@ go build -trimpath -o embed-code main.go
```

This creates `embed-code` on Unix-like systems or `embed-code.exe` on Windows.
The `-trimpath` flag prevents local absolute paths from appearing in stack
traces.
The `-trimpath` flag prevents local absolute paths from appearing in stack traces.

## Development

Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.2.3
Binary file removed bin/embed-code-linux
Binary file not shown.
Binary file removed bin/embed-code-macos
Binary file not shown.
Binary file removed bin/embed-code-windows.exe
Binary file not shown.
15 changes: 10 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,23 @@
package main

import (
"embed-code/embed-code-go/cli"
"embed-code/embed-code-go/configuration"
"embed-code/embed-code-go/logging"
_ "embed"
"errors"
"fmt"
"log/slog"
"os"
"strings"

"embed-code/embed-code-go/cli"
"embed-code/embed-code-go/configuration"
"embed-code/embed-code-go/logging"
)

// Version of the embed-code application.
const Version = "1.2.2"
//go:embed VERSION
var versionFile string

// Version is the embed-code application version embedded from the VERSION file.
var Version = strings.TrimSpace(versionFile)

// The entry point for embed-code.
//
Expand Down
Loading