Skip to content

Commit

Permalink
Merge pull request #118 from lippkg/develop
Browse files Browse the repository at this point in the history
Release 0.20.0
  • Loading branch information
futrime authored Feb 3, 2024
2 parents aa33d7f + fc9c490 commit c4e5ff1
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 42 deletions.
23 changes: 18 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
GOOS: [darwin, linux, windows]
GOARCH: [amd64, arm64]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-go@v3
- uses: actions/setup-go@v5
with:
cache: true

Expand All @@ -26,23 +26,36 @@ jobs:
export GOARCH=${{ matrix.GOARCH }}
go build -ldflags "-s -w" -o bin/ github.com/lippkg/lip/cmd/lip
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.GOOS }}-${{ matrix.GOARCH }}
path: bin

update-release-notes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- id: extract-release-notes
uses: ffurrer2/extract-release-notes@v2

- uses: softprops/action-gh-release@v1
with:
body: ${{ steps.extract-release-notes.outputs.release_notes }}

upload-to-release:
needs:
- build
- update-release-notes
runs-on: ubuntu-latest
strategy:
matrix:
GOOS: [darwin, linux, windows]
GOARCH: [amd64, arm64]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: ${{ matrix.GOOS }}-${{ matrix.GOARCH }}
path: artifact
Expand Down
30 changes: 19 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.20.0] - 2024-02-03

### Added

- Support Go module URL as asset URL.

### Changed

- Files downloaded from GitHub mirror are now cached in different paths.

### Removed

Expand Down Expand Up @@ -48,15 +56,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Use `github.com/blang/semver/v4` for versioning.
- Refactor most of the code.

### Fixed

- Some bugs.

### Removed

- Remove `lip autoremove` command.
- Percentage progress bar.

### Fixed

- Some bugs.

## [0.17.0] - 2023-12-30

### Added
Expand Down Expand Up @@ -353,23 +361,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Possession field in tooth.json to specify directory to remove when uninstalling a tooth.

### Changed

- Change extension name of tooth files to .tth

### Fixed

- Fix failing to fetch tooth when the repository does not contain go.mod file.
- Fix failing to parse tooth file when the tooth is downloaded via GOPROXY.
- Fix failing to parse tooth when tooth.json is the only file in the tooth.

### Changed

- Change extension name of tooth files to .tth

## [0.1.0] - 2023-01-17

### Added

- Basic functions: cache, install, list, show, tooth init, and uninstall.

[unreleased]: https://github.com/lippkg/lip/compare/v0.19.0...HEAD
[0.20.0]: https://github.com/lippkg/lip/compare/v0.19.0...v0.20.0
[0.19.0]: https://github.com/lippkg/lip/compare/v0.18.1...v0.19.0
[0.18.1]: https://github.com/lippkg/lip/compare/v0.18.0...v0.18.1
[0.18.0]: https://github.com/lippkg/lip/compare/v0.17.0...v0.18.0
Expand All @@ -396,7 +404,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[0.7.1]: https://github.com/lippkg/lip/compare/v0.7.0...v0.7.1
[0.7.0]: https://github.com/lippkg/lip/compare/v0.6.0...v0.7.0
[0.6.0]: https://github.com/lippkg/lip/compare/v0.5.1...v0.6.0
[0.5.1]: https://github.com/lippkg/lip/compare/v0.4.0...v0.5.1
[0.5.1]: https://github.com/lippkg/lip/compare/v0.5.0...v0.5.1
[0.5.0]: https://github.com/lippkg/lip/compare/v0.4.0...v0.5.0
[0.4.0]: https://github.com/lippkg/lip/compare/v0.3.4...v0.4.0
[0.3.4]: https://github.com/lippkg/lip/compare/v0.3.3...v0.3.4
Expand Down
17 changes: 16 additions & 1 deletion internal/cmd/cmdlipinstall/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/blang/semver/v4"
"github.com/lippkg/lip/internal/context"
"github.com/lippkg/lip/internal/install"
"github.com/lippkg/lip/internal/network"
"github.com/lippkg/lip/internal/path"
"github.com/lippkg/lip/internal/tooth"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -115,7 +116,21 @@ func installToothArchive(ctx *context.Context, archive tooth.Archive, forceReins

assetArchiveFilePath := path.MakeEmpty()
if assetURL.String() != "" {
cachePath, err := getCachePath(ctx, assetURL)
gitHubMirrorURL, err := ctx.GitHubMirrorURL()
if err != nil {
return fmt.Errorf("failed to get GitHub mirror URL: %w", err)
}

mirroredURL := assetURL
if network.IsGitHubDirectDownloadURL(assetURL) && gitHubMirrorURL.String() != "" {
// Rewrite GitHub URL to GitHub mirror URL if it is set.
mirroredURL, err = network.GenerateGitHubMirrorURL(assetURL, gitHubMirrorURL)
if err != nil {
return fmt.Errorf("failed to generate GitHub mirror URL: %w", err)
}
}

cachePath, err := getCachePath(ctx, mirroredURL)
if err != nil {
return fmt.Errorf("failed to get cache path of asset URL %v: %w", assetURL, err)
}
Expand Down
53 changes: 32 additions & 21 deletions internal/cmd/cmdlipinstall/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,18 @@ import (
"github.com/lippkg/lip/internal/path"
"github.com/lippkg/lip/internal/tooth"
log "github.com/sirupsen/logrus"
"golang.org/x/mod/module"
)

func downloadFileIfNotCached(ctx *context.Context, downloadURL *url.URL, explicitCachePath path.Path) (path.Path, error) {
func downloadFileIfNotCached(ctx *context.Context, downloadURL *url.URL) (path.Path, error) {
debugLogger := log.WithFields(log.Fields{
"package": "cmdlipinstall",
"method": "downloadFileIfNotCached",
})

var cachePath path.Path

if explicitCachePath.IsEmpty() {
p, err := getCachePath(ctx, downloadURL)
if err != nil {
return path.Path{}, fmt.Errorf("failed to get cache path of %v: %w", downloadURL, err)
}

cachePath = p

} else {
cachePath = explicitCachePath
cachePath, err := getCachePath(ctx, downloadURL)
if err != nil {
return path.Path{}, fmt.Errorf("failed to get cache path of %v: %w", downloadURL, err)
}

// Skip downloading if the file is already in the cache.
Expand Down Expand Up @@ -77,7 +69,7 @@ func downloadToothArchiveIfNotCached(ctx *context.Context, toothRepoPath string,
return tooth.Archive{}, fmt.Errorf("failed to generate Go module zip file URL: %w", err)
}

cachePath, err := downloadFileIfNotCached(ctx, downloadURL, path.MakeEmpty())
cachePath, err := downloadFileIfNotCached(ctx, downloadURL)
if err != nil {
return tooth.Archive{}, fmt.Errorf("failed to download file: %w", err)
}
Expand Down Expand Up @@ -116,27 +108,46 @@ func downloadToothAssetArchiveIfNotCached(ctx *context.Context, archive tooth.Ar
return fmt.Errorf("failed to get GitHub mirror URL: %w", err)
}

if network.IsGitHubURL(assetURL) && gitHubMirrorURL.String() != "" {
if network.IsGitHubDirectDownloadURL(assetURL) && gitHubMirrorURL.String() != "" {
// HTTP or HTTPS URL from GitHub.

mirroredURL, err := network.GenerateGitHubMirrorURL(assetURL, gitHubMirrorURL)
if err != nil {
return fmt.Errorf("failed to generate GitHub mirror URL: %w", err)
}

log.Infof("GitHub URL detected. Rewrite URL to %v", gitHubMirrorURL)

cachePath, err := getCachePath(ctx, assetURL)
if err != nil {
return fmt.Errorf("failed to get cache path of asset URL %v: %w", assetURL, err)
if _, err := downloadFileIfNotCached(ctx, mirroredURL); err != nil {
return fmt.Errorf("failed to download file: %w", err)
}

if _, err := downloadFileIfNotCached(ctx, mirroredURL, cachePath); err != nil {
} else if assetURL.Scheme == "http" || assetURL.Scheme == "https" {
// Other HTTP or HTTPS URL.

if _, err := downloadFileIfNotCached(ctx, assetURL); err != nil {
return fmt.Errorf("failed to download file: %w", err)
}

} else {
if _, err := downloadFileIfNotCached(ctx, assetURL, path.MakeEmpty()); err != nil {
} else if err := module.CheckPath(assetURL.String()); err == nil {
// Go module path.

goModuleProxyURL, err := ctx.GoModuleProxyURL()
if err != nil {
return fmt.Errorf("failed to get Go module proxy URL: %w", err)
}

downloadURL, err := network.GenerateGoModuleZipFileURL(assetURL.String(), archive.Metadata().Version(), goModuleProxyURL)
if err != nil {
return fmt.Errorf("failed to generate Go module zip file URL: %w", err)
}

if _, err := downloadFileIfNotCached(ctx, downloadURL); err != nil {
return fmt.Errorf("failed to download file: %w", err)
}

} else {
return fmt.Errorf("unsupported asset URL: %v", assetURL)
}

return nil
Expand Down
8 changes: 4 additions & 4 deletions internal/network/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// GenerateGitHubMirrorURL generates a GitHub mirror URL from a GitHub URL.
func GenerateGitHubMirrorURL(url *url.URL, gitHubMirrorURL *url.URL) (*url.URL, error) {
if !IsGitHubURL(url) {
if !IsGitHubDirectDownloadURL(url) {
return nil, fmt.Errorf("not a GitHub URL: %v", url)
}

Expand All @@ -20,7 +20,7 @@ func GenerateGitHubMirrorURL(url *url.URL, gitHubMirrorURL *url.URL) (*url.URL,
return mirroredURL, nil
}

// IsGitHubURL checks if a URL is a GitHub URL.
func IsGitHubURL(url *url.URL) bool {
return url.Host == "github.com"
// IsGitHubDirectDownloadURL checks if a URL is a GitHub URL that can be directly downloaded.
func IsGitHubDirectDownloadURL(url *url.URL) bool {
return url.Host == "github.com" && (url.Scheme == "http" || url.Scheme == "https")
}

0 comments on commit c4e5ff1

Please sign in to comment.