Skip to content

Commit 3c25ef1

Browse files
authored
Add test for mismatching checked out git tag when publishing (#1329)
1 parent 01cc874 commit 3c25ef1

File tree

6 files changed

+186
-127
lines changed

6 files changed

+186
-127
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Reading Spago workspace configuration...
2+
3+
✓ Selecting package to build: aaa
4+
5+
Downloading dependencies...
6+
Building...
7+
Src Lib All
8+
Warnings 0 0 0
9+
Errors 0 0 0
10+
11+
✓ Build succeeded.
12+
13+
Your package "aaa" is not ready for publishing yet, encountered 1 error:
14+
15+
16+
✘ The tag (v0.0.1) does not match the expected tag (v0.0.2).
17+
Fix all other publishing-related errors first before creating the correct tag. Do not push your created tag to its remote. Prematurely creating and pushing a tag can lead to unpublishable tags.
18+
To create the tag, you can run:
19+
git tag v0.0.2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package:
2+
name: aaa
3+
dependencies: []
4+
publish:
5+
version: 0.0.2
6+
license: MIT
7+
location:
8+
githubOwner: purescript
9+
githubRepo: aaa
10+
workspace:
11+
packageSet:
12+
registry: 58.0.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Lib where
2+
3+
anExport :: String
4+
anExport = "Hello, World!"

test/Spago.purs

+6-4
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,23 @@ import Test.Spago.Repl as Repl
2323
import Test.Spago.Run as Run
2424
import Test.Spago.Sources as Sources
2525
import Test.Spago.Test as Test
26+
import Test.Spago.Transfer as Transfer
2627
import Test.Spago.Uninstall as Uninstall
2728
import Test.Spago.Unit as Unit
2829
import Test.Spago.Upgrade as Upgrade
2930
import Test.Spec as Spec
3031
import Test.Spec.Reporter as Spec.Reporter
3132
import Test.Spec.Runner.Node (runSpecAndExitProcess')
32-
import Test.Spec.Runner.Node.Config as Config
33+
import Test.Spec.Runner.Node.Config as Cfg
3334

34-
testConfig :: Config.TestRunConfig
35-
testConfig = Config.defaultConfig
35+
testConfig :: Cfg.TestRunConfig
36+
testConfig = Cfg.defaultConfig
3637
{ timeout = Just (Milliseconds 120_000.0)
3738
}
3839

3940
main :: Effect Unit
4041
main = do
41-
config <- Config.fromCommandLine' testConfig Config.commandLineOptionParsers
42+
config <- Cfg.fromCommandLine' testConfig Cfg.commandLineOptionParsers
4243
runSpecAndExitProcess' config [ Spec.Reporter.consoleReporter ] do
4344
Spec.describe "spago" do
4445
-- TODO: script
@@ -57,6 +58,7 @@ main = do
5758
Docs.spec
5859
Upgrade.spec
5960
Publish.spec
61+
Transfer.spec
6062
Graph.spec
6163
Spec.describe "miscellaneous" do
6264
Lock.spec

test/Spago/Publish.purs

+94-123
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
module Test.Spago.Publish (spec) where
1+
module Test.Spago.Publish
2+
( doTheGitThing
3+
, spec
4+
)
5+
where
26

37
import Test.Prelude
48

@@ -85,133 +89,100 @@ spec = Spec.around withTempDir do
8589
spago [ "fetch" ] >>= shouldBeSuccess
8690
spago [ "publish", "-p", "root", "--offline" ] >>= shouldBeFailureErr (fixture "publish/1307-publish-dependencies/expected-stderr.txt")
8791

88-
Spec.describe "transfer" do
89-
90-
Spec.it "fails if the publish config is not specified" \{ spago, fixture } -> do
91-
spago [ "init", "--name", "aaaa" ] >>= shouldBeSuccess
92-
spago [ "registry", "transfer", "--offline", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeFailureErr (fixture "publish/transfer/no-publish-config.txt")
93-
94-
Spec.it "fails if the config does not specify an owner" \{ spago, fixture, testCwd } -> do
95-
FS.copyFile { src: fixture "publish/basic.yaml", dst: testCwd </> "spago.yaml" }
92+
Spec.it "#1110 installs versions of packages that are returned by the registry solver, but not present in cache" \{ spago, fixture, testCwd } -> do
93+
let
94+
shouldBeFailureErr' file = checkOutputs'
95+
{ stdoutFile: Nothing
96+
, stderrFile: Just file
97+
, result: isLeft
98+
, sanitize:
99+
String.trim
100+
>>> String.replaceAll (String.Pattern "\\") (String.Replacement "/")
101+
>>> String.replaceAll (String.Pattern "\r\n") (String.Replacement "\n")
102+
>>> Regex.replace buildOrderRegex "[x of 3] Compiling module-name"
103+
}
104+
105+
-- We have to ignore lines like "[1 of 3] Compiling Effect.Console" when
106+
-- comparing output, because the compiler will always compile in
107+
-- different order, depending on how the system resources happened to
108+
-- align at the moment of the test run.
109+
buildOrderRegex = unsafeFromRight $ Regex.regex
110+
"\\[\\d of 3\\] Compiling (Effect\\.Console|Effect\\.Class\\.Console|Lib)"
111+
RF.global
112+
113+
FS.copyTree { src: fixture "publish/1110-solver-different-version", dst: testCwd }
96114
spago [ "build" ] >>= shouldBeSuccess
97-
spago [ "registry", "transfer", "--offline", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeFailureErr (fixture "publish/transfer/no-owner.txt")
98-
99-
Spec.it "fails if the git tree is not clean" \{ spago, fixture, testCwd } -> do
100-
FS.copyFile { src: fixture "publish/basic.yaml", dst: testCwd </> "spago.yaml" }
101-
spago [ "auth", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeSuccess
102-
spago [ "registry", "transfer", "--offline", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeFailureErr (fixture "publish/transfer/no-git.txt")
103-
104-
Spec.it "fails if the package has never been published before" \{ spago, fixture, testCwd } -> do
105-
FS.copyFile { src: fixture "publish/basic.yaml", dst: testCwd </> "spago.yaml" }
106-
spago [ "auth", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeSuccess
107-
doTheGitThing
108-
spago [ "registry", "transfer", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeFailureErr (fixture "publish/transfer/never-published.txt")
109-
110-
Spec.it "fails if the new repo location is the same as the current one in the registry" \{ spago, fixture, testCwd } -> do
111-
FS.copyFile { src: fixture "publish/transfer/aff.yaml", dst: testCwd </> "spago.yaml" }
112-
spago [ "auth", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeSuccess
113115
doTheGitThing
114-
spago [ "registry", "transfer", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeFailureErr (fixture "publish/transfer/same-location.txt")
116+
spago [ "fetch" ] >>= shouldBeSuccess
115117

116-
Spec.it "fails if can't find the private key" \{ spago, fixture, testCwd } -> do
117-
FS.copyFile { src: fixture "publish/transfer/aff-new-location.yaml", dst: testCwd </> "spago.yaml" }
118-
spago [ "auth", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeSuccess
118+
-- The local `spago.yaml` specifies `console: 6.0.0` in `extraPackages`,
119+
-- so that's what should be in local cache after running `fetch`.
120+
-- Importantly, `console-6.1.0` should not be there yet.
121+
FS.exists (testCwd </> ".spago/p/console-6.0.0") >>= (_ `shouldEqual` true)
122+
FS.exists (testCwd </> ".spago/p/console-6.1.0") >>= (_ `shouldEqual` false)
123+
124+
spago [ "publish", "--offline" ] >>= shouldBeFailureErr' (fixture "publish/1110-solver-different-version/expected-stderr.txt")
125+
126+
-- When `publish` runs, it uses the registry solver, which returns
127+
-- `console-6.1.0` version, so `publish` should fetch that into local
128+
-- cache and build with it.
129+
FS.exists (testCwd </> ".spago/p/console-6.1.0") >>= (_ `shouldEqual` true)
130+
131+
-- Now screw up the `console-6.1.0` package in the local cache, so that it
132+
-- doesn't compile anymore, and check that the relevant compile error
133+
-- happens on publish.
134+
FS.unlink $ testCwd </> ".spago/p/console-6.1.0/src/Effect/Console.js"
135+
rmRf $ testCwd </> ".spago/p/console-6.1.0/output"
136+
spago [ "publish", "--offline" ] >>= shouldBeFailureErr' (fixture "publish/1110-solver-different-version/failure-stderr.txt")
137+
138+
Spec.describe "#1060 auto-filling the `publish.location` field" do
139+
let
140+
prepareProject spago fixture testCwd = do
141+
FS.copyTree { src: fixture "publish/1060-autofill-location/project", dst: testCwd }
142+
spago [ "build" ] >>= shouldBeSuccess
143+
doTheGitThing
144+
spago [ "fetch" ] >>= shouldBeSuccess
145+
146+
Spec.it "happens for root package" \{ fixture, spago, testCwd } -> do
147+
prepareProject spago fixture testCwd
148+
spago [ "publish", "-p", "aaa", "--offline" ] >>=
149+
shouldBeFailureErr (fixture "publish/1060-autofill-location/scenario-root/expected-stderr.txt")
150+
checkFixture (testCwd </> "spago.yaml")
151+
(fixture "publish/1060-autofill-location/scenario-root/expected-spago.yaml")
152+
153+
Spec.it "errors out for non-root package" \{ fixture, spago, testCwd } -> do
154+
prepareProject spago fixture testCwd
155+
spago [ "publish", "-p", "bbb", "--offline" ] >>=
156+
shouldBeFailureErr (fixture "publish/1060-autofill-location/scenario-subdir/expected-stderr.txt")
157+
158+
Spec.it "errors out for nested non-root package" \{ fixture, spago, testCwd } -> do
159+
prepareProject spago fixture testCwd
160+
spago [ "publish", "-p", "ccc", "--offline" ] >>=
161+
shouldBeFailureErr (fixture "publish/1060-autofill-location/scenario-nested-subdir/expected-stderr.txt")
162+
163+
Spec.it "errors out when not a GitHub remote" \{ fixture, spago, testCwd } -> do
164+
prepareProject spago fixture testCwd
165+
git [ "remote", "set-url", "origin", "https://not.git-hub.net/foo/bar.git" ]
166+
spago [ "publish", "-p", "aaa", "--offline" ] >>=
167+
shouldBeFailureErr (fixture "publish/1060-autofill-location/scenario-non-github/expected-stderr.txt")
168+
checkFixture (testCwd </> "spago.yaml")
169+
(fixture "publish/1060-autofill-location/scenario-non-github/expected-spago.yaml")
170+
171+
Spec.it "prints error when no origin remote" \{ fixture, spago, testCwd } -> do
172+
prepareProject spago fixture testCwd
173+
git [ "remote", "remove", "origin" ]
174+
git [ "remote", "add", "upstream", "[email protected]:foo/bar.git" ]
175+
spago [ "publish", "-p", "aaa", "--offline" ] >>=
176+
shouldBeFailureErr (fixture "publish/1060-autofill-location/scenario-no-origin/expected-stderr.txt")
177+
checkFixture (testCwd </> "spago.yaml")
178+
(fixture "publish/1060-autofill-location/project/spago.yaml")
179+
180+
Spec.it "#1109 fails if the checked out git tag does not match the publish config's version" \{ spago, fixture, testCwd } -> do
181+
FS.copyTree { src: fixture "publish/1109-tag-mismatch", dst: testCwd }
182+
spago [ "build" ] >>= shouldBeSuccess
119183
doTheGitThing
120-
spago [ "registry", "transfer", "-i", (Path.toRaw $ fixture "publish/no-key") ] >>= shouldBeFailureErr (fixture "publish/transfer/no-key.txt")
184+
spago [ "publish", "--offline" ] >>= shouldBeFailureErr (fixture "publish/1109-tag-mismatch/expected-stderr.txt")
121185

122-
Spec.it "fails if running with --offline" \{ spago, fixture, testCwd } -> do
123-
FS.copyFile { src: fixture "publish/transfer/aff-new-location.yaml", dst: testCwd </> "spago.yaml" }
124-
spago [ "auth", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeSuccess
125-
doTheGitThing
126-
spago [ "registry", "transfer", "--offline", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeFailureErr (fixture "publish/transfer/offline.txt")
127-
128-
Spec.it "#1110 installs versions of packages that are returned by the registry solver, but not present in cache" \{ spago, fixture, testCwd } -> do
129-
let
130-
shouldBeFailureErr' file = checkOutputs'
131-
{ stdoutFile: Nothing
132-
, stderrFile: Just file
133-
, result: isLeft
134-
, sanitize:
135-
String.trim
136-
>>> String.replaceAll (String.Pattern "\\") (String.Replacement "/")
137-
>>> String.replaceAll (String.Pattern "\r\n") (String.Replacement "\n")
138-
>>> Regex.replace buildOrderRegex "[x of 3] Compiling module-name"
139-
}
140-
141-
-- We have to ignore lines like "[1 of 3] Compiling Effect.Console" when
142-
-- comparing output, because the compiler will always compile in
143-
-- different order, depending on how the system resources happened to
144-
-- align at the moment of the test run.
145-
buildOrderRegex = unsafeFromRight $ Regex.regex
146-
"\\[\\d of 3\\] Compiling (Effect\\.Console|Effect\\.Class\\.Console|Lib)"
147-
RF.global
148-
149-
FS.copyTree { src: fixture "publish/1110-solver-different-version", dst: testCwd }
150-
spago [ "build" ] >>= shouldBeSuccess
151-
doTheGitThing
152-
spago [ "fetch" ] >>= shouldBeSuccess
153-
154-
-- The local `spago.yaml` specifies `console: 6.0.0` in `extraPackages`,
155-
-- so that's what should be in local cache after running `fetch`.
156-
-- Importantly, `console-6.1.0` should not be there yet.
157-
FS.exists (testCwd </> ".spago/p/console-6.0.0") >>= (_ `shouldEqual` true)
158-
FS.exists (testCwd </> ".spago/p/console-6.1.0") >>= (_ `shouldEqual` false)
159-
160-
spago [ "publish", "--offline" ] >>= shouldBeFailureErr' (fixture "publish/1110-solver-different-version/expected-stderr.txt")
161-
162-
-- When `publish` runs, it uses the registry solver, which returns
163-
-- `console-6.1.0` version, so `publish` should fetch that into local
164-
-- cache and build with it.
165-
FS.exists (testCwd </> ".spago/p/console-6.1.0") >>= (_ `shouldEqual` true)
166-
167-
-- Now screw up the `console-6.1.0` package in the local cache, so that it
168-
-- doesn't compile anymore, and check that the relevant compile error
169-
-- happens on publish.
170-
FS.unlink $ testCwd </> ".spago/p/console-6.1.0/src/Effect/Console.js"
171-
rmRf $ testCwd </> ".spago/p/console-6.1.0/output"
172-
spago [ "publish", "--offline" ] >>= shouldBeFailureErr' (fixture "publish/1110-solver-different-version/failure-stderr.txt")
173-
174-
Spec.describe "#1060 auto-filling the `publish.location` field" do
175-
let
176-
prepareProject spago fixture testCwd = do
177-
FS.copyTree { src: fixture "publish/1060-autofill-location/project", dst: testCwd }
178-
spago [ "build" ] >>= shouldBeSuccess
179-
doTheGitThing
180-
spago [ "fetch" ] >>= shouldBeSuccess
181-
182-
Spec.it "happens for root package" \{ fixture, spago, testCwd } -> do
183-
prepareProject spago fixture testCwd
184-
spago [ "publish", "-p", "aaa", "--offline" ] >>=
185-
shouldBeFailureErr (fixture "publish/1060-autofill-location/scenario-root/expected-stderr.txt")
186-
checkFixture (testCwd </> "spago.yaml")
187-
(fixture "publish/1060-autofill-location/scenario-root/expected-spago.yaml")
188-
189-
Spec.it "errors out for non-root package" \{ fixture, spago, testCwd } -> do
190-
prepareProject spago fixture testCwd
191-
spago [ "publish", "-p", "bbb", "--offline" ] >>=
192-
shouldBeFailureErr (fixture "publish/1060-autofill-location/scenario-subdir/expected-stderr.txt")
193-
194-
Spec.it "errors out for nested non-root package" \{ fixture, spago, testCwd } -> do
195-
prepareProject spago fixture testCwd
196-
spago [ "publish", "-p", "ccc", "--offline" ] >>=
197-
shouldBeFailureErr (fixture "publish/1060-autofill-location/scenario-nested-subdir/expected-stderr.txt")
198-
199-
Spec.it "errors out when not a GitHub remote" \{ fixture, spago, testCwd } -> do
200-
prepareProject spago fixture testCwd
201-
git [ "remote", "set-url", "origin", "https://not.git-hub.net/foo/bar.git" ]
202-
spago [ "publish", "-p", "aaa", "--offline" ] >>=
203-
shouldBeFailureErr (fixture "publish/1060-autofill-location/scenario-non-github/expected-stderr.txt")
204-
checkFixture (testCwd </> "spago.yaml")
205-
(fixture "publish/1060-autofill-location/scenario-non-github/expected-spago.yaml")
206-
207-
Spec.it "prints error when no origin remote" \{ fixture, spago, testCwd } -> do
208-
prepareProject spago fixture testCwd
209-
git [ "remote", "remove", "origin" ]
210-
git [ "remote", "add", "upstream", "[email protected]:foo/bar.git" ]
211-
spago [ "publish", "-p", "aaa", "--offline" ] >>=
212-
shouldBeFailureErr (fixture "publish/1060-autofill-location/scenario-no-origin/expected-stderr.txt")
213-
checkFixture (testCwd </> "spago.yaml")
214-
(fixture "publish/1060-autofill-location/project/spago.yaml")
215186

216187
doTheGitThing :: Aff Unit
217188
doTheGitThing = do

test/Spago/Transfer.purs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module Test.Spago.Transfer (spec) where
2+
3+
import Test.Prelude
4+
5+
import Spago.FS as FS
6+
import Spago.Path as Path
7+
import Test.Spago.Publish (doTheGitThing)
8+
import Test.Spec (Spec)
9+
import Test.Spec as Spec
10+
11+
spec :: Spec Unit
12+
spec = Spec.around withTempDir do
13+
Spec.describe "transfer" do
14+
15+
Spec.it "fails if the publish config is not specified" \{ spago, fixture } -> do
16+
spago [ "init", "--name", "aaaa" ] >>= shouldBeSuccess
17+
spago [ "registry", "transfer", "--offline", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeFailureErr (fixture "publish/transfer/no-publish-config.txt")
18+
19+
Spec.it "fails if the config does not specify an owner" \{ spago, fixture, testCwd } -> do
20+
FS.copyFile { src: fixture "publish/basic.yaml", dst: testCwd </> "spago.yaml" }
21+
spago [ "build" ] >>= shouldBeSuccess
22+
spago [ "registry", "transfer", "--offline", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeFailureErr (fixture "publish/transfer/no-owner.txt")
23+
24+
Spec.it "fails if the git tree is not clean" \{ spago, fixture, testCwd } -> do
25+
FS.copyFile { src: fixture "publish/basic.yaml", dst: testCwd </> "spago.yaml" }
26+
spago [ "auth", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeSuccess
27+
spago [ "registry", "transfer", "--offline", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeFailureErr (fixture "publish/transfer/no-git.txt")
28+
29+
Spec.it "fails if the package has never been published before" \{ spago, fixture, testCwd } -> do
30+
FS.copyFile { src: fixture "publish/basic.yaml", dst: testCwd </> "spago.yaml" }
31+
spago [ "auth", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeSuccess
32+
doTheGitThing
33+
spago [ "registry", "transfer", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeFailureErr (fixture "publish/transfer/never-published.txt")
34+
35+
Spec.it "fails if the new repo location is the same as the current one in the registry" \{ spago, fixture, testCwd } -> do
36+
FS.copyFile { src: fixture "publish/transfer/aff.yaml", dst: testCwd </> "spago.yaml" }
37+
spago [ "auth", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeSuccess
38+
doTheGitThing
39+
spago [ "registry", "transfer", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeFailureErr (fixture "publish/transfer/same-location.txt")
40+
41+
Spec.it "fails if can't find the private key" \{ spago, fixture, testCwd } -> do
42+
FS.copyFile { src: fixture "publish/transfer/aff-new-location.yaml", dst: testCwd </> "spago.yaml" }
43+
spago [ "auth", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeSuccess
44+
doTheGitThing
45+
spago [ "registry", "transfer", "-i", (Path.toRaw $ fixture "publish/no-key") ] >>= shouldBeFailureErr (fixture "publish/transfer/no-key.txt")
46+
47+
Spec.it "fails if running with --offline" \{ spago, fixture, testCwd } -> do
48+
FS.copyFile { src: fixture "publish/transfer/aff-new-location.yaml", dst: testCwd </> "spago.yaml" }
49+
spago [ "auth", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeSuccess
50+
doTheGitThing
51+
spago [ "registry", "transfer", "--offline", "-i", (Path.toRaw $ fixture "publish/key") ] >>= shouldBeFailureErr (fixture "publish/transfer/offline.txt")

0 commit comments

Comments
 (0)