Github Actions for Xcode - continuous-integration

I am trying to get Github Actions to work with my Xcode project but it won't.
Here's my file
name: CI
on:
push:
branches:
- ci-test
jobs:
build:
runs-on: [macos-latest]
steps:
- name: Force xcode
run: sudo xcode-select -switch /Applications/Xcode_11.3.app
- name: Start xcodebuild test
# working-directory: 'My App'
run: xcodebuild clean test -workspace 'MyApp.xcworkspace' -scheme 'MyApp (Production)' -sdk iphonesimulator -destination 'name=iPhone 11 Pro Max,OS=13.3'
Further info:
This is the final version of the file. In most of my attempts, it complained about not finding my .xcworkspace.
This file resides in a specific feature branch, not on the master or a parent branch. I am not sure if this is relavent
The xcodebuild command works fine locally
Normally when I clone the repo on my Mac, the path is "where ever I choose/myapp-ios" and myapp-ios is the root directory where all my files including MyApp.xcworkspace are.
When I tried doing "pwd" in the action, it printed a weird path (I am assuming it's due to the action running in a virtual machine) however the path ended as follows "weird path/myapp-ios/myapp-ios"
I tried doing cd .. in the action file but that didn't work either
I tried doing git branch in the action file but I got an error indicating that it's not a git repository (I am guessing it means that it is not initialized)
I tried doing ls in the action file but it gave me bin/bash in the output instead of listing the files.
At this point I am not sure if the branch is wrong or if the path is wrong but in a test project, things worked smoothly by just specify the working directory and the action file was pretty much the same. It's worth noting that in the test project, cloning the project put all the files in another folder in the root directory, unlike this project. That's why I have omitted the working directory command from the file.

Not sure if you are still having trouble with this, but if so, I had to add the workspace prefix to get this to work correctly.
-workspace ${GITHUB_WORKSPACE}/MyApp.xcworkspace

Related

Run `flutter clean` command on each project in a directory

As a Flutter developer, I've been working on many projects. I have to work on all of them occasionally. Now those projects lie in a single directory occupying 30+ GB on my drive. It'd be a good idea to have the project's build-cache deleted to save some space. So I figured to write a script that would loop through each of them and run flutter clean inside every folder instead of running the command manually under each project's root.
After Google and StackOverflow search I came up with a command :
for /D %G in ("D:\MyProjects\*") do flutter clean "%~fG"
Well this command executes the flutter clean command for each folder like:
C:\Users\vipin>flutter clean "D:\MyProjects\Project1"
C:\Users\vipin>flutter clean "D:\MyProjects\Project2"
C:\Users\vipin>flutter clean "D:\MyProjects\Project3"
C:\Users\vipin>flutter clean "D:\MyProjects\Project4"
This should have worked since the command states to run flutter clean for each folder as it looked. Unfortunately, it didn't and threw error:
C:\Users\vipin>flutter clean "D:\MyProjects\Project1"
Error: No pubspec.yaml file found.
This command should be run from the root of your Flutter project.
C:\Users\vipin>flutter clean "D:\MyProjects\Project2"
Error: No pubspec.yaml file found.
This command should be run from the root of your Flutter project.
C:\Users\vipin>flutter clean "D:\MyProjects\Project3"
Error: No pubspec.yaml file found.
This command should be run from the root of your Flutter project.
C:\Users\vipin>flutter clean "D:\MyProjects\Project4"
Error: No pubspec.yaml file found.
This command should be run from the root of your Flutter project.
...
Well, the pubspec.yaml files are very much present in each folder and I figured that the flutter clean command demands your prompt pointing to Project's ROOT, like below to do the job:
D:\Myprojects\Project1>flutter clean
Now I'm looking for a command/script anything to move the command's prompt to each project's root and execute the command.
Glad you asked. I had the same thought about doing it to my list of projects. The below command will do exactly what you expect. Make sure to run this from D:\MyProjects
for /d %i in (D:\MyProjects\*) do ( cd "%i" & flutter clean )

how to build go outside of source directory?

My go application directory structure is like this:
/app
go.mod
go.sum
main.go
When I build the app I usually cd into that directory and build.
cd app
go build
I wonder if I can build without cd in to app directory.
When I go go build /app, it prints go: go.mod file not found in current directory or any parent directory; see 'go help modules'.
See https://golang.org/ref/mod#commands-outside :
go build needs to be run from a module directory.
The simplest way is to cd into your module directory (cd /app) to run your go build command.
(there probably is some way to create a phony local go.mod file, and reference your /app module from there, but I wasn't able to devise a hack to do this)
Go now can change directory before build with the help of flag -C:
go build -C app
"The go subcommands now accept -C to change directory to before performing the command"
Source: https://tip.golang.org/doc/go1.20
(You don't need to run cd .. after this command. Shell stays in the same directory)
I'm pretty sure to build you will need to be in the app directory.
As a workaround if you are just wanting to be on the command line in a different directory and want to run the build with one command you can just chain the cd and go build commands together like this:
cd app; go build ; cd ..
This is the same amount of typing but could be in your command history just a couple presses of the up arrow away.
Note this is for bash or similar UNIX style shell. If using Windows cmd then I think it would be something like this (Not tested as I don’t have readily available access to a Windows machine right now):
cd app & go build & cd ..

Fastlane command not found in XCode bots post build trigger

Here's my script
echo "===================="
echo "MAKE ENTERPRISE IPA"
echo "===================="
pwd
cd "${XCS_PRIMARY_REPO_DIR}/"
pwd
fastlane enterprise
This is what's in the logs
====================
MAKE ENTERPRISE IPA
====================
/Users/XcodeServer/Library/Caches/XCSBuilder/Bots/1fc5d5c4b44f01807859f14cc303b56c/Source
/Users/XcodeServer/Library/Caches/XCSBuilder/Bots/1fc5d5c4b44f01807859f14cc303b56c/Source/ProjectName
/var/folders/rc/28t61gwn3c1bcsn1b360d0h40000gp/T/F389538F-77F0-481A-A413-456C809755D1-22343-000364DDDB596983: line 10: fastlane: command not found
If I march directly to the directory on the build server and go to XCS_PRIMARY_REPO_DIR and type in fastlane enterprise everything works fine. I don't know why it's looking in var/folders for fastlane.
Any help would be greatly appreciated thank you.
I added usr/local/bin to the path. I added the following line before I call fastlane. If anyone knows of a better place to put it. I'm all ears.
export PATH=/usr/local/bin:$PATH
Follow this steps:
Navigate inside the repo. e.g.cd TemplateProject.
Add fastlane command.(Since xcode server can't find the Fastlane command you need to specify path)
To know the path navigate to your project folder from terminal and execute command:
which fastlane
Result will look as:
/Users/yourcomputername/.fastlane/bin/fastlane beta
Now use this to create a post Script command as attached in the image
This now makes xcode server find your fastlane.

Access Pods project directory in post install hook

In my podfile I am using a post install hook in my podfile to add build phase scripts to the Pods project targets and build each of the targets. The problem I am having is I that am using
system "xcodebuild -target #{target.name} -sdk iphonesimulator"
which is building the current Pods project as I am in the Pods directory. So what I need is to change to the directory of the Pods project being generated (I assume it is stored in a temp directory and then copied to the final Pods directory after the post install hook). So is there a way to access the directory of the project which I am referencing below so that I can run xcodebuild in that directory?
post_install do | installer |
installer.project <-- need the directory of this file
end
Thanks,
Liam.
You might be trying to replicate this plugin: cocoapods-native-integration. But otherwise, you should be able to access the xcodeproj path via target.user_project_path seen here

xcodebuild - how to specify the directory where the project is, without doing a cd in it

I am using xcodebuild from command line in a script, but I realized that I cannot specify the path of the project that i wanna build;I am forced to cd in the folder where the project is.
Is there a way to accomplish the build process without having to cd in the directory, or this is how it must be?
Is not a big deal to cd into the directory and execute xcodebuild, but I wonder what if someday you need to build a project and you cannot cd into the directory....It doesn't really make sense to me to not being able to specify the path.
You can use xcodebuild -project pathtoprojectfile
eg
xcodebuild -project /IOSprojects/YourProject/YourProject.xcodeproj
You must be in the directory containing the project(s) when you run xcodebuild. If you don’t want to mess with your current directory, there a couple of options:
/bin/sh -c "cd $PRJDIR; xcodebuild"
or
(cd $PRJDIR; xcodebuild)

Resources