-
Notifications
You must be signed in to change notification settings - Fork 25
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
Showing
10 changed files
with
283 additions
and
31 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
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
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,173 @@ | ||
# SPDX-FileCopyrightText: Copyright 2024 Prasad Tengse | ||
# SPDX-License-Identifier: MIT | ||
|
||
# yaml-language-server: $schema=https://taskfile.dev/schema.json | ||
version: "3" | ||
|
||
vars: | ||
# Go coverage data directory is user's working directory + '.gocover'. | ||
# Go benchmarks data directory is user's working director + 'benchmarks'. | ||
GO_COVER_DIR: '{{ joinPath .ROOT_DIR ".gocover" }}' | ||
GO_BENCHMARKS_DIR: '{{ joinPath .ROOT_DIR "benchmarks" }}' | ||
|
||
tasks: | ||
# ----------------------------------------------------------------- | ||
# Default Task. Shows List of available tasks. | ||
# | ||
# This intentionally lacks a desc field to hide it from help output. | ||
# ----------------------------------------------------------------- | ||
default: | ||
cmds: | ||
- cmd: task --list | ||
silent: true | ||
# ----------------------------------------------------------------- | ||
# Creates a directory if not present. | ||
# ----------------------------------------------------------------- | ||
internal:mkdir: | ||
internal: true | ||
label: mkdir | ||
requires: | ||
vars: | ||
- DIRECTORY | ||
status: | ||
- >- | ||
{{- if .DIRECTORY }} | ||
test -d {{ .DIRECTORY|quote }} | ||
{{- else }} | ||
exit 0 | ||
{{- end }} | ||
cmds: | ||
# Do not use long form flag --parents as it is not supported on macOS. | ||
- cmd: mkdir -p {{.DIRECTORY|quote}} | ||
platforms: | ||
- linux | ||
- darwin | ||
- freebsd | ||
- netbsd | ||
- dragonfly | ||
- openbsd | ||
- cmd: powershell.exe -NonInteractive -NoProfile -NoLogo -Command 'New-Item -ItemType Directory -Force -Path "{{.DIRECTORY}}"' | ||
platforms: | ||
- windows | ||
# ----------------------------------------------------------------- | ||
# Removes files with PATTERN in the given DIRECTORY. | ||
# ----------------------------------------------------------------- | ||
internal:rm-file-glob: | ||
internal: true | ||
label: "rm" | ||
requires: | ||
vars: | ||
- DIRECTORY | ||
- PATTERN | ||
status: | ||
- >- | ||
{{- if .DIRECTORY }} | ||
! test -d {{ .DIRECTORY|quote }} | ||
{{- else }} | ||
exit 0 | ||
{{- end }} | ||
cmds: | ||
# Do not use long form flag --parents as it is not supported on macOS. | ||
- cmd: rm -f {{ joinPath (.DIRECTORY | quote) .PATTERN }} | ||
platforms: | ||
- linux | ||
- darwin | ||
- freebsd | ||
- netbsd | ||
- dragonfly | ||
- openbsd | ||
- cmd: powershell.exe -NonInteractive -NoProfile -NoLogo -Command 'Remove-Item -Force -Path "{{ joinPath .DIRECTORY .PATTERN }}"' | ||
platforms: | ||
- windows | ||
# ----------------------------------------------------------------- | ||
# Removes an empty DIRECTORY. | ||
# ----------------------------------------------------------------- | ||
internal:rmdir: | ||
internal: true | ||
label: "rmdir" | ||
requires: | ||
vars: | ||
- DIRECTORY | ||
status: | ||
- >- | ||
{{- if .DIRECTORY }} | ||
! test -d {{ .DIRECTORY|quote }} | ||
{{- else }} | ||
exit 0 | ||
{{- end }} | ||
cmds: | ||
- cmd: rmdir {{ .DIRECTORY | quote }} | ||
platforms: | ||
- linux | ||
- darwin | ||
- freebsd | ||
- netbsd | ||
- dragonfly | ||
- openbsd | ||
- cmd: powershell.exe -NonInteractive -NoProfile -NoLogo -Command 'Remove-Item -Force -Path "{{ .DIRECTORY }}"' | ||
platforms: | ||
- windows | ||
# ----------------------------------------------------------------- | ||
# Build Docker images | ||
# ----------------------------------------------------------------- | ||
internal:build-script: | ||
# internal: true | ||
requires: | ||
vars: | ||
- "GIT_COMMIT" | ||
- "VERSION" | ||
cmds: | ||
- task: internal:mkdir | ||
vars: | ||
DIRECTORY: "{{.DIST}}" | ||
- cmd: ./scripts/build-script build -o=dist/protonwire main.commit={{.GIT_COMMIT}} main.version={{.VERSION}} | ||
internal:build-image: | ||
internal: true | ||
requires: | ||
vars: | ||
- "PLATFORM" | ||
- "GIT_COMMIT" | ||
- "GIT_COMMIT_TIMESTAMP" | ||
vars: | ||
IMAGE_LABEL_FLAGS: >- | ||
{{- printf `--label "%s=%s"` "org.opencontainers.image.revision" .GIT_COMMIT }} | ||
{{- printf ` --label "%s=%s"` "org.opencontainers.image.created" .GIT_COMMIT_TIMESTAMP }} | ||
{{- printf ` --label "%s=%s"` "org.opencontainers.image.vendor" "Prasad Tengse <tprasadtp@users.noreply.github.com>" }} | ||
{{- printf ` --label "%s=%s"` "org.opencontainers.image.source" "https://github.com/tprasadtp/protonvpn-docker" }} | ||
{{- printf ` --label "%s=%s"` "org.opencontainers.image.title" "protonwire" }} | ||
{{- printf ` --label "%s=%s"` "org.opencontainers.image.description" "ProtonVPN Wireguard Client" }} | ||
{{- printf ` --label "%s=%s"` "org.opencontainers.image.licenses" "GPLv3" }} | ||
{{- printf ` --label "%s=%s"` "org.opencontainers.image.documentation" "https://github.com/tprasadtp/protonvpn-docker" }} | ||
{{- printf ` --label "%s=%s"` "io.artifacthub.package.readme-url" "https://raw.githubusercontent.com/tprasadtp/go-autotune/master/README.md" }} | ||
IMAGE_TAG: '{{.GIT_COMMIT }}-{{.PLATFORM | replace "/" "-" }}' | ||
IMAGE_TARBALL: '{{ printf "%s.tar" (joinPath "build" (.PLATFORM | replace "/" "-")) }}' | ||
env: | ||
DOCKER_BUILDKIT: "1" | ||
cmds: | ||
- cmd: cp Dockerfile dist/Dockerfile | ||
- docker build {{.IMAGE_LABEL_FLAGS}} --tag=ghcr.io/tprasadtp/protonwire:{{.IMAGE_TAG}} --platform={{.PLATFORM}} dist/ | ||
- docker image save --output={{.IMAGE_TARBALL}} ghcr.io/tprasadtp/protonwire:{{.IMAGE_TAG}} | ||
build-images: | ||
desc: "Build Docker Images" | ||
aliases: | ||
- "images-build" | ||
vars: | ||
GIT_COMMIT: | ||
sh: git -c log.showSignature=false show --format=%H --quiet HEAD | ||
GIT_TREE_STATE: | ||
sh: git -c log.showSignature=false status --porcelain | ||
GIT_COMMIT_TIMESTAMP: | ||
sh: git -c log.showSignature=false show --format=%cI --quiet HEAD | ||
cmds: | ||
- task: internal:build-script | ||
vars: | ||
DIST: "{{.DIST_DIR}}" | ||
GIT_COMMIT: "{{.GIT_COMMIT}}" | ||
VERSION: "dev" | ||
- for: ["linux/amd64", "linux/arm64"] | ||
task: internal:build-image | ||
vars: | ||
PLATFORM: "{{.ITEM}}" | ||
DIST_DIR: "dist" | ||
GIT_COMMIT: "{{.GIT_COMMIT}}" | ||
GIT_COMMIT_TIMESTAMP: "{{.GIT_COMMIT_TIMESTAMP}}" |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module github.com/tprasadtp/protonwire | ||
module github.com/tprasadtp/protonvpn-docker | ||
|
||
go 1.20 | ||
|
||
require github.com/Masterminds/semver/v3 v3.2.1 |
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,2 @@ | ||
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= | ||
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= |
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 @@ | ||
// SPDX-FileCopyrightText: Copyright 2024 Prasad Tengse | ||
// SPDX-License-Identifier: GPLv3-only | ||
|
||
// CLI tool to parse and extract semver versions. | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"io" | ||
"os" | ||
"strings" | ||
|
||
"github.com/Masterminds/semver/v3" | ||
) | ||
|
||
func main() { | ||
flag.Usage = func() { | ||
help(os.Stderr) | ||
} | ||
flag.Parse() | ||
|
||
if len(os.Args) < 2 { | ||
fmt.Fprintln(os.Stderr, "No commands specified!") | ||
fmt.Fprintln(os.Stderr) | ||
help(os.Stderr) | ||
os.Exit(2) | ||
} | ||
|
||
switch strings.ToLower(os.Args[1]) { | ||
case "major", "major-version", "get-major", "get-major-version": | ||
version := validate(os.Args[2]) | ||
fmt.Println(version.Major()) | ||
case "minor", "minor-version", "get-minor", "get-minor-version": | ||
version := validate(os.Args[2]) | ||
fmt.Println(version.Minor()) | ||
case "patch", "patch-version", "get-patch", "get-patch-version": | ||
version := validate(os.Args[2]) | ||
fmt.Println(version.Patch()) | ||
case "pre-release", "pre-release-version", "get-pre-release", "get-pre-release-version", | ||
"prerelease", "prerelease-version", "get-prerelease", "get-prerelease-version": | ||
version := validate(os.Args[2]) | ||
fmt.Println(version.Prerelease()) | ||
case "build", "build-version", "get-build", "get-build-version", | ||
"metadata", "metadata-version", "get-metadata", "get-metadata-version": | ||
version := validate(os.Args[2]) | ||
fmt.Println(version.Metadata()) | ||
case "is-pre-release", "is-prerelease": | ||
version := validate(os.Args[2]) | ||
if version.Prerelease() != "" { | ||
fmt.Println("true") | ||
} else { | ||
fmt.Println("false") | ||
} | ||
case "help": | ||
help(os.Stderr) | ||
default: | ||
fmt.Fprintf(os.Stderr, "Unknown commands: %s\n\n", os.Args[1:]) | ||
fmt.Fprintln(os.Stderr) | ||
help(os.Stderr) | ||
os.Exit(2) | ||
} | ||
} | ||
|
||
func help(w io.Writer) { | ||
fmt.Fprintln(w, "CLI to validate and extract semantic versions.") | ||
fmt.Fprintln(w) | ||
fmt.Fprintln(w, "USAGE: semver COMMAND VERSION") | ||
fmt.Fprintln(w) | ||
fmt.Fprintln(w, "COMMANDS:") | ||
fmt.Fprintln(w, " validate Validates VERSION is a valid semver") | ||
fmt.Fprintln(w, " major Extract major version from VERSION") | ||
fmt.Fprintln(w, " minor Extract minor version from VERSION") | ||
fmt.Fprintln(w, " minor Extract patch version from VERSION") | ||
fmt.Fprintln(w, " pre-release Extract pre-release version from VERSION") | ||
fmt.Fprintln(w, " metadata Extract metadata from VERSION") | ||
fmt.Fprintln(w, " is-pre-release Prints true if VERSION is a pre-release otherwise print false") | ||
fmt.Fprintln(w, " help Show this help message") | ||
fmt.Fprintln(w) | ||
} | ||
|
||
func validate(input string) *semver.Version { | ||
version, err := semver.StrictNewVersion(strings.TrimPrefix(input, "v")) | ||
|
||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Version(%s) is invalid: %s\n", input, err) | ||
os.Exit(2) | ||
} | ||
return version | ||
} |
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