-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 CRAN package registry #22331
Merged
Merged
Add CRAN package registry #22331
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
3d722c9
Add CRAN package registry.
KN4CK3R 1a6991a
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R c509694
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R fd9b1f0
Merge branch 'main' into feature-cran
KN4CK3R 69e6f1c
Merge branch 'main' into feature-cran
lunny d6f5dce
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R b3888e3
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R 1caa4d4
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R 6c075d8
Use relative url.
KN4CK3R dad233d
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R 6dfd20f
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R dd02f85
Add suggestions.
KN4CK3R 6b85c09
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R 49aca08
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R 3dc959a
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R 04d85f1
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R 05f8059
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R 15cf315
Crop svg.
KN4CK3R c3bdb00
Update docs.
KN4CK3R 4a1859f
fix path
KN4CK3R 2fb6bd7
Apply suggestions from code review
KN4CK3R ea313a6
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R dc4e5e2
Merge branch 'feature-cran' of https://github.com/KN4CK3R/gitea into …
KN4CK3R 01f9b55
Merge branch 'main' into feature-cran
GiteaBot e0ab621
Merge branch 'main' into feature-cran
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
--- | ||
date: "2023-01-01T00:00:00+00:00" | ||
title: "CRAN Packages Repository" | ||
slug: "cran" | ||
draft: false | ||
toc: false | ||
menu: | ||
sidebar: | ||
parent: "packages" | ||
name: "CRAN" | ||
weight: 35 | ||
identifier: "cran" | ||
--- | ||
|
||
# CRAN Packages Repository | ||
|
||
Publish [R](https://www.r-project.org/) packages to a [CRAN](https://cran.r-project.org/)-like registry for your user or organization. | ||
|
||
**Table of Contents** | ||
|
||
{{< toc >}} | ||
|
||
## Requirements | ||
|
||
To work with the CRAN package registry, you need to install [the R toolset](https://cran.r-project.org/). | ||
KN4CK3R marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Configuring the package registry | ||
|
||
To register the package registry you need to add it to `Rprofile.site`, either on the system-level, user-level (`~/.Rprofile`) or project-level: | ||
|
||
``` | ||
options("repos" = c(getOption("repos"), c(gitea="https://gitea.example.com/api/packages/{owner}/cran"))) | ||
``` | ||
|
||
| Parameter | Description | | ||
| --------- | ----------- | | ||
| `owner` | The owner of the package. | | ||
|
||
If you need to provide credentials, you may embed them as part of the url (`https://user:password@gitea.example.com/...`). | ||
|
||
## Publish a package | ||
|
||
To publish a R package, perform a HTTP `PUT` operation with the package content in the request body. | ||
|
||
Source packages: | ||
|
||
``` | ||
PUT https://gitea.example.com/api/packages/{owner}/cran/src | ||
``` | ||
|
||
| Parameter | Description | | ||
| --------- | ----------- | | ||
| `owner` | The owner of the package. | | ||
|
||
Binary packages: | ||
|
||
``` | ||
PUT https://gitea.example.com/api/packages/{owner}/cran/bin?platform={platform}&rversion={rversion} | ||
``` | ||
|
||
| Parameter | Description | | ||
| ---------- | ----------- | | ||
| `owner` | The owner of the package. | | ||
| `platform` | The name of the platform. | | ||
| `rversion` | The R version of the binary. | | ||
|
||
For example: | ||
|
||
```shell | ||
curl --user your_username:your_password_or_token \ | ||
--upload-file path/to/package.zip \ | ||
https://gitea.example.com/api/packages/testuser/cran/bin?platform=windows&rversion=4.2 | ||
``` | ||
|
||
You cannot publish a package if a package of the same name and version already exists. You must delete the existing package first. | ||
|
||
## Install a package | ||
|
||
To install a R package from the package registry, execute the following command: | ||
|
||
```shell | ||
install.packages({package_name}) | ||
KN4CK3R marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
| Parameter | Description | | ||
| -------------- | ----------- | | ||
| `package_name` | The package name. | | ||
|
||
For example: | ||
|
||
```shell | ||
install.packages("testpackage") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package cran | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
"strings" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
"code.gitea.io/gitea/models/packages" | ||
cran_module "code.gitea.io/gitea/modules/packages/cran" | ||
|
||
"xorm.io/builder" | ||
) | ||
|
||
type SearchOptions struct { | ||
OwnerID int64 | ||
FileType string | ||
Platform string | ||
RVersion string | ||
Filename string | ||
} | ||
|
||
func (opts *SearchOptions) toConds() builder.Cond { | ||
var cond builder.Cond = builder.Eq{ | ||
"package.type": packages.TypeCran, | ||
"package.owner_id": opts.OwnerID, | ||
"package_version.is_internal": false, | ||
} | ||
|
||
if opts.Filename != "" { | ||
cond = cond.And(builder.Eq{"package_file.lower_name": strings.ToLower(opts.Filename)}) | ||
} | ||
|
||
var propsCond builder.Cond = builder.Eq{ | ||
"package_property.ref_type": packages.PropertyTypeFile, | ||
} | ||
propsCond = propsCond.And(builder.Expr("package_property.ref_id = package_file.id")) | ||
|
||
count := 1 | ||
propsCondBlock := builder.Eq{"package_property.name": cran_module.PropertyType}.And(builder.Eq{"package_property.value": opts.FileType}) | ||
|
||
if opts.Platform != "" { | ||
count += 2 | ||
propsCondBlock = propsCondBlock. | ||
Or(builder.Eq{"package_property.name": cran_module.PropertyPlatform}.And(builder.Eq{"package_property.value": opts.Platform})). | ||
Or(builder.Eq{"package_property.name": cran_module.PropertyRVersion}.And(builder.Eq{"package_property.value": opts.RVersion})) | ||
} | ||
|
||
propsCond = propsCond.And(propsCondBlock) | ||
|
||
cond = cond.And(builder.Eq{ | ||
strconv.Itoa(count): builder.Select("COUNT(*)").Where(propsCond).From("package_property"), | ||
}) | ||
|
||
return cond | ||
} | ||
|
||
func SearchLatestVersions(ctx context.Context, opts *SearchOptions) ([]*packages.PackageVersion, error) { | ||
sess := db.GetEngine(ctx). | ||
Table("package_version"). | ||
Select("package_version.*"). | ||
Join("LEFT", "package_version pv2", builder.Expr("package_version.package_id = pv2.package_id AND pv2.is_internal = ? AND (package_version.created_unix < pv2.created_unix OR (package_version.created_unix = pv2.created_unix AND package_version.id < pv2.id))", false)). | ||
Join("INNER", "package", "package.id = package_version.package_id"). | ||
Join("INNER", "package_file", "package_file.version_id = package_version.id"). | ||
Where(opts.toConds().And(builder.Expr("pv2.id IS NULL"))). | ||
Asc("package.name") | ||
|
||
pvs := make([]*packages.PackageVersion, 0, 10) | ||
return pvs, sess.Find(&pvs) | ||
} | ||
|
||
func SearchFile(ctx context.Context, opts *SearchOptions) (*packages.PackageFile, error) { | ||
sess := db.GetEngine(ctx). | ||
Table("package_version"). | ||
Select("package_file.*"). | ||
Join("INNER", "package", "package.id = package_version.package_id"). | ||
Join("INNER", "package_file", "package_file.version_id = package_version.id"). | ||
Where(opts.toConds()) | ||
|
||
pf := &packages.PackageFile{} | ||
if has, err := sess.Get(pf); err != nil { | ||
return nil, err | ||
} else if !has { | ||
return nil, packages.ErrPackageFileNotExist | ||
} | ||
return pf, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy with that wording, thanks all for hearing me out ❤️