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
13 changes: 10 additions & 3 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

permissions:
contents: write
actions: write

jobs:
nightly:
Expand Down Expand Up @@ -35,12 +36,15 @@ jobs:
fi
fi

- name: Read version from manifest
- name: Compute next patch version
if: steps.check.outputs.has_changes == 'true'
id: version
run: |
VERSION=$(jq -r '.["."]' .release-please-manifest.json)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
# The manifest holds the last released version. A nightly must sort
# above it under semver, so tag the next patch: 0.15.0 -> v0.15.1-nightly.<date>.
RELEASED=$(jq -r '.["."]' .release-please-manifest.json)
IFS=. read -r MAJOR MINOR PATCH <<< "$RELEASED"
echo "version=${MAJOR}.${MINOR}.$((PATCH + 1))" >> "$GITHUB_OUTPUT"

- name: Create nightly tag
if: steps.check.outputs.has_changes == 'true'
Expand All @@ -52,6 +56,9 @@ jobs:
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "$TAG" -m "Nightly build $DATE"
git push origin "$TAG"
gh workflow run prerelease.yml --ref "$TAG"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

cleanup:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- 'v*-beta*'
- 'v*-alpha*'
- 'v*-nightly*'
workflow_dispatch:

permissions:
contents: write
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,21 @@ task docker:up

- `GET /api/v1/projects/:id/issues/:iid/events` - Get audit events

## Releasing

### Release candidates and nightlies

Tag release candidates on `main` with the next version and a dotted counter:
`v0.16.0-rc.1`, `v0.16.0-rc.2`. The dot matters from the tenth candidate on.
Semver compares `rc.10` and `rc.9` numerically but `rc10` and `rc9` lexically.
Without the dot, `v0.16.0-rc10` sorts below `v0.16.0-rc9` and the rc channel
never offers it. `arc self update` asks for confirmation before installing.
Pass `-y` or `--yes` to skip the prompt in scripts.

Nightlies are tagged automatically as `v<next patch>-nightly.<date>`. The next
patch, not the released version, is what makes a nightly sort above the current
release. The update channel logic always prefers a newer stable release.

## License

MIT
67 changes: 66 additions & 1 deletion cmd/arc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
package main

import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"os"
"os/signal"
"strings"
"syscall"
"text/tabwriter"
"time"

"github.com/fatih/color"
"github.com/sentiolabs/arc/internal/client"
Expand Down Expand Up @@ -81,11 +85,72 @@ var (
)

func main() {
if err := rootCmd.Execute(); err != nil {
if err := runRoot(); err != nil {
os.Exit(1)
}
}

// runRoot executes the root command under a context that SIGINT or SIGTERM
// cancels. The first signal no longer kills the process, so every command
// that can block for a long time must watch ctx.Done. See tailFollow and
// planWaitCmd.
func runRoot() error {
ctx, stop := signalContext()
defer stop()
return rootCmd.ExecuteContext(ctx)
}

// Signal-handling constants.
const (
// signalBuffer holds the two signals signalContext reads: the one that
// cancels the context and the one that exits the process.
signalBuffer = 2

// signalExitBase is the offset a shell adds to a signal number when it
// reports a process killed by that signal.
signalExitBase = 128
)

// signalContext returns a context cancelled by the first SIGINT or SIGTERM.
// A second signal exits the process with 128 plus the signal number, the
// same status a shell reports for a process killed by that signal.
func signalContext() (context.Context, context.CancelFunc) {
ctx, cancel := context.WithCancel(context.Background())
sigs := make(chan os.Signal, signalBuffer)
signal.Notify(sigs, os.Interrupt, syscall.SIGTERM)
go func() {
<-sigs
cancel()
s := <-sigs
if n, ok := s.(syscall.Signal); ok {
os.Exit(signalExitBase + int(n))
}
os.Exit(1)
}()
return ctx, func() { signal.Stop(sigs); cancel() }
}

// cmdContext returns cmd's context. Tests that call RunE directly never go
// through Execute, so cmd.Context() is nil for them and a never-cancelled
// background context keeps their behavior unchanged.
func cmdContext(cmd *cobra.Command) context.Context {
if ctx := cmd.Context(); ctx != nil {
return ctx
}
return context.Background()
}

// sleepOrCancel waits for d, or returns early when ctx is cancelled. It
// reports whether the full delay elapsed.
func sleepOrCancel(ctx context.Context, d time.Duration) bool {
select {
case <-ctx.Done():
return false
case <-time.After(d):
return true
}
}

// ProjectSource indicates how the project was resolved
type ProjectSource int

Expand Down
17 changes: 14 additions & 3 deletions cmd/arc/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,17 @@ type planWaitResult struct {
Comments []*types.PlanComment `json:"comments"`
}

// planWaitCancelled reports an interrupted wait. It stays non-zero so a
// caller still tells "no decision yet" from a decision.
func planWaitCancelled(planID string, cause error) error {
return fmt.Errorf("stopped waiting for a decision on %s: %w", planID, cause)
}

// planWaitCmd blocks until a review decision is made in the planner web UI.
// It polls the plan status every 2s until it leaves draft/in_review, then
// prints the decision and the full comment thread (the same formats used by
// `arc plan comments`). Exits non-zero on timeout so callers can distinguish
// "no decision yet" from a decision.
// "no decision yet" from a decision. A cancelled context also ends the wait.
var planWaitCmd = &cobra.Command{
Use: "wait <plan-id>",
Short: "Block until the plan is approved/rejected/changes-requested in the web UI",
Expand All @@ -335,6 +341,7 @@ var planWaitCmd = &cobra.Command{
return err
}
planID := args[0]
ctx := cmdContext(cmd)

deadline := time.Now().Add(planWaitTimeout)
var consecutiveErrors int
Expand All @@ -350,7 +357,9 @@ var planWaitCmd = &cobra.Command{
return fmt.Errorf("timed out after %s waiting for a decision on %s: %w",
planWaitTimeout, planID, err)
}
time.Sleep(planWaitPollInterval)
if !sleepOrCancel(ctx, planWaitPollInterval) {
return planWaitCancelled(planID, ctx.Err())
}
continue
}
consecutiveErrors = 0
Expand All @@ -371,7 +380,9 @@ var planWaitCmd = &cobra.Command{
return fmt.Errorf("timed out after %s waiting for a decision on %s (status: %s)",
planWaitTimeout, planID, plan.Status)
}
time.Sleep(planWaitPollInterval)
if !sleepOrCancel(ctx, planWaitPollInterval) {
return planWaitCancelled(planID, ctx.Err())
}
}
},
}
Loading