-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1c8fb1e
Showing
25 changed files
with
1,369 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: build | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
go-version: [1.21] | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
runs-on: ${{ matrix.os }} | ||
env: | ||
GO111MODULE: "on" | ||
steps: | ||
- name: Install Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Download Go modules | ||
run: go mod download | ||
|
||
- name: Build project | ||
run: go build -v ./... |
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,4 @@ | ||
*.orig | ||
.idea | ||
portsync | ||
todo |
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,15 @@ | ||
# Path to your local ports directory. | ||
#base = "/usr/ports" | ||
|
||
# Default maintainer used by portscout. | ||
#maintainer = "ports@FreeBSD.org" | ||
|
||
# By default all packages associated with a | ||
# maintainer are used. You can limit this | ||
# to an explicit list of package origins | ||
# below. | ||
#origins = ["x11/xmenu", "devel/gh"] | ||
|
||
# Location in which the Makefile scripts | ||
# are located. | ||
#scriptDir = "/usr/lcoal/share/portsync/Mk" |
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,22 @@ | ||
Copyright (c) Lewis Cook <lcook@FreeBSD.org> | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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,43 @@ | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
# | ||
# Copyright (c) Lewis Cook <lcook@FreeBSD.org> | ||
# All rights reserved. | ||
# | ||
PROG= portsync | ||
VERSION= 0.2 | ||
|
||
LOCALBASE?= /usr/local | ||
BINDIR= ${LOCALBASE}/bin | ||
SHAREDIR= ${LOCALBASE}/share | ||
|
||
GO_DEFAULT?= 1.21 | ||
GO_SUFFIX= ${GO_DEFAULT:S/.//} | ||
GO_CMD= ${BINDIR}/go${GO_SUFFIX} | ||
|
||
GO_MODULE= github.com/lcook/${PROG} | ||
GO_FLAGS= -v -ldflags "-s -w -X '${GO_MODULE}/cmd.version=${VERSION}'" | ||
.if exists(${.CURDIR}/.git) | ||
SHA!= git rev-parse --short HEAD | ||
BRANCH!= git symbolic-ref HEAD | sed 's,refs/heads/,,' | ||
VERSION:= ${BRANCH}/${VERSION}-${SHA} | ||
.endif | ||
|
||
all: build | ||
|
||
build: | ||
${GO_CMD} build ${GO_FLAGS} -o ${PROG} | ||
|
||
clean: | ||
${GO_CMD} clean -x | ||
|
||
install: | ||
mkdir -p ${SHAREDIR}/${PROG}/Mk | ||
cp -vR Mk ${SHAREDIR}/${PROG} | ||
cp -v ${PROG} ${BINDIR} | ||
|
||
uninstall: | ||
rm -rfv ${SHAREDIR}/${PROG} | ||
rm -rf ${BINDIR}/${PROG} | ||
|
||
.PHONY: all build clean install |
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,14 @@ | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
# | ||
# Copyright (c) Lewis Cook <lcook@FreeBSD.org> | ||
# All rights reserved. | ||
# | ||
.include "guard.mk" | ||
.include "make.mk" | ||
|
||
default: | ||
@if [ -d "${PACKAGE_DIR}/work" ]; then \ | ||
${_MAKE_CMD} clean; \ | ||
fi | ||
${_MAKE_CMD} build |
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,14 @@ | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
# | ||
# Copyright (c) Lewis Cook <lcook@FreeBSD.org> | ||
# All rights reserved. | ||
# | ||
.include "guard.mk" | ||
|
||
_GIT= /usr/local/bin/git | ||
_GIT_CMD= ${_GIT} | ||
|
||
default: | ||
(cd ${PACKAGE_DIR}; ${_GIT_CMD} add .; \ | ||
${_GIT_CMD} commit -m "${PACKAGE_ORIGIN}: Update to ${PACKAGE_LATEST}") |
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,17 @@ | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
# | ||
# Copyright (c) Lewis Cook <lcook@FreeBSD.org> | ||
# All rights reserved. | ||
# | ||
_VARS= DIR \ | ||
LATEST \ | ||
MAINTAINER \ | ||
ORIGIN \ | ||
TYPE \ | ||
VERSION | ||
.for var in ${_VARS} | ||
. if !defined(PACKAGE_${var}) | ||
.error PACKAGE_${var} is not defined. | ||
. endif | ||
.endfor |
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,10 @@ | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
# | ||
# Copyright (c) Lewis Cook <lcook@FreeBSD.org> | ||
# All rights reserved. | ||
# | ||
_MAKE?= /usr/bin/make | ||
_MAKE_ARGS= -C ${PACKAGE_DIR} \ | ||
-DNO_DIALOG | ||
_MAKE_CMD= ${_MAKE} ${_MAKE_ARGS} |
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,14 @@ | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
# | ||
# Copyright (c) Lewis Cook <lcook@FreeBSD.org> | ||
# All rights reserved. | ||
# | ||
.include "guard.mk" | ||
.include "make.mk" | ||
|
||
default: | ||
@if [ -d "${PACKAGE_DIR}/work" ]; then \ | ||
${_MAKE_CMD} clean; \ | ||
fi | ||
${_MAKE_CMD} test |
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,32 @@ | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
# | ||
# Copyright (c) Lewis Cook <lcook@FreeBSD.org> | ||
# All rights reserved. | ||
# | ||
.include "guard.mk" | ||
.include "make.mk" | ||
|
||
_TYPES= CARGO:cargo-crates-merge GO:gomod-vendor | ||
.for tuple in ${_TYPES} | ||
_MAKE_${tuple:C/(.*):(.*)/\1/}= ${_MAKE_CMD} ${tuple:C/(.*):(.*)/\2/} | ||
.endfor | ||
|
||
_PORTEDIT= /usr/local/bin/portedit | ||
default: | ||
@if [ -d "${PACKAGE_DIR}/work" ]; then \ | ||
${_MAKE_CMD} clean; \ | ||
fi | ||
${_PORTEDIT} set-version -i ${PACKAGE_LATEST} ${PACKAGE_DIR}/Makefile | ||
${_MAKE_CMD} makesum | ||
.if ${PACKAGE_TYPE} != "" | ||
. for tuple in ${_TYPES:C/(.*):(.*)/\1/} | ||
. if ${PACKAGE_TYPE} == ${tuple} | ||
${_MAKE_${tuple}} | ||
. if ${tuple} == GO | ||
${_MAKE_${tuple}} | ${_PORTEDIT} merge -i ${PACKAGE_DIR}/Makefile | ||
. endif | ||
${_MAKE_CMD} makesum | ||
. endif | ||
. endfor | ||
.endif |
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,107 @@ | ||
## ⌛ portsync | ||
|
||
![](https://github.com/lcook/portsync/actions/workflows/build.yaml/badge.svg) | ||
|
||
Command-line utility tailored for FreeBSD, focused on management of package | ||
updates, version tracking and streamlined commits of updated packages. | ||
|
||
_Caveat emptor: Still a work in progress, not all cases are covered and you | ||
are likely to encounter bugs. Little is done in terms of error-checking as primarily | ||
we run a set of Makefiles for a bulk of the work. Note that static variables, e.g., | ||
build SHA hashes are not updated, there is still a level of manual work required | ||
when updating packages albeit greatly reduced._ | ||
|
||
![Command-line demonstration](./demo.gif) | ||
|
||
[Features](#features) | [Get started](#get-started) | [Usage](#usage) | [License](#license) | ||
|
||
## Features | ||
|
||
- Fetch and display the latest package versions from [portscout](https://portscout.freebsd.org/). | ||
- Apply new updates to your local ports tree based. | ||
- Streamlined commit process for updated packages. | ||
- Conveniently build and test any changes made. | ||
|
||
## Get started | ||
|
||
1. Ensure you have Go installed on your system (minimum of 1.21). | ||
2. Clone the repository. | ||
3. Build and install. | ||
```sh | ||
git clone https://github.com/lcook/portsync | ||
cd portsync && make build install | ||
``` | ||
|
||
#### Dependencies | ||
|
||
We utilize a plethora of external tools used in helping us achieve a lot | ||
of the functionality provided. Make sure that you have `portfmt` and `modules2tuple` | ||
installed. | ||
```sh | ||
pkg install portfmt modules2tuple | ||
``` | ||
|
||
#### Configuration file | ||
|
||
There is an [included example](.portsync.example) configuration. You most only | ||
need to worry about updating the `maintainer` field with your email, and setting | ||
`base` (your ports tree) correctly. Copy this file to your $HOME directory. | ||
|
||
Alternatively, you can specify a custom location for your configuration file by | ||
passing `-c` to the utility. Likewise with the values in the configuration you | ||
may pass them to the utility. See `portsync -h` for the appropriate flags. | ||
|
||
## Usage | ||
|
||
The general workflow is pretty straightforward. | ||
|
||
Display any potential package updates for a given maintainer | ||
```sh | ||
portsync fetch -m "email@example.com" | ||
``` | ||
|
||
If no maintainer is explicitly passed, it is populated by default with `ports@FreeBSD.org` | ||
(ports with no maintainer prescribed), falling back to values found in the | ||
configuration file as mentioned above. Similarly with the directory containing | ||
your ports tree, defaulting to `/usr/ports`. | ||
|
||
Display any potential package updates for a given maintainer, only processing | ||
the packages updates for `foo/bar` and `bar/baz` (if any applicable) | ||
```sh | ||
portsync fetch -m "email@example.com" -o foo/bar -o bar/baz | ||
``` | ||
|
||
Update and commit the package `foo/bar` | ||
```sh | ||
portsync update -o foo/bar --commit # Use -g for a shorthand to --commit | ||
``` | ||
|
||
Build package `foo/bar` | ||
```sh | ||
portsync build -o foo/bar | ||
``` | ||
|
||
Run package `foo/bar`'s test suite (if any applicable) | ||
```sh | ||
portsync test -o foo/bar | ||
``` | ||
|
||
Having the ability to define a custom format specifier can be helpful when | ||
scripting. For example this neat one-liner, providing a nice terminal interface | ||
of available package updates through `fzf` | ||
```sh | ||
portsync fetch -f "%o" | fzf --multi \ | ||
--header "Select port(s) to update" --preview "pkg rquery -r FreeBSD '%e' {}" \ | ||
--preview-window=up | xargs portsync update -o | ||
``` | ||
|
||
Or even be able to output updates in a particular file format, such as JSON | ||
```sh | ||
portsync fetch -f '{"origin": "%o", "current": "%v", "latest": "%l"}' | ||
``` | ||
|
||
Happy hacking! | ||
|
||
## License | ||
|
||
[BSD 2-Clause](LICENSE) |
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,33 @@ | ||
/* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
* | ||
* Copyright (c) Lewis Cook <lcook@FreeBSD.org> | ||
* All rights reserved. | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
. "github.com/lcook/portsync/internal/fetcher" | ||
"github.com/lcook/portsync/internal/mk" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var buildCmd = &cobra.Command{ | ||
Use: "build", | ||
Short: "Build local port(s)", | ||
Long: `Attempt to build port(s) from local ports tree.`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
packages, err := Get(cmd, nil) | ||
if err != nil { | ||
return err | ||
} | ||
for _, pkg := range *packages { | ||
mk.Build(pkg) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(buildCmd) | ||
} |
Oops, something went wrong.