From 7f3aa01bd5a4b24d4d21e6df4535cac09af42101 Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Mon, 6 Jan 2025 14:00:11 -0500 Subject: [PATCH] feature/1220 origin handle exists method (#1243) * feat: add docs and CI workflow for publishing to onsonr.dev * (refactor): Move hway,motr executables to their own repos * feat: simplify devnet and testnet configurations * refactor: update import path for didcrypto package * docs(networks): Add README with project overview, architecture, and community links * refactor: Move network configurations to deploy directory * build: update golang version to 1.23 * refactor: move logger interface to appropriate package * refactor: Move devnet configuration to networks/devnet * chore: improve release process with date variable * (chore): Move Crypto Library * refactor: improve code structure and readability in DID module * feat: integrate Trunk CI checks * ci: optimize CI workflow by removing redundant build jobs * feat: integrate Trunk CI checks, simplify devnet and testnet configurations, add docs and CI for onsonr.dev publishing, automate releases using Taskfile and GitHub Actions, and add Reddit release notification * ci: Trigger release validation on pull requests * ci: Migrate GoReleaser configuration to Makefiles * chore: update CI workflow permissions and rename job * refactor: remove unnecessary docker push steps from release process * feat: automate release process using Taskfile and GitHub Actions * fix: change shebang from bash to sh * chore: update setup script shebang to bash * chore: remove unnecessary setup-env step from release process * test: improve test descriptions and naming for clarity * refactor: rename workflow files for clarity * refactor: rename post-merge workflow file * refactor: Move race and coverage tests to separate workflow * refactor: simplify merge group trigger * chore: prevent accidental release overwriting of existing tags * test: rename GoReleaser Dry Run step to GoReleaser Test * fix: correct GitHub Actions workflow for version bumping * fix: Correct tag validation in CI workflow * refactor: simplify GitHub Actions workflow for version checking * test: replace version check with make command * chore: update setup-python action to v5 * test: rename workflow job and remove unnecessary steps * feat: enable workflow on merge group events --------- Signed-off-by: Prad Nukala Co-authored-by: Darp Alakun --- .cz.toml | 2 +- .../workflows/{checks.yml => check-pr.yml} | 64 ++++------------- .github/workflows/merge-group.yml | 68 +++++++++++++++++++ .../workflows/{merge.yml => merge-post.yml} | 4 +- .../{publish.yml => new-release.yml} | 8 +-- .../workflows/{release.yml => new-tag.yml} | 4 +- .goreleaser.yaml | 4 -- Makefile | 2 + scripts/setup_env.sh | 54 ++------------- scripts/validate_tag.sh | 53 +++++++++++++++ 10 files changed, 151 insertions(+), 112 deletions(-) rename .github/workflows/{checks.yml => check-pr.yml} (64%) create mode 100644 .github/workflows/merge-group.yml rename .github/workflows/{merge.yml => merge-post.yml} (92%) rename .github/workflows/{publish.yml => new-release.yml} (91%) rename .github/workflows/{release.yml => new-tag.yml} (95%) create mode 100755 scripts/validate_tag.sh diff --git a/.cz.toml b/.cz.toml index 3a10d9132..95b2670cc 100644 --- a/.cz.toml +++ b/.cz.toml @@ -3,6 +3,6 @@ name = "cz_conventional_commits" tag_format = "v$version" version_scheme = "semver" version = "0.6.1" -update_changelog_on_bump = false +update_changelog_on_bump = true major_version_zero = true changelog_file = "CHANGELOG.md" diff --git a/.github/workflows/checks.yml b/.github/workflows/check-pr.yml similarity index 64% rename from .github/workflows/checks.yml rename to .github/workflows/check-pr.yml index b0d0c8d92..3ce9b2234 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/check-pr.yml @@ -1,4 +1,4 @@ -name: Perform Checks on PR +name: Check PR on: pull_request: @@ -10,7 +10,7 @@ permissions: jobs: verify-pr: - name: Verify PR + name: Test Lints if: github.event_name == 'pull_request' permissions: contents: read # for TimonVS/pr-labeler-action to read config file @@ -31,7 +31,7 @@ jobs: test-builds: if: github.event_name == 'pull_request' runs-on: ubuntu-latest - name: Run Build Tests + name: Test Builds steps: - name: Checkout repository uses: actions/checkout@v4 @@ -50,7 +50,7 @@ jobs: test-unit: if: github.event_name == 'pull_request' runs-on: ubuntu-latest - name: Run Unit Tests + name: Test Unit steps: - name: Checkout repository uses: actions/checkout@v4 @@ -65,47 +65,10 @@ jobs: check-latest: true - run: make test-unit - test-race: - runs-on: ubuntu-latest - if: github.event_name == 'merge_group' - name: Run Race Tests - continue-on-error: true - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - repository: onsonr/sonr - fetch-depth: 0 - fetch-tags: true - - - uses: actions/setup-go@v5 - with: - go-version: "1.23" - check-latest: true - - run: make test-race - - test-cover: - runs-on: ubuntu-latest - if: github.event_name == 'merge_group' - name: Run Coverage Tests - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - repository: onsonr/sonr - fetch-depth: 0 - fetch-tags: true - - - uses: actions/setup-go@v5 - with: - go-version: "1.23" - check-latest: true - - run: make test-cover - validate-release: if: github.event_name == 'merge_group' || github.event_name == 'pull_request' runs-on: ubuntu-latest - name: Verify Release Config + name: Test Version steps: - name: Checkout repository uses: actions/checkout@v4 @@ -119,20 +82,17 @@ jobs: go-version: "1.23" check-latest: true - - name: Commitizen Dry Run - uses: commitizen-tools/commitizen-action@master + - name: Install Python + uses: actions/setup-python@v5 with: - push: false - dry_run: true - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: main + python-version: "3.x" - - name: Check GoReleaser Config - run: make release-check + - name: Version Check + run: make validate-tag env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: GoReleaser Dry Run - run: make release-dry + - name: Check GoReleaser Config + run: make release-check env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/merge-group.yml b/.github/workflows/merge-group.yml new file mode 100644 index 000000000..dd3cdf250 --- /dev/null +++ b/.github/workflows/merge-group.yml @@ -0,0 +1,68 @@ +name: Merge Group + +on: + merge_group: + +permissions: + contents: read # for TimonVS/pr-labeler-action to read config file + pull-requests: write # for TimonVS/pr-labeler-action to add labels in PR + +jobs: + test-race: + runs-on: ubuntu-latest + if: github.event_name == 'merge_group' + name: Test Race + continue-on-error: true + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: onsonr/sonr + fetch-depth: 0 + fetch-tags: true + + - uses: actions/setup-go@v5 + with: + go-version: "1.23" + check-latest: true + - run: make test-race + + test-cover: + runs-on: ubuntu-latest + if: github.event_name == 'merge_group' + name: Test Coverage + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: onsonr/sonr + fetch-depth: 0 + fetch-tags: true + + - uses: actions/setup-go@v5 + with: + go-version: "1.23" + check-latest: true + - run: make test-cover + + test-release: + runs-on: ubuntu-latest + name: Test Release + if: github.event_name == 'merge_group' + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: onsonr/sonr + fetch-depth: 0 + fetch-tags: true + + - uses: actions/setup-go@v5 + with: + go-version: "1.23" + check-latest: true + + - name: Release Dry Run + run: make release-dry + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/merge.yml b/.github/workflows/merge-post.yml similarity index 92% rename from .github/workflows/merge.yml rename to .github/workflows/merge-post.yml index 7201bf386..b1b56dffa 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge-post.yml @@ -1,4 +1,4 @@ -name: Bump Version on Merge +name: Post Merge on: pull_request: types: [closed] @@ -9,6 +9,7 @@ permissions: jobs: bump-version: + name: Cz Bump if: | github.event.pull_request.merged == true && github.event.pull_request.user.login != 'dependabot[bot]' && @@ -26,6 +27,7 @@ jobs: with: push: false increment: patch + branch: main - name: Push using ssh run: | diff --git a/.github/workflows/publish.yml b/.github/workflows/new-release.yml similarity index 91% rename from .github/workflows/publish.yml rename to .github/workflows/new-release.yml index 598ae3d68..5187773c4 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/new-release.yml @@ -1,4 +1,4 @@ -name: Publish Assets on Release +name: New Release on: release: types: [published] @@ -9,7 +9,7 @@ permissions: jobs: buf_push: - name: Publish to buf.build/onsonr/sonr + name: Publish Protobufs runs-on: ubuntu-latest steps: # Run `git checkout` @@ -24,7 +24,7 @@ jobs: buf_token: ${{ secrets.BUF_TOKEN }} container-push: - name: Publish Container Images + name: Publish Docker Images runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -45,7 +45,7 @@ jobs: docs-push: runs-on: ubuntu-latest - name: Publish Docs to onsonr.dev + name: Publish Tech Docs steps: - uses: actions/checkout@v4 - name: Configure Git Credentials diff --git a/.github/workflows/release.yml b/.github/workflows/new-tag.yml similarity index 95% rename from .github/workflows/release.yml rename to .github/workflows/new-tag.yml index 23c598f08..63ce13962 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/new-tag.yml @@ -1,4 +1,4 @@ -name: Versioned Release +name: New Tag on: pull_request: @@ -14,7 +14,7 @@ permissions: jobs: new-release: - name: Run GoReleaser on New Tag + name: Create Release if: startsWith(github.ref, 'refs/tags/') permissions: write-all runs-on: ubuntu-latest diff --git a/.goreleaser.yaml b/.goreleaser.yaml index d064da10d..86c2f5cae 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -5,10 +5,6 @@ project_name: sonr before: hooks: - echo "Release date is {{ .Env.RELEASE_DATE }}" - - docker build -t ghcr.io/onsonr/sonr:latest . - - docker tag ghcr.io/onsonr/sonr:latest ghcr.io/onsonr/sonr:{{ .Tag }} - - docker push ghcr.io/onsonr/sonr:{{ .Tag }} - - docker push ghcr.io/onsonr/sonr:latest builds: - id: sonr diff --git a/Makefile b/Makefile index 52751e035..888516188 100644 --- a/Makefile +++ b/Makefile @@ -342,6 +342,8 @@ release-check: @go install github.com/goreleaser/goreleaser/v2@latest @RELEASE_DATE=$(RELEASE_DATE) goreleaser check +validate-tag: + @sh ./scripts/validate_tag.sh ############################################################################### ### help ### ############################################################################### diff --git a/scripts/setup_env.sh b/scripts/setup_env.sh index e72bbf7f5..edcc6c02f 100755 --- a/scripts/setup_env.sh +++ b/scripts/setup_env.sh @@ -1,7 +1,5 @@ #!/bin/bash -set -e - ROOT_DIR=$(git rev-parse --show-toplevel) # Function to install a Go binary if it doesn't exist @@ -12,57 +10,17 @@ function go_install() { fi } -# Function to install a Cargo binary if it doesn't exist -function cargo_install() { - if ! command -v "$1" &>/dev/null; then - echo "Installing $1..." - cargo install "$1" - fi -} - -# Function to install a uv tool if it doesn't exist -function uv_install() { - if ! command -v "$1" &>/dev/null; then - echo "Installing $1..." - uv tool install "$1" --force - fi -} - -# Function to initialize git credentials -function set_git() { - git config --global user.name "Darp Alakun" - git config --global user.email "i@prad.nu" - - # Check if the GITHUB_TOKEN is set then authenticate with it if not ignore - if [[ -z ${GITHUB_TOKEN} ]]; then - echo "GITHUB_TOKEN is not set. Please set it before running this script." - exit 1 - else - gh auth login --with-token <<<"${GITHUB_TOKEN}" - fi +# Function to install a gh extension if it doesn't exist. Check gh for checking if installed +function gh_ext_install() { + gh extension install "$1" } -function get_deps() { +function main() { go_install go-task/task/v3/cmd/task@latest - go_install x-motemen/ghq@latest go_install a-h/templ/cmd/templ@latest + go_install goreleaser/goreleaser/v2@latest - cargo_install ripgrep - cargo_install fd-find - cargo_install eza - - uv_install aider-chat -} - -function clone_repos() { - ghq get github.com/onsonr/sonr - ghq get github.com/onsonr/nebula - ghq get github.com/onsonr/hway -} - -function main() { - get_deps - set_git + gh_ext_install johnmanjiro13/gh-bump } main diff --git a/scripts/validate_tag.sh b/scripts/validate_tag.sh new file mode 100755 index 000000000..a5bbfa15a --- /dev/null +++ b/scripts/validate_tag.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +set -e # Exit on any error + +# Function to compare version strings +version_gt() { + test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" +} + +# Install commitizen if not present +if ! command -v cz &> /dev/null; then + echo "Installing commitizen..." + pip install --user commitizen +fi + +# Get all tags and sort them by version +echo "Fetching all tags..." +git fetch --tags --force +TAGS=$(git tag -l "v*" | sort -V) +LATEST_TAG=$(echo "$TAGS" | tail -n1) + +if [ -z "$LATEST_TAG" ]; then + echo "No tags found" + exit 1 +fi + +echo "Latest tag: $LATEST_TAG" + +# Run commitizen to determine next version +echo "Running commitizen bump --dry-run..." +NEXT_VERSION=$(cz bump --dry-run --increment=patch 2>&1 | grep "tag to create: v" | cut -d "v" -f2) + +if [ -z "$NEXT_VERSION" ]; then + echo "Failed to determine next version" + exit 1 +fi + +echo "Next version determined by commitizen: v$NEXT_VERSION" + +# Check if the next version already exists +if echo "$TAGS" | grep -q "v$NEXT_VERSION"; then + echo "ERROR: Version v$NEXT_VERSION already exists!" + exit 1 +fi + +# Verify the next version is actually greater than the latest +if ! version_gt "$NEXT_VERSION" "${LATEST_TAG#v}"; then + echo "ERROR: Next version v$NEXT_VERSION is not greater than current version $LATEST_TAG" + exit 1 +fi + +echo "✅ Version v$NEXT_VERSION is valid and does not exist yet" +exit 0