8000 Add fossil resolver by MistressRemilia · Pull Request #530 · crystal-lang/shards · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add fossil resolver #530

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2485428
Initial work on Fossil resolver
Oct 28, 2021
95c188d
Initial work on Fossil resolver
MistressRemilia Oct 28, 2021
4abe844
Merge branch 'add-fossil-resolver' of github.com:MistressRemilia/shar…
MistressRemilia Oct 28, 2021
41e55a9
Remove unneded lines
MistressRemilia Oct 28, 2021
dbc0fc2
Add documentation
MistressRemilia Oct 28, 2021
aad749e
Add spec tests
MistressRemilia Oct 28, 2021
c15fdd8
Fix FossilResolver so that it passes the specs.
MistressRemilia Oct 28, 2021
d33c81a
Install fossil
MistressRemilia Oct 28, 2021
5b816d1
Install fossil (I hope)
MistressRemilia Oct 28, 2021
5ae7bcd
Format using `crystal tool format`
MistressRemilia Oct 28, 2021
fbbf336
Be sure USER is set in the environment on Linux
MistressRemilia Oct 28, 2021
9c12b0b
Use -nested when opening the Fossil repository.
MistressRemilia Jan 8, 2022
39c41e2
spec: Use CIRCLE_PROJECT_USERNAME instead of USER for the username
MistressRemilia Jan 30, 2022
5fa397d
Fix syntax error
8000 MistressRemilia Jan 31, 2022
0b07b11
Add workaround for older Fossil versions that don't have the --workdi…
Feb 1, 2022
ff419d1
Try something different with user environment variables *sigh*
Feb 1, 2022
a3bca12
Use less than, not less than or equal.
Feb 1, 2022
9833fd0
Use the environment: key to export environment variables for jobs
Feb 1, 2022
b911ff6
Improve support for older versions of Fossil.
Feb 1, 2022
a5958a8
Fix tests
Feb 1, 2022
9dc62b9
Merge branch 'crystal-lang:master' into add-fossil-resolver
MistressRemilia Feb 1, 2022
f6f036a
Use #split instead of #lines
Feb 1, 2022
eb62bcf
Update .github/workflows/ci.yml
MistressRemilia Feb 9, 2022
615868a
Update docs/shard.yml.adoc
MistressRemilia Feb 9, 2022
2a90c8a
Ignore the extra '--- entry limit (1) reached ---' string that gets p…
Feb 10, 2022
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
16 changes: 10 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ jobs:
test:
docker:
- image: crystallang/crystal:latest
environment:
USER: shardsuser
steps:
- run:
name: Install mercurial
command: apt-get update && apt-get install mercurial -y
name: Install mercurial and fossil
command: apt-get update && apt-get install mercurial fossil -y
- shards-make-test

test-on-osx:
Expand All @@ -63,17 +65,19 @@ jobs:
- with-brew-cache:
steps:
- run:
name: Install Crystal and Mercurial
command: brew install crystal mercurial
name: Install Crystal, Mercurial, and Fossil
command: brew install crystal mercurial fossil
- shards-make-test

test-on-nightly:
docker:
- image: crystallang/crystal:nightly
environment:
USER: shardsuser
steps:
- run:
name: Install mercurial
command: apt-get update && apt-get install mercurial -y
name: Install mercurial and fossil
command: apt-get update && apt-get install mercurial fossil -y
- shards-make-test

workflows:
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ jobs:
with:
crystal: ${{ matrix.crystal }}

- name: Install Fossil
if: ${{ runner.os == 'Linux' }}
run: |
sudo apt-get update
sudo apt-get install fossil

- name: Install Fossil
if: ${{ matrix.os == 'macos-latest' }}
run: |
brew update
brew install fossil

- name: Install Fossil
if: ${{ matrix.os == 'windows-latest' }}
run: choco install fossil

- name: Download source
uses: actions/checkout@v2

Expand Down
25 changes: 21 additions & 4 deletions docs/shard.yml.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,21 @@ required. When missing, Shards will install the _@_ bookmark or _tip_.
+
*Example:* _hg: https://hg.example.org/crystal-library_

*fossil*::

A https://www.fossil-scm.org[Fossil] repository URL (string).
+
The URL may be https://fossil-scm.org/home/help/clone[any protocol]
supported by Fossil, which includes SSH and HTTPS.
+
The Fossil repository will be cloned, the list of versions (and associated
_shard.yml_) will be extracted from Fossil tags (e.g., _v1.2.3_).
+
One of the other attributes (_version_, _tag_, _branch_, or _commit_) is
required. When missing, Shards will install _trunk_.
+
*Example:* _fossil: https://fossil.example.org/crystal-library_

*version*::
A version requirement (string).
+
Expand All @@ -357,14 +372,16 @@ the _~>_ operator has a special meaning, best shown by example:
--

*branch*::
Install the specified branch of a git dependency or the named branch
of a mercurial dependency (string).
Install the specified branch of a git dependency, or the named branch
of a mercurial or fossil dependency (string).

*commit*::
Install the specified commit of a git or mercurial dependency (string).
Install the specified commit of a git, mercurial, or fossil dependency
(string).

*tag*::
Install the specified tag of a git or mercurial dependency (string).
Install the specified tag of a git, mercurial, or fossil dependency
(string).

*bookmark*::
Install the specified bookmark of a mercurial dependency (string).
Expand Down
111 changes: 111 additions & 0 deletions spec/support/factories.cr
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,93 @@ def checkout_hg_rev(project, rev)
end
end

def create_fossil_repository(project, *versions)
Dir.cd(tmp_path) do
run "fossil init #{Process.quote(project)}.fossil"

# Use a workaround so we don't use --workdir in case the specs are run on a
# machine with an old Fossil version. See the #install_sources method in
# src/resolvers/fossil.cr
Dir.mkdir(fossil_path(project)) unless Dir.exists?(fossil_path(project))
Dir.cd(fossil_path(project)) do
run "fossil open #{Process.quote(File.join(tmp_path, project))}.fossil"
end
end

Dir.mkdir(File.join(fossil_path(project), "src"))
File.write(File.join(fossil_path(project), "src", "#{project}.cr"), "module #{project.capitalize}\nend")

Dir.cd(fossil_path(project)) do
run %|fossil add #{Process.quote("src/#{project}.cr")}|
end

versions.each { |version| create_fossil_release project, version, tag: "v#{version}" }
end

def create_fossil_release(project, version, shard : Bool | NamedTuple = true, tag : String? = nil)
create_fossil_version_commit(project, version, shard, tag)
end

def create_fossil_version_commit(project, version, shard : Bool | NamedTuple = true, tag : String? = nil)
Dir.cd(fossil_path(project)) do
if shard
contents = shard.is_a?(NamedTuple) ? shard : nil
6DB6 create_shard project, version, contents
end

name = shard[:name]? if shard.is_a?(NamedTuple)
name ||= project
File.touch "src/#{name}.cr"
run "fossil addremove"

create_fossil_commit project, "release: v#{version}", tag
end
end

def create_fossil_commit(project, message = "new commit", tag : String? = nil)
Dir.cd(fossil_path(project)) do
File.write("src/#{project}.cr", "# #{message}", mode: "a")
run "fossil addremove"

# Use --hash here to work around a file that's changed, but the size and
# mtime are the same. Depending on the resolution of mtime on the
# underlying filesystem, shard.yml may fall into this edge case during
# testing.
#
# https://fossil-users.fossil-scm.narkive.com/9ybRAo1U/error-file-is-different-on-disk-compared-to-the-repository-during-commti
if tag
run "fossil commit --hash --tag #{Process.quote(tag)} -m #{Process.quote(message)}"
else
run "fossil commit --hash -m #{Process.quote(message)}"
end
end
end

def create_fork_fossil_repository(project, upstream)
Dir.cd(tmp_path) do
run "fossil clone #{Process.quote(fossil_url(upstream))} #{Process.quote(project)}"
end
end

def create_fossil_tag(project, version)
Dir.cd(fossil_path(project)) do
run "fossil tag add #{Process.quote(version)} current"
end
end

def checkout_new_fossil_branch(project, branch)
Dir.cd(fossil_path(project)) do
run "fossil branch new #{Process.quote(branch)} current"
run "fossil checkout branch"
end
end

def checkout_fossil_rev(project, rev)
Dir.cd(fossil_path(project)) do
run "fossil checkout #{Process.quote(rev)}"
end
end

def create_shard(project, version, contents : NamedTuple? = nil)
spec = {name: project, version: version, crystal: Shards.crystal_version}
spec = spec.merge(contents) if contents
Expand Down Expand Up @@ -214,6 +301,29 @@ def hg_path(project)
File.join(tmp_path, project.to_s)
end

def fossil_commits(project, rev = "trunk")
# This is using the workaround code in case the machine running the specs is
# using an old Fossil version. See the #commit_sha1_at method in
# src/resolvers/fossil.cr for info.
Dir.cd(fossil_path(project)) do
retStr = run("fossil timeline #{Process.quote(rev)} -t ci -W 0").strip.split('\n')
retLines = retStr.flat_map do |line|
/^.+ \[(.+)\].*/.match(line).try &.[1]
end

retLines.reject! &.nil?
[/artifact:\s+(.+)/.match(run("fossil whatis #{retLines[0]}")).not_nil!.[1]]
Copy link
Member

Choose a reason for hiding this comment

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

This looks like it returns a list with only a single commit instead of a list of all commits. What's the reason for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That mirrors the behavior of the Mercurial code, which this was based on. That code looks like this:

run("hg log --template=#{Process.quote("{node}\n")} -r #{Process.quote(rev)}").strip.split('\n')

Let me go ahead and adjust the Fossil-based stuff to not rely on a list since it seems like it's not needed.

end
end

def fossil_url(project)
"file://#{Path[fossil_path(project)].to_posix}"
end

def fossil_path(project)
File.join(tmp_path, "#{project.to_s}")
end

def rel_path(project)
"../../spec/.repositories/#{project}"
end
Expand Down Expand Up @@ -252,6 +362,7 @@ def run(command, *, env = nil)
# FIXME: Concurrent streams are currently broken on Windows. Need to drop one for now.
error = nil
{% end %}

status = Process.run(command, shell: true, env: cmd_env, output: output, error: error || Process::Redirect::Close)

output = output.to_s.gsub("\r\n", "\n")
Expand Down
4 changes: 4 additions & 0 deletions spec/support/requirement.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def hg_branch(name)
Shards::HgBranchRef.new(name)
end

def fossil_branch(name)
Shards::FossilBranchRef.new(name)
end

def version(version)
Shards::Version.new(version)
end
Expand Down
Loading
0