Skip to content

Commit 9c64d18

Browse files
committed
Add dry run option, add tests
1 parent 8eadf4a commit 9c64d18

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/fpm/cmd/publish.f90

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ subroutine cmd_publish(settings)
8181
do i = 1, size(upload_data)
8282
print *, upload_data(i)%s
8383
end do
84-
call delete_file(tmp_file); return
8584
end if
8685

8786
! Make sure a token is provided for publishing.
@@ -93,6 +92,14 @@ subroutine cmd_publish(settings)
9392
call delete_file(tmp_file); call fpm_stop(1, 'No token provided.')
9493
end if
9594

95+
! Perform network request and validate package on the backend as soon as
96+
! https://github.com/fortran-lang/registry/issues/41 is resolved.
97+
if (settings%is_dry_run) then
98+
print *, 'Dry run successful.'
99+
print *, ''
100+
print *, 'tarball generated for upload: ', tmp_file; return
101+
end if
102+
96103
call downloader%upload_form(official_registry_base_url//'/packages', upload_data, error)
97104
call delete_file(tmp_file)
98105
if (allocated(error)) call fpm_stop(1, '*cmd_publish* Upload error: '//error%message)

src/fpm_command_line.f90

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ module fpm_command_line
121121
type, extends(fpm_build_settings) :: fpm_publish_settings
122122
logical :: show_package_version = .false.
123123
logical :: show_upload_data = .false.
124+
logical :: is_dry_run = .false.
124125
character(len=:), allocatable :: token
125126
end type
126127

@@ -621,6 +622,7 @@ subroutine get_command_line_settings(cmd_settings)
621622
call set_args(common_args // compiler_args //'&
622623
& --show-package-version F &
623624
& --show-upload-data F &
625+
& --dry-run F &
624626
& --token " " &
625627
& --list F &
626628
& --show-model F &
@@ -638,6 +640,7 @@ subroutine get_command_line_settings(cmd_settings)
638640
cmd_settings = fpm_publish_settings( &
639641
& show_package_version = lget('show-package-version'), &
640642
& show_upload_data = lget('show-upload-data'), &
643+
& is_dry_run = lget('dry-run'), &
641644
& profile=val_profile,&
642645
& prune=.not.lget('no-prune'), &
643646
& compiler=val_compiler, &
@@ -754,7 +757,8 @@ subroutine set_help()
754757
' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] ', &
755758
' [options] ', &
756759
' clean [--skip] [--all] ', &
757-
' publish [--show-package-version] [--show-upload-data] [--token TOKEN] ', &
760+
' publish [--token TOKEN] [--show-package-version] [--show-upload-data] ', &
761+
' [--dry-run] ', &
758762
' ']
759763
help_usage=[character(len=80) :: &
760764
'' ]
@@ -878,7 +882,8 @@ subroutine set_help()
878882
' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] ', &
879883
' [options] ', &
880884
' clean [--skip] [--all] ', &
881-
' publish [--show-package-version] [--show-upload-data] [--token TOKEN] ', &
885+
' publish [--token TOKEN] [--show-package-version] [--show-upload-data] ', &
886+
' [--dry-run] ', &
882887
' ', &
883888
'SUBCOMMAND OPTIONS ', &
884889
' -C, --directory PATH', &
@@ -1362,6 +1367,7 @@ subroutine set_help()
13621367
'', &
13631368
'SYNOPSIS', &
13641369
' fpm publish [--token TOKEN] [--show-package-version] [--show-upload-data]', &
1370+
' [--dry-run] ', &
13651371
'', &
13661372
' fpm publish --help|--version', &
13671373
'', &
@@ -1390,13 +1396,15 @@ subroutine set_help()
13901396
'OPTIONS', &
13911397
' --show-package-version show package version without publishing', &
13921398
' --show-upload-data show uploaded data without publishing', &
1399+
' --dry-run create tarball for revision without publishing', &
13931400
' --help print this help and exit', &
13941401
' --version print program version information and exit', &
13951402
'', &
13961403
'EXAMPLES', &
13971404
'', &
13981405
' fpm publish --show-package-version # show package version without publishing', &
13991406
' fpm publish --show-upload-data # show upload data without publishing', &
1407+
' fpm publish --dry-run # create tarball without publishing', &
14001408
' fpm publish --token TOKEN # upload package to the registry using TOKEN', &
14011409
'' ]
14021410
end subroutine set_help

test/cli_test/cli_test.f90

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ program main
3131
logical :: c_a,act_c_a ; namelist/act_cli/act_c_a
3232
logical :: show_v,act_show_v ; namelist/act_cli/act_show_v
3333
logical :: show_u_d,act_show_u_d; namelist/act_cli/act_show_u_d
34+
logical :: dry_run,act_dry_run ; namelist/act_cli/act_dry_run
3435
character(len=:), allocatable :: token, act_token ; namelist/act_cli/act_token
3536

3637
character(len=:), allocatable :: profile,act_profile ; namelist/act_cli/act_profile
3738
character(len=:), allocatable :: args,act_args ; namelist/act_cli/act_args
38-
namelist/expected/cmd,cstat,estat,w_e,w_t,c_s,c_a,name,profile,args,show_v,show_u_d,token
39+
namelist/expected/cmd,cstat,estat,w_e,w_t,c_s,c_a,name,profile,args,show_v,show_u_d,dry_run,token
3940
integer :: lun
4041
logical,allocatable :: tally(:)
4142
logical,allocatable :: subtally(:)
@@ -76,6 +77,7 @@ program main
7677
'CMD="clean --all", C_A=T, NAME=, ARGS="",', &
7778
'CMD="publish --token abc --show-package-version", SHOW_V=T, NAME=, token="abc",ARGS="",', &
7879
'CMD="publish --token abc --show-upload-data", SHOW_U_D=T, NAME=, token="abc",ARGS="",', &
80+
'CMD="publish --token abc --dry-run", DRY_RUN=T, NAME=, token="abc",ARGS="",', &
7981
'CMD="publish --token abc", NAME=, token="abc",ARGS="",', &
8082
' ' ]
8183
character(len=256) :: readme(3)
@@ -111,6 +113,7 @@ program main
111113
c_a=.false. ! --all
112114
show_v=.false. ! --show-package-version
113115
show_u_d=.false. ! --show-upload-data
116+
dry_run=.false. ! --dry-run
114117
token='' ! --token TOKEN
115118
args=repeat(' ',132) ! -- ARGS
116119
cmd=repeat(' ',132) ! the command line arguments to test
@@ -133,6 +136,7 @@ program main
133136
act_c_a=.false.
134137
act_show_v=.false.
135138
act_show_u_d=.false.
139+
act_dry_run=.false.
136140
act_token=''
137141
act_args=repeat(' ',132)
138142
read(lun,nml=act_cli,iostat=ios,iomsg=message)
@@ -149,6 +153,7 @@ program main
149153
call test_test('WITH_TEST',act_w_t.eqv.w_t)
150154
call test_test('SHOW-PACKAGE-VERSION',act_show_v.eqv.show_v)
151155
call test_test('SHOW-UPLOAD-DATA',act_show_u_d.eqv.show_u_d)
156+
call test_test('DRY-RUN',act_dry_run.eqv.dry_run)
152157
call test_test('TOKEN',act_token==token)
153158
call test_test('ARGS',act_args==args)
154159
if(all(subtally))then
@@ -238,6 +243,7 @@ subroutine parse()
238243
act_c_a=.false.
239244
act_show_v=.false.
240245
act_show_u_d=.false.
246+
act_dry_run=.false.
241247
act_token=''
242248
act_profile=''
243249

@@ -263,6 +269,7 @@ subroutine parse()
263269
type is (fpm_publish_settings)
264270
act_show_v=settings%show_package_version
265271
act_show_u_d=settings%show_upload_data
272+
act_dry_run=settings%is_dry_run
266273
act_token=settings%token
267274
end select
268275

0 commit comments

Comments
 (0)