Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hashGlobs query to state service #3484

Merged
merged 16 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
33 changes: 16 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Build-Test-Deploy

# === Triggers ===
"on":
'on':
push:
branches:
- master
Expand All @@ -20,7 +20,7 @@ name: Build-Test-Deploy
# === Workflow Permissions ===
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
contents: read # This is required for actions/checkout

# === Workflow-level environment variables ===
env:
Expand All @@ -38,9 +38,9 @@ jobs:
go-version:
- 1.22.x
sys:
- {os: ubuntu-latest}
- {os: macos-12, shell: zsh}
- {os: windows-2019}
- { os: ubuntu-latest }
- { os: macos-12, shell: zsh }
- { os: windows-2019 }
fail-fast: false
runs-on: ${{ matrix.sys.os }}
env:
Expand Down Expand Up @@ -174,7 +174,7 @@ jobs:
name: Check Format
id: check_format
shell: bash
if: "!contains(fromJSON('[\"refs/heads/beta\", \"refs/heads/release\", \"refs/heads/LTS\", \"refs/heads/master\"]'), github.ref) && !startsWith(github.event.pull_request.head.ref, 'version/')"
if: '!contains(fromJSON(''["refs/heads/beta", "refs/heads/release", "refs/heads/LTS", "refs/heads/master"]''), github.ref) && !startsWith(github.event.pull_request.head.ref, ''version/'')'
MDrakos marked this conversation as resolved.
Show resolved Hide resolved
run: parallelize results Check-Format

- # === Unit Tests ===
Expand All @@ -185,32 +185,32 @@ jobs:
continue-on-error: ${{ github.event_name != 'schedule' }}

- # === "Build: CLI" ===
name: "Build: CLI"
name: 'Build: CLI'
shell: bash
run: parallelize results Build-CLI

- # === "Build: Service" ===
name: "Build: Service"
name: 'Build: Service'
shell: bash
run: parallelize results Build-Service

- # === "Build: Installer" ===
name: "Build: Installer"
name: 'Build: Installer'
shell: bash
run: parallelize results Build-Installer

- # === "Build: Remote Installer" ===
name: "Build: Remote Installer"
name: 'Build: Remote Installer'
shell: bash
run: parallelize results Build-Remote-Installer

- # === "Build: Install Scripts" ===
name: "Build: Install Scripts"
name: 'Build: Install Scripts'
shell: bash
run: parallelize results Build-Install-Scripts

- # === "Build: Executor" ===
name: "Build: Executor"
name: 'Build: Executor'
shell: bash
run: parallelize results Build-Executor

Expand Down Expand Up @@ -271,7 +271,7 @@ jobs:

- # === Deploy for Integration Tests # NEVER run this against production branches. This is meant for PR deployments. ===
name: Deploy for Integration Tests # NEVER run this against production branches. This is meant for PR deployments.
if: "!contains(fromJSON('[\"refs/heads/beta\", \"refs/heads/release\", \"refs/heads/LTS\"]'), github.ref)"
if: '!contains(fromJSON(''["refs/heads/beta", "refs/heads/release", "refs/heads/LTS"]''), github.ref)'
shell: bash
run: |
if [ "$GITHUB_EVENT_NAME" != "schedule" ]; then
Expand All @@ -296,7 +296,7 @@ jobs:
- # === Integration Tests ===
name: Integration Tests
id: integration_tests
if: "!contains(fromJSON('[\"refs/heads/beta\", \"refs/heads/release\", \"refs/heads/LTS\"]'), github.ref)"
if: '!contains(fromJSON(''["refs/heads/beta", "refs/heads/release", "refs/heads/LTS"]''), github.ref)'
shell: bash
run: |
if [ "$GITHUB_EVENT_NAME" != "schedule" ]; then
Expand Down Expand Up @@ -392,7 +392,7 @@ jobs:

- # === Upload Session Artifacts ===
name: Upload Session Artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: session-build-${{ matrix.sys.os }}
path: build/
Expand Down Expand Up @@ -435,7 +435,6 @@ jobs:

# === Deploy Steps ===
steps:

- # === Checkout code ===
name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -510,7 +509,7 @@ jobs:

- # === Upload Artifacts ===
name: Upload Artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: build
path: build/
21 changes: 21 additions & 0 deletions cmd/state-svc/internal/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"os"
"path/filepath"
"runtime/debug"
"sort"
"strconv"
Expand All @@ -20,6 +21,7 @@ import (
"github.com/ActiveState/cli/internal/constants"
"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/graph"
"github.com/ActiveState/cli/internal/hash"
"github.com/ActiveState/cli/internal/logging"
configMediator "github.com/ActiveState/cli/internal/mediators/config"
"github.com/ActiveState/cli/internal/multilog"
Expand All @@ -36,6 +38,7 @@ type Resolver struct {
updatePoller *poller.Poller
authPoller *poller.Poller
projectIDCache *projectcache.ID
fileHasher *hash.FileHasher
an *sync.Client
anForClient *sync.Client // Use separate client for events sent through service so we don't contaminate one with the other
rtwatch *rtwatcher.Watcher
Expand Down Expand Up @@ -81,6 +84,7 @@ func New(cfg *config.Instance, an *sync.Client, auth *authentication.Auth) (*Res
pollUpdate,
pollAuth,
projectcache.NewID(),
hash.NewFileHasher(),
an,
anForClient,
rtwatcher.New(cfg, anForClient),
Expand Down Expand Up @@ -263,6 +267,8 @@ func (r *Resolver) GetProcessesInUse(ctx context.Context, execDir string) ([]*gr
}

func (r *Resolver) GetJwt(ctx context.Context) (*graph.Jwt, error) {
defer func() { handlePanics(recover(), debug.Stack()) }()

if err := r.auth.MaybeRenew(); err != nil {
return nil, errs.Wrap(err, "Could not renew auth token")
}
Expand Down Expand Up @@ -296,6 +302,21 @@ func (r *Resolver) GetJwt(ctx context.Context) (*graph.Jwt, error) {
return jwt, nil
}

func (r *Resolver) HashGlobs(ctx context.Context, globs []string) (string, error) {
defer func() { handlePanics(recover(), debug.Stack()) }()

var files []string
for _, glob := range globs {
matches, err := filepath.Glob(glob)
if err != nil {
return "", errs.Wrap(err, "Could not match glob: %s", glob)
}
files = append(files, matches...)
}

return r.fileHasher.HashFiles(files)
}

func handlePanics(recovered interface{}, stack []byte) {
if recovered != nil {
multilog.Error("Panic: %v", recovered)
Expand Down
Loading
Loading