Create your custom Github Action
In the last article I solved Package.resolved issue and was glad to assist many people. Recently, I encountered the same issue while updating another app. So I decided to create custom Github action for ease.
You may recall the solution involved replacing the version value in Package.resolved.
sed
I first created shell command to replace the version value using sed. I am not going to delve about here.
sed -i ‘’ ‘s/”version” : 3/”version” : 2/’ {your project}.xcworkspace/xcshareddata/swiftpm/Package.resolved
Creating Repository
Next, I embbeded this script into a Github Action for resusability.
Following the Guide for MacOS, I created a repository
Creating Script File
and then I included a shell script file with this command line
sed -i ‘’ ‘s/”version” : 3/”version” : 2/’ *.xcworkspace/xcshareddata/swiftpm/Package.resolved
Granting execution
Execution permission is also required for the created script file to run
chmod +x patch.sh
Creating Action File
Lastly I created an action.yml like Workflow with the following content
name: 'Patch Package.resolved'
description: 'Patch Xcode 15.3 Package.resolved issue'
inputs:
workspacce:
description: 'Workspace name'
required: false
default: '*'
runs:
using: "composite"
steps:
- name: Set GitHub Path
run: echo "$GITHUB_ACTION_PATH" >> $GITHUB_PATH
shell: bash
env:
GITHUB_ACTION_PATH: ${{ github.action_path }}
- name: Run Patch
run: patch.sh ${{ inputs.workspacce }}
shell: bash
Parameter
We can provide parameters using inputs
, and its usage is similar to Workflow Dispatch.
Action Path
Setting the Github Action Path is essential to run our scripts; otherwise, you will encounter a “no such file” error.
Releasing
To publish this action, I pushed the action tagging with Version v1
git push --tags
Usage
Running the published action is straightforward. You’ve already used uses
for checking out the repository. The action path will be {github account}/{repository name}@{version}
. If your action has any parameters, provide them using with
.
- name: ...
uses: {account}/{repository name}@{version}
with:
{parameter name}: {param value}
Now I can resolve Package.resolved issue of any project just by using uses: 2sem/patch-package-resolved@v1
.
If you found this post helpful, please give it a round of applause 👏. Explore more iOS-related content in my other posts.
For additional insights and updates, check out my LinkedIn profile. Thank you for your support!
Troubleshootings
extra characters at the end of l command
https://myshittycode.com/2014/07/24/os-x-sed-extra-characters-at-the-end-of-l-command-error/
attach ‘’ (empty)
sed -i ‘’ ‘s/…/’
No such file or directory
Append this above shell script step
- name: Set GitHub Path
run: echo "$GITHUB_ACTION_PATH" >> $GITHUB_PATH
shell: bash
env:
GITHUB_ACTION_PATH: ${{ github.action_path }}