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

zip action with 'include' option runs at wrong level, produces empty archive #21433

Open
4 tasks done
robpridham-bbc opened this issue Aug 1, 2023 · 1 comment
Open
4 tasks done

Comments

@robpridham-bbc
Copy link

robpridham-bbc commented Aug 1, 2023

New Issue Checklist

Issue Description

The 'zip' action does not behave as expected when given specific files to zip.

This was previously reported by another reporter at #20219 but they did not follow up.

Command executed

In ProjectName/fastlane/Fastfile:

default_platform(:android)

platform :android do

    lane :quickFastlaneTest do
        zipList = ["x.txt", "y.txt"]
        zip(
            path: ".",
            output_path: "test.zip",
            include: zipList
        )
    end
end

Then, from ProjectName, run this command sequence:

pwd
echo "Hello X" > x.txt
echo "Hello Y" > y.txt
bundle exec fastlane quickFastlaneTest
zipinfo test.zip

pwd outputs /Users/Username/ProjectName

Partially redacted Fastlane output is:

[✔] 🚀 
[10:33:55]: ------------------------------
[10:33:55]: --- Step: default_platform ---
[10:33:55]: ------------------------------
[10:33:55]: Driving the lane 'android quickFastlaneTest' 🚀
[10:33:55]: -----------------
[10:33:55]: --- Step: zip ---
[10:33:55]: -----------------
[10:33:55]: Compressing ....
[10:33:55]: $ zip -r /Users/Username/ProjectName/test.zip . -i ./x.txt ./y.txt
[10:34:09]: ▸ Scanning files ..
[10:34:09]: ▸ zip warning: name not matched: [file in directory outside project, i.e. /Users/Username/SomewhereElse]
[10:34:10]: ▸ . zip warning: zip file empty
[10:34:10]: Successfully generated zip file at path '/Users/Username/ProjectName/test.zip'

Expected result: The zip file contains x.txt and y.txt.

Actual result: The zip file is created but empty. The command takes a long time to execute and warnings indicate it's operating at the wrong level.

Correcting for this prediction, if I alter the include path to include the project name:

        zipList = ["ProjectName/x.txt", "ProjectName/y.txt"]

then this works:

[✔] 🚀 
[10:44:32]: ------------------------------
[10:44:32]: --- Step: default_platform ---
[10:44:32]: ------------------------------
[10:44:32]: Driving the lane 'android quickFastlaneTest' 🚀
[10:44:32]: -----------------
[10:44:32]: --- Step: zip ---
[10:44:32]: -----------------
[10:44:32]: Compressing ....
[10:44:32]: $ zip -r /Users/pridhr01/StudioProjects/ProjectName/test.zip . -i ./ProjectName/x.txt ./ProjectName/y.txt
[10:44:46]: ▸ Scanning files ..
[10:44:46]: ▸ zip warning: name not matched: [redacted]
[10:44:47]: ▸ .  adding: ProjectName/x.txt (stored 0%)
[10:44:47]: ▸ .  adding: ProjectName/y.txt (stored 0%)
[10:44:47]: Successfully generated zip file at path '/Users/Username/ProjectName/test.zip'

To be clear, I should not have to do this. If it was absolutely necessary, then I would expect the output file to need the same approach. This current behaviour is confusing.

For the time being, my preferred workaround is to use sh instead of this action:

    zipList = ["x.txt", "y.txt"]
    Dir.chdir("..") do
        sh("zip", "-r", "test.zip", *zipList) #unpack array into varargs
    end

Environment

 
🚫 fastlane environment 🚫

Stack

Key Value
OS 13.4.1
Ruby 3.1.4
Bundler? true
Git git version 2.33.0
Installation Source ~/.rbenv/versions/3.1.4/bin/fastlane
Host macOS 13.4.1 (22F82)
Ruby Lib Dir ~/.rbenv/versions/3.1.4/lib
OpenSSL Version OpenSSL 3.1.0 14 Mar 2023
Is contained false
Is homebrew false
Is installed via Fabric.app false
Xcode Path /Library/Developer/CommandLineTools/
Xcode Version
Swift Version 5.8.1

System Locale

Error
No Locale with UTF8 found 🚫

fastlane files:

`./fastlane/Fastfile`
default_platform(:android)

platform :android do

    lane :quickFastlaneTest do
        zipList = ["x.txt", "y.txt"]
        zip(
            path: ".",
            output_path: "test.zip",
            include: zipList
        )
    end
end

No Appfile found

fastlane gems

Gem Version Update-Status
fastlane 2.214.0 ✅ Up-To-Date

Loaded fastlane plugins:

No plugins Loaded

Loaded gems
Gem Version
error_highlight 0.3.0
did_you_mean 1.6.1
bundler 2.3.26
pathname 0.2.0
rake 13.0.6
rexml 3.2.6
CFPropertyList 3.0.6
public_suffix 5.0.3
addressable 2.8.4
artifactory 3.0.15
atomos 0.1.3
aws-eventstream 1.2.0
aws-partitions 1.795.0
aws-sigv4 1.6.0
jmespath 1.6.2
aws-sdk-core 3.180.1
aws-sdk-kms 1.71.0
aws-sdk-s3 1.132.0
babosa 1.0.4
claide 1.1.0
colored 1.2
colored2 3.1.2
highline 2.0.3
commander 4.6.0
declarative 0.0.20
digest-crc 0.6.5
unf_ext 0.0.8.2
unf 0.1.4
domain_name 0.5.20190701
dotenv 2.8.1
emoji_regex 3.2.3
excon 0.100.0
faraday-em_http 1.0.0
faraday-em_synchrony 1.0.0
faraday-excon 1.1.0
faraday-httpclient 1.0.1
multipart-post 2.3.0
faraday-multipart 1.0.4
faraday-net_http 1.0.1
faraday-net_http_persistent 1.2.0
faraday-patron 1.0.0
faraday-rack 1.0.0
faraday-retry 1.0.3
ruby2_keywords 0.0.5
faraday 1.10.3
http-cookie 1.0.5
faraday-cookie_jar 0.0.7
faraday_middleware 1.2.0
fastimage 2.2.7
gh_inspector 1.1.3
jwt 2.7.1
memoist 0.16.2
multi_json 1.15.0
os 1.1.4
signet 0.17.0
googleauth 1.7.0
httpclient 2.8.3
mini_mime 1.1.2
trailblazer-option 0.1.2
uber 0.1.0
representable 3.2.0
retriable 3.1.2
webrick 1.8.1
google-apis-core 0.11.1
google-apis-androidpublisher_v3 0.46.0
google-apis-playcustomapp_v1 0.13.0
google-apis-iamcredentials_v1 0.17.0
google-apis-storage_v1 0.19.0
google-cloud-env 1.6.0
google-cloud-errors 1.3.1
google-cloud-core 1.6.0
google-cloud-storage 1.44.0
json 2.6.3
mini_magick 4.12.0
naturally 2.2.1
optparse 0.1.1
plist 3.7.0
rubyzip 2.3.2
security 0.1.3
simctl 1.6.10
terminal-notifier 2.0.0
unicode-display_width 1.8.0
terminal-table 1.8.0
tty-screen 0.8.1
tty-cursor 0.7.1
tty-spinner 0.9.3
word_wrap 1.0.0
nanaimo 0.3.0
xcodeproj 1.22.0
rouge 2.0.7
xcpretty 0.3.0
xcpretty-travis-formatter 1.0.1

generated on: 2023-08-01

@manminusone
Copy link

manminusone commented Mar 4, 2024

The problem here is that the action code moves one directory up during execution of the Zip command. See source here: https://github.com/fastlane/fastlane/blob/master/fastlane/lib/fastlane/actions/zip.rb#L36

So in your example the Zip command is run in the directory /Users/Username, which is why it can't find the text files. You can prove this by chdir'ing to your project directory and executing the command that Fastlane prints out: zip -r /Users/Username/ProjectName/test.zip . -i ./x.txt ./y.txt

This caused a big headache for me when I switched to Fastlane because I needed this exact functionality, so I just ended up writing my own zip action with code changed to create the archive without moving up one directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants