Skip to content
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 function to dynamically determine package version for PKGBUILD #186

Merged
merged 3 commits into from
Oct 23, 2024

Conversation

timwehrle
Copy link
Contributor

Description:
This pull request resolves issue #176 by enhancing the PKGBUILD file to dynamically set the pkgver based on Git tags.

Changes:

  1. PKGBUILD:
    • Implemented a pkgver() function that dynamically retrieves the latest Git tag using git describe --tags.
    • The function uses sed 's/^v//;s/-.*//' to format the version string, ensuring it adheres to the pkgver format by:
      • Stripping the leading v from the tag (e.g., v1.7.1 becomes 1.7.1).
      • Removing any additional commit metadata (e.g., -3-ge168780).

@kehoecj kehoecj added hacktoberfest-accepted Valid PR Hacktoberfest PR hacktoberfest 🎃 Hacktoberfest 2024 waiting-on-maintainer-review PR is waiting to be reviewed and functionally tested by the maintainers labels Oct 21, 2024
@kehoecj kehoecj self-requested a review October 21, 2024 21:09
@kehoecj
Copy link
Collaborator

kehoecj commented Oct 21, 2024

@timwehrle Can you show me some output from testing this on Arch?

@kehoecj kehoecj added pr-action-requested PR is awaiting feedback from the submitting developer and removed waiting-on-maintainer-review PR is waiting to be reviewed and functionally tested by the maintainers labels Oct 22, 2024
@timwehrle
Copy link
Contributor Author

Sooo @kehoecj... I had to do an update within the function because after testing it intentionally I found some bugs. I read through the Arch forums and saw that using $srcdir is a common approach and makes the build process cleaner. We need to set the git repo as the source, so it automatically takes the latest version. If something is wrong here, just get back to me and I will try another way. But this works fine on my Arch setup.

[tim@Tim config-file-validator]$ makepkg -f
==> Making package: config-file-validator 1.7.1-1 (Tue 22 Oct 2024 11:00:37 PM CEST)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
  -> Updating config-file-validator git repo...
==> Validating source files with md5sums...
    config-file-validator ... Skipped
==> Validating source files with sha256sums...
    config-file-validator ... Skipped
==> Extracting sources...
  -> Creating working copy of config-file-validator git repo...
Cloning into 'config-file-validator'...
done.
==> Starting pkgver()...
==> Removing existing $pkgdir/ directory...
==> Starting build()...
==> Entering fakeroot environment...
==> Starting package()...
==> Tidying install...
  -> Removing libtool files...
  -> Purging unwanted files...
  -> Removing static library files...
  -> Stripping unneeded symbols from binaries and libraries...
  -> Compressing man and info pages...
==> Checking for packaging issues...
==> WARNING: Package contains reference to $srcdir
usr/bin/validator
==> Creating package "config-file-validator"...
  -> Generating .PKGINFO file...
  -> Generating .BUILDINFO file...
  -> Generating .MTREE file...
  -> Compressing package...
==> Creating package "config-file-validator-debug"...
  -> Generating .PKGINFO file...
  -> Generating .BUILDINFO file...
  -> Generating .MTREE file...
  -> Compressing package...
==> Leaving fakeroot environment.
==> Finished making: config-file-validator 1.7.1-1 (Tue 22 Oct 2024 11:00:40 PM CEST)
[tim@Tim config-file-validator]$ sudo pacman -U config-file-validator-1.7.1-1-x86_64.pkg.tar.zst
[sudo] password for tim: 
loading packages...
resolving dependencies...
looking for conflicting packages...

Packages (1) config-file-validator-1.7.1-1

Total Installed Size:  5.92 MiB

:: Proceed with installation? [Y/n] Y
(1/1) checking keys in keyring                                                                                                            [####################################################################################] 100%
(1/1) checking package integrity                                                                                                          [####################################################################################] 100%
(1/1) loading package files                                                                                                               [####################################################################################] 100%
(1/1) checking for file conflicts                                                                                                         [####################################################################################] 100%
:: Processing package changes...
(1/1) installing config-file-validator                                                                                                    [####################################################################################] 100%
:: Running post-transaction hooks...
(1/1) Arming ConditionNeedsUpdate...
[tim@Tim config-file-validator]$ pacman -Q config-file-validator
config-file-validator 1.7.1-1
[tim@Tim config-file-validator]$ validator --help
Usage: validator [OPTIONS] [<search_path>...]

positional arguments:
    search_path: The search path on the filesystem for configuration files. Defaults to the current working directory if no search_path provided

optional flags:
  -depth int
        Depth of recursion for the provided search paths. Set depth to 0 to disable recursive path traversal
  -exclude-dirs string
        Subdirectories to exclude when searching for configuration files
  -exclude-file-types string
        A comma separated list of file types to ignore
  -groupby string
        Group output by filetype, directory, pass-fail. Supported for Standard and JSON reports
  -output string
        Destination to a file to output results
  -quiet
        If quiet flag is set. It doesn't print any output to stdout.
  -reporter string
        Format of the printed report. Options are standard and json (default "standard")
  -version
        Version prints the release version of validator
[tim@Tim config-file-validator]$ validator -version
validator version 1.7.1
[tim@Tim config-file-validator]$ validator test
    ✓ /home/tim/coding/config-file-validator/test/fixtures/exclude-file-types/excluded.json
    ✓ /home/tim/coding/config-file-validator/test/fixtures/exclude-file-types/not-excluded.toml
    ✓ /home/tim/coding/config-file-validator/test/fixtures/good.csv
    ✓ /home/tim/coding/config-file-validator/test/fixtures/good.editorconfig
    ✓ /home/tim/coding/config-file-validator/test/fixtures/good.env
    ✓ /home/tim/coding/config-file-validator/test/fixtures/good.hcl
    ✓ /home/tim/coding/config-file-validator/test/fixtures/good.hocon
    ✓ /home/tim/coding/config-file-validator/test/fixtures/good.ini
    ✓ /home/tim/coding/config-file-validator/test/fixtures/good.json
    ✓ /home/tim/coding/config-file-validator/test/fixtures/good.plist
    ✓ /home/tim/coding/config-file-validator/test/fixtures/good.properties
    ✓ /home/tim/coding/config-file-validator/test/fixtures/good.toml
    ✓ /home/tim/coding/config-file-validator/test/fixtures/good.yaml
    ✓ /home/tim/coding/config-file-validator/test/fixtures/mixedcase-extension/good.CSv
    ✓ /home/tim/coding/config-file-validator/test/fixtures/mixedcase-extension/good.HCl
    ✓ /home/tim/coding/config-file-validator/test/fixtures/mixedcase-extension/good.INi
    ✓ /home/tim/coding/config-file-validator/test/fixtures/mixedcase-extension/good.JSon
    ✓ /home/tim/coding/config-file-validator/test/fixtures/mixedcase-extension/good.PList
    ✓ /home/tim/coding/config-file-validator/test/fixtures/mixedcase-extension/good.PRoperties
    ✓ /home/tim/coding/config-file-validator/test/fixtures/mixedcase-extension/good.TOml
    ✓ /home/tim/coding/config-file-validator/test/fixtures/mixedcase-extension/good.YAml
    × /home/tim/coding/config-file-validator/test/fixtures/subdir/bad.json
        error: Error at line 3 column 14: invalid character ':' after array element
    × /home/tim/coding/config-file-validator/test/fixtures/subdir/bad.toml
        error: Error at line 6 column 6: toml: expected character =
    × /home/tim/coding/config-file-validator/test/fixtures/subdir/bad.yml
        error: yaml: line 3: did not find expected '-' indicator
    ✓ /home/tim/coding/config-file-validator/test/fixtures/subdir/good.json
    × /home/tim/coding/config-file-validator/test/fixtures/subdir2/bad.csv
        error: parse error on line 1, column 20: bare " in non-quoted-field
    × /home/tim/coding/config-file-validator/test/fixtures/subdir2/bad.editorconfig
        error: cannot load ini file: unclosed section: [*.md
    × /home/tim/coding/config-file-validator/test/fixtures/subdir2/bad.env
        error: Error at line 2: invalid escape sequence: "a"
    × /home/tim/coding/config-file-validator/test/fixtures/subdir2/bad.hcl
        error: error at line 1 column 1: :1,1-2: Invalid argument name; Argument names must not be quoted.
    × /home/tim/coding/config-file-validator/test/fixtures/subdir2/bad.hocon
        error: two adjacent commas at: 3:16, adjacent commas in arrays and objects are invalid!
    × /home/tim/coding/config-file-validator/test/fixtures/subdir2/bad.ini
        error: key-value delimiter not found: name value
    × /home/tim/coding/config-file-validator/test/fixtures/subdir2/bad.json
        error: Error at line 1 column 3: invalid character '}' looking for beginning of value
    × /home/tim/coding/config-file-validator/test/fixtures/subdir2/bad.plist
        error: plist: error parsing XML property list: missing value in dictionary
    × /home/tim/coding/config-file-validator/test/fixtures/subdir2/bad.properties
        error: circular reference in:
               key=${key}
    ✓ /home/tim/coding/config-file-validator/test/fixtures/subdir2/good.ini
    ✓ /home/tim/coding/config-file-validator/test/fixtures/subdir2/good.json
    ✓ /home/tim/coding/config-file-validator/test/fixtures/uppercase-extension/good.CSV
    ✓ /home/tim/coding/config-file-validator/test/fixtures/uppercase-extension/good.HCL
    ✓ /home/tim/coding/config-file-validator/test/fixtures/uppercase-extension/good.INI
    ✓ /home/tim/coding/config-file-validator/test/fixtures/uppercase-extension/good.JSON
    ✓ /home/tim/coding/config-file-validator/test/fixtures/uppercase-extension/good.PLIST
    ✓ /home/tim/coding/config-file-validator/test/fixtures/uppercase-extension/good.PROPERTIES
    ✓ /home/tim/coding/config-file-validator/test/fixtures/uppercase-extension/good.TOML
    ✓ /home/tim/coding/config-file-validator/test/fixtures/uppercase-extension/good.YAML
    ✓ /home/tim/coding/config-file-validator/test/fixtures/with-depth/additional-depth/sample.json
    ✓ /home/tim/coding/config-file-validator/test/fixtures/with-depth/sample.json
    ✓ /home/tim/coding/config-file-validator/test/output/example/good.json
    ✓ /home/tim/coding/config-file-validator/test/output/example/result.json
    ✓ /home/tim/coding/config-file-validator/test/output/example/result.xml
[tim@Tim config-file-validator]$ makepkg -f
==> Making package: config-file-validator 0.0.0-1 (Tue 22 Oct 2024 11:02:44 PM CEST) **// Used the version 0.0.0 to ensure that it updates the version**
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
  -> Updating config-file-validator git repo...
==> Validating source files with md5sums...
    config-file-validator ... Skipped
==> Validating source files with sha256sums...
    config-file-validator ... Skipped
==> Extracting sources...
  -> Creating working copy of config-file-validator git repo...
Switched to a new branch 'makepkg'
==> Starting pkgver()...
==> **Updated version: config-file-validator 1.7.1-1 // Version was updated**
==> Removing existing $pkgdir/ directory...
==> Starting build()...
==> Entering fakeroot environment...
==> Starting package()...
==> Tidying install...
  -> Removing libtool files...
  -> Purging unwanted files...
  -> Removing static library files...
  -> Stripping unneeded symbols from binaries and libraries...
  -> Compressing man and info pages...
==> Checking for packaging issues...
==> WARNING: Package contains reference to $srcdir
usr/bin/validator
==> Creating package "config-file-validator"...
  -> Generating .PKGINFO file...
  -> Generating .BUILDINFO file...
  -> Generating .MTREE file...
  -> Compressing package...
==> Creating package "config-file-validator-debug"...
  -> Generating .PKGINFO file...
  -> Generating .BUILDINFO file...
  -> Generating .MTREE file...
  -> Compressing package...
==> Leaving fakeroot environment.
==> Finished making: config-file-validator 1.7.1-1 (Tue 22 Oct 2024 11:02:46 PM CEST)

PKGBUILD Outdated Show resolved Hide resolved
Copy link
Collaborator

@kehoecj kehoecj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks for the PR @timwehrle

@kehoecj kehoecj merged commit 1e9f9ba into Boeing:main Oct 23, 2024
9 of 10 checks passed
@kehoecj kehoecj added OSS Community Contribution Contributions from the OSS Community and removed pr-action-requested PR is awaiting feedback from the submitting developer labels Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest 🎃 Hacktoberfest 2024 hacktoberfest-accepted Valid PR Hacktoberfest PR OSS Community Contribution Contributions from the OSS Community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants