Skip to content

Commit

Permalink
use UTC in the install_date; add install_commit to help tracking mast…
Browse files Browse the repository at this point in the history
…er/main versions; do not reinstall roles with master/main versions when commit matches; rearrange files
  • Loading branch information
aine-etke committed Sep 12, 2024
1 parent ae47198 commit 149e01e
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 20 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- name: add just repo
run: |
wget -qO - 'https://proget.makedeb.org/debian-feeds/prebuilt-mpr.pub' | gpg --dearmor | sudo tee /usr/share/keyrings/prebuilt-mpr-archive-keyring.gpg 1> /dev/null
echo "deb [arch=all,$(dpkg --print-architecture) signed-by=/usr/share/keyrings/prebuilt-mpr-archive-keyring.gpg] https://proget.makedeb.org prebuilt-mpr $(lsb_release -cs)" | sudo tee /etc/apt/sources.list.d/prebuilt-mpr.list
- uses: ConorMacBride/install-package@v1
with:
apt: just
- uses: extractions/setup-just@v1
- name: lint
uses: golangci/golangci-lint-action@v6
with:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist/
/cover.out
/dist
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ linters:
- bidichk
- bodyclose
- containedctx
- copyloopvar
- decorder
- dogsled
- dupl
Expand All @@ -86,7 +87,6 @@ linters:
- errname
- errorlint
- exhaustive
- exportloopref
- forcetypeassert
- gocognit
- gocritic
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ builds:
- -extldflags "-static"
flags:
- -tags=timetzdata,goolm
main: ./cmd/
main: ./cmd/agru
goos:
- linux
- windows
Expand Down
File renamed without changes.
12 changes: 7 additions & 5 deletions internal/models/entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ var forcedVersions = map[string]bool{

// GalaxyInstallInfo is meta/.galaxy_install_info struct
type GalaxyInstallInfo struct {
InstallDate string `yaml:"install_date"`
Version string `yaml:"version"`
InstallDate string `yaml:"install_date"`
InstallCommit string `yaml:"install_commit,omitempty"` // commit hash, agru's own field to help with versions like main, master
Version string `yaml:"version"`
}

// Entry is requirements.yml's entry structure
Expand Down Expand Up @@ -81,10 +82,11 @@ func (e *Entry) GetInstallInfo(rolesPath string) GalaxyInstallInfo {
}

// GenerateInstallInfo generates fresh install info from current state of the entry struct
func (e *Entry) GenerateInstallInfo() ([]byte, error) {
func (e *Entry) GenerateInstallInfo(commitSHA string) ([]byte, error) {
info := GalaxyInstallInfo{
InstallDate: time.Now().Format("Mon 02 Jan 2006 03:04:05 PM "), // the trailing space is done by ansible-galaxy
Version: e.Version,
InstallDate: time.Now().UTC().Format("Mon 02 Jan 2006 03:04:05 PM "), // the trailing space is done by ansible-galaxy
InstallCommit: commitSHA,
Version: e.Version,
}
return yaml.Marshal(info)
}
Expand Down
16 changes: 14 additions & 2 deletions internal/parser/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func InstallMissingRoles(rolesPath string, entries models.File, cleanup bool) {
func GetInstalledRoles(rolesPath string, entries models.File) models.File {
installed := models.File{}
for _, entry := range entries {
entry := entry
if entry.GetInstallInfo(rolesPath).Version != "" {
installed = append(installed, entry)
}
Expand Down Expand Up @@ -131,6 +130,19 @@ func installRole(rolesPath string, entry *models.Entry, cleanup bool) {
return
}

sha, err := utils.Run("git rev-parse HEAD", tmpdir)
if err != nil {
utils.Log("ERROR: cannot get commit hash:", err)
return
}

// check if the role is already installed
installedCommit := entry.GetInstallInfo(rolesPath).InstallCommit
if sha != "" && installedCommit != "" && sha == entry.GetInstallInfo(rolesPath).InstallCommit {
utils.Debug(name, "is already up to date")
return
}

// create archive from the cloned source
var archive strings.Builder
archive.WriteString("git archive --prefix=")
Expand All @@ -155,7 +167,7 @@ func installRole(rolesPath string, entry *models.Entry, cleanup bool) {
}

// write install info file
outb, err := entry.GenerateInstallInfo()
outb, err := entry.GenerateInstallInfo(sha)
if err != nil {
utils.Log("ERROR: cannot generate install info:", err)
return
Expand Down
10 changes: 7 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ default:

# update go deps
update *flags:
go get {{ flags }} ./cmd
go get {{ flags }} ./cmd/agru
go mod tidy
go mod vendor

Expand All @@ -28,8 +28,12 @@ test packages="./...":

# run app
run:
@go run ./cmd
@go run ./cmd/agru

# install app
install:
@CGO_ENABLED=0 go install -ldflags '-extldflags "-static"' -tags timetzdata,goolm -v ./cmd/agru

# build app
build:
CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' -tags timetzdata,goolm -v -o agru ./cmd
@CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' -tags timetzdata,goolm -v ./cmd/agru

0 comments on commit 149e01e

Please sign in to comment.