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

Capkgs dereference updates with shortRev addn #2

Merged
merged 7 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
df -h
- name: Checkout
uses: actions/checkout@v4
with:
ref: "${{github.head_ref || github.ref_name}}"
- name: Install Nix
uses: cachix/install-nix-action@v23
with:
Expand All @@ -51,12 +53,13 @@ jobs:
--ignore-environment \
--keep AWS_ACCESS_KEY_ID \
--keep AWS_SECRET_ACCESS_KEY \
--keep S3_ENDPOINT \
--keep CI \
--keep LOG_LEVEL \
--keep S3_ENDPOINT \
--command just ci
env:
AWS_ACCESS_KEY_ID: "${{secrets.AWS_ACCESS_KEY_ID}}"
AWS_SECRET_ACCESS_KEY: "${{secrets.AWS_SECRET_ACCESS_KEY}}"
S3_ENDPOINT: "${{secrets.S3_ENDPOINT}}"
LOG_LEVEL: "debug"
NIX_SIGNING_KEY_FILE: "/home/runner/work/capkgs/capkgs/hydra_key"
LOG_LEVEL: "debug"
S3_ENDPOINT: "${{secrets.S3_ENDPOINT}}"
10 changes: 5 additions & 5 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ list:

secret_key := env_var_or_default('NIX_SIGNING_KEY_FILE', "hydra_key")

# Based on releases.json, upload the CA contents and update packages.json
# Based on projects.json, upload the CA contents and update packages.json
packages *ARGS:
./packages.cr \
--to "s3://devx?secret-key={{secret_key}}&endpoint=${S3_ENDPOINT}&region=auto&compression=zstd" \
--from-store https://cache.iog.io \
--systems x86_64-linux

# Based on releases.json, upload the CA contents and update packages.json
# Based on projects.json, upload the CA contents and update packages.json
ci:
@just -v cache-download
@just -v packages
Expand All @@ -29,11 +29,11 @@ cache-upload:

rclone *ARGS:
#!/usr/bin/env nu
$env.HOME = $env.PWD
if $env.CI? == "true" { $env.HOME = $env.PWD }
mkdir .config/rclone
rclone config create s3 s3 env_auth=true | save -f .config/rclone/rclone.conf
rclone --s3-provider Cloudflare --s3-region auto --s3-endpoint $env.S3_ENDPOINT --verbose {{ARGS}}

push:
git add packages.json
git commit -m 'Update packages.json'
Expand All @@ -48,4 +48,4 @@ check:
nix build --no-link --print-out-paths $".#packages.x86_64-linux.($p)"
| complete
}
)
)
3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
fragment = builtins.split "#" flakeUrl;
parts = builtins.split "\\." (last fragment);
name = last parts;
shortrev = builtins.substring 0 7 pkg.commit;
in
sane "${name}-${pkg.org_name}-${pkg.repo_name}-${pkg.version}";
sane "${name}-${pkg.org_name}-${pkg.repo_name}-${pkg.version}-${shortrev}";

packagesJson = fromJSON (readFile ./packages.json);
validPackages = filterAttrs (flakeUrl: pkg: pkg ? system && !(pkg ? fail)) packagesJson;
Expand Down
16 changes: 13 additions & 3 deletions packages.cr
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,17 @@ class CAPkgs
result = sh("git", "ls-remote", "--exit-code", url)
raise "Couldn't fetch git refs for '#{url}'" unless result.success?

# Ref patterns will not be automatically dereferenced.
# To dereference, a ref pattern should have a suffix of: `\\^\\{\\}$`
# The resulting package name from a dereferenced pattern will *NOT* include the `^{}` suffix.
# The shortRev in the package name can be used to infer dereferencing.
refs_tags = ref_patterns.flat_map do |ref_pattern|
regex = Regex.new(ref_pattern)
result.stdout.lines
.map { |line| line.strip.split }
.select { |(rev, ref)| ref =~ regex }
.map do |(rev, ref)|
[ref.sub(%r(^refs/[^/]+/), ""), rev]
[ref.sub(%r(^refs/[^/]+/), "").sub(%r(\^\{\}$), ""), rev]
end
end

Expand All @@ -135,8 +139,14 @@ class CAPkgs
end

tags_url = "https://github.com/#{org_name}/#{repo_name}"
tags_result = sh("git", "ls-remote", "--exit-code", "--tags", tags_url, tag_name)
raise "Failed to fetch #{tag_name} from #{tags_url}" unless tags_result.success?

# If a tag associated dereferenced object exists, use it preferentially.
# Only annotated tags will have a dereferenced object available.
tags_result = sh("git", "ls-remote", "--exit-code", "--tags", tags_url, tag_name + "^{}")
unless tags_result.success?
tags_result = sh("git", "ls-remote", "--exit-code", "--tags", tags_url, tag_name)
raise "Failed to fetch #{tag_name} from #{tags_url}" unless tags_result.success?
end

pattern = /refs\/tags\/#{Regex.escape(tag_name)}/
matching = tags_result.stdout.lines.select { |line| line =~ pattern }
Expand Down
Loading