Skip to content

Commit

Permalink
Add Features + GitHub Actions Workflows + Dependency Manager Contract…
Browse files Browse the repository at this point in the history
… Files (#1)

* feat: create directory

Since it's the first feature to be implemented, it includes adding the new files.

* feat: delete directory

Includes a few refactors on create directory to keep structure as similar as possible.

* chore: manage to be deprecated method

Create a URLFactory that, depending on the current build iOS version, uses the new or current (to be deprecated) version of creating an URL based on a path string.

* feat: list directory

Refactor existing implementation to use the new method.

* feat: read file

Refactor project to make it easier to navigate.
Add new swiftlint disabled rule.

* feat: get file url

Exchange URLFactory with an extension as there are now 2 methods being used and it makes sense to group it all.

* feat: delete file

* feat: save file

* feat: append data to file

* feat: get item attributes

* feat: rename and copy item

Split OSFLSTFileManagerTests file into different extensions to avoid SwiftLint warnings.

* fix: Xcode 15 compatibility issue

For Xcode 15, 'switch' statements may only be used as expression in return, throw, or as the source of an assignment.

* chore: rename FLST to FILE

* chore: add build folder to gitignore

* chore: use URL instead of Path

This makes the whole library simpler to use.
Adapt tests accordingly.
Remove redundant code.
Add two missing tests, one for rename and another for copy, where the FileManager fails its operations.

* feat: use directory types instead of search paths and add 2 new values

These new values accommodate values required by the Cordova plugin. By having this, the name "SearchPath" doesn't make sense anymore, which justifies its update to DirectoryType.
Add tests for these new types.

* chore: remove encoding from path

Apply some additional refactoring.

* feat: add read file in chunks

rename the old readFile method to readEntireFile for easier separation of concerns.

* chore: adapt chunk size to encoding type

Byte buffers, since they're Base64 data, need to be encoding in multiple of 3 sizes.

* chore: add error when not able to handle file

This is added to the OSFILEChunkSubscription flow.
Add unit test to validate scenario.

* chore: change naming

Adopt the ION name instead of OS.
Update Gemfile bundles.

* chore: add GitHub Actions workflows

* chore: add SwiftPackageManager file

* chore: set initial project and marketing versions

* fix: failing workflow unit tests

Removed a readFileInChunks test as it proved unreliable for versions below iOS 18.

* chore: add CHANGELOG entries

* fix: add possibility to return byteBuffer on both read file methods

This aligns the read methods with the approach already used for write.

* chore: address PR comments

* fix: address PR comments + refactors

Remove the return statement from saveFile.
Align getItemAttributes with the rest of the protocol's methods: to receive a URL instead of a plain-text path.
Add the withSecurityScopedAccess verification to all operations.
Add read file validations to validate the behaviour when the file doesn't exists.
Refactor the code a bit, to remove unnecessary protocol logic.

* chore: revert code for copy and rename

This introduced a change in the logic so it reverts it.

* chore: add descriptive message to all errors
  • Loading branch information
OS-ricardomoreirasilva authored Feb 5, 2025
1 parent d3e1b71 commit 055e50b
Show file tree
Hide file tree
Showing 30 changed files with 1,999 additions and 123 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Continuous Integration

on:
push:
branches:
- main, development
pull_request:
types: [opened, synchronize, reopened]

jobs:
sonarcloud:
name: Unit-Tests
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Link SwiftLint or install it
run: brew link --overwrite swiftlint || brew install swiftlint

- name: Set up XCode
run: sudo xcode-select --switch /Applications/Xcode_15.0.app

- name: Bundle Install
run: bundle install

- name: Unit tests
run: bundle exec fastlane unit_tests

- name: Code Coverage
run: bundle exec fastlane coverage

- name: Lint
run: bundle exec fastlane lint
81 changes: 81 additions & 0 deletions .github/workflows/prepare_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Prepare Release

on:
workflow_dispatch:
inputs:
versionBumpLevel:
description: 'Version bump level (patch, minor, major)'
required: true
type: choice
default: 'patch'
options:
- patch
- minor
- major

jobs:
build-and-release:
if: github.ref == 'refs/heads/main'
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Link SwiftLint or install it
run: brew link --overwrite swiftlint || brew install swiftlint

- name: Set up XCode
run: sudo xcode-select --switch /Applications/Xcode_15.0.app

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'

- name: Bump version
run: ruby ./scripts/bump_versions.rb ${{ github.event.inputs.versionBumpLevel }}

- name: Build XCFramework
run: ./scripts/build_framework.sh

- name: Get new version
id: version
run: echo "VERSION=$(ruby -e 'puts File.read("./IONFilesystemLib.podspec").match(/spec.version.*=.*''(\d+\.\d+\.\d+)''/)[1]')" >> $GITHUB_ENV

- name: Create new branch
run: |
git switch --create "prepare-new-release-${{ env.VERSION }}"
- name: Move zip file to root and push changes
run: |
if [ -f IONFilesystemLib.zip ]; then
rm IONFilesystemLib.zip
else
echo "File does not exist."
fi
mv build/IONFilesystemLib.zip .
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add .
git commit -m "chore: Bump version to ${{ env.VERSION }}"
git push origin HEAD:prepare-new-release-${{ env.VERSION }}
- name: Create pull request
id: create_pr
run: |
gh pr create -B main -H prepare-new-release-${{ env.VERSION }} --title 'Prepare `main` to Release `${{ env.VERSION }}`' --body 'Bumps version to `${{ env.VERSION }}`.<br/>Creates an updated and ready-to-be-released `IONFilesystemLib.zip`.'
PR_NUMBER=$(gh pr view --json number --jq '.number')
echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Add label to the pull request
run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/issues/${{ env.PR_NUMBER }}/labels \
-f "labels[]=release"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67 changes: 67 additions & 0 deletions .github/workflows/release_and_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Release and Publish

on:
pull_request:
types: [closed]
branches:
- 'main'

jobs:
post-merge:
if: contains(github.event.pull_request.labels.*.name, 'release') && github.event.pull_request.merged == true
runs-on: macos-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Cocoapods
run: gem install cocoapods

- name: Get new version
id: version
run: echo "VERSION=$(ruby -e 'puts File.read("./IONFilesystemLib.podspec").match(/spec.version.*=.*''(\d+\.\d+\.\d+)''/)[1]')" >> $GITHUB_ENV

- name: Extract release notes
run: sh scripts/extract_release_notes.sh "${{ env.VERSION }}" >> release_notes.md

- name: Create Tag
id: create_tag
run: |
# Define the tag name and message
TAG_NAME="${{ env.VERSION }}"
TAG_MESSAGE="Tag for version ${{ env.VERSION }}"
# Create the tag
git tag -a "$TAG_NAME" -m "$TAG_MESSAGE"
git push origin "$TAG_NAME"
echo "Tag created: $TAG_NAME"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create Release
run: |
# Extract the tag name
TAG_NAME="${{ env.VERSION }}"
RELEASE_NOTES="$(cat release_notes.md)"
# Create the release using GitHub CLI
gh release create "$TAG_NAME" \
--title "$TAG_NAME" \
--notes "$RELEASE_NOTES" \
"IONFilesystemLib.zip"
echo "Release created for tag: $TAG_NAME"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Deploy to Cocoapods
run: pod trunk push ./IONFilesystemLib.podspec --allow-warnings
env:
COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }}

- name: Delete Release Branch
run: git push origin --delete prepare-new-release-${{ env.VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output

build/
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
disabled_rules:
- trailing_whitespace
- switch_case_alignment
opt_in_rules:
- empty_count
- empty_string
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Features
- Add read operations, namely `readEntireFile(atURL:withEncoding:)`, `readFileInChunks(atURL:withEncoding:andChunkSize:)`, `listDirectory(atURL:)`, `getItemAttributes(atPath:)` and `getFileURL(atPath: withSearchPath:)`.
- Add write operations, namely `saveFile(atURL:withEncodingAndData:includeIntermediateDirectories:)` and `appendData(_:atURL:includeIntermediateDirectories:)`.
- Add directory operations, namely `createDirectory(atURL:includeIntermediateDirectories:)` and `removeDirectory(atURL:includeIntermediateDirectories:)`.
- Add file management operations, namely `deleteFile(atURL:)`, `renameItem(fromURL:toURL:)` and `copyItem(fromURL:toURL:)`.

### Chores
- Add dependency management contract file for CocoaPods and Swift Package Manager.
- Add GitHub Actions workflows.
- Create Repository
48 changes: 26 additions & 22 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ GEM
artifactory (3.0.17)
atomos (0.1.3)
aws-eventstream (1.3.0)
aws-partitions (1.1034.0)
aws-sdk-core (3.214.1)
aws-partitions (1.1043.0)
aws-sdk-core (3.217.0)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.992.0)
aws-sigv4 (~> 1.9)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.96.0)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sdk-kms (1.97.0)
aws-sdk-core (~> 3, >= 3.216.0)
aws-sigv4 (~> 1.5)
aws-sdk-s3 (1.177.0)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sdk-s3 (1.179.0)
aws-sdk-core (~> 3, >= 3.216.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.5)
aws-sigv4 (1.10.1)
aws-sigv4 (1.11.0)
aws-eventstream (~> 1, >= 1.0.2)
babosa (1.0.4)
base64 (0.2.0)
Expand All @@ -47,10 +47,10 @@ GEM
colored2 (3.1.2)
commander (4.6.0)
highline (~> 2.0.0)
concurrent-ruby (1.3.4)
concurrent-ruby (1.3.5)
connection_pool (2.5.0)
declarative (0.0.20)
digest-crc (0.6.5)
digest-crc (0.7.0)
rake (>= 12.0.0, < 14.0.0)
domain_name (0.6.20240107)
dotenv (2.8.1)
Expand Down Expand Up @@ -171,7 +171,7 @@ GEM
http-cookie (1.0.8)
domain_name (~> 0.5)
httpclient (2.8.3)
i18n (1.14.6)
i18n (1.14.7)
concurrent-ruby (~> 1.0)
jmespath (1.6.2)
json (2.9.1)
Expand All @@ -180,25 +180,27 @@ GEM
logger (1.6.5)
mini_magick (4.13.2)
mini_mime (1.1.5)
mini_portile2 (2.8.8)
minitest (5.25.4)
multi_json (1.15.0)
multipart-post (2.4.1)
nanaimo (0.4.0)
naturally (2.2.1)
nkf (0.2.0)
nokogiri (1.18.1)
mini_portile2 (~> 2.8.2)
nokogiri (1.18.2-aarch64-linux-gnu)
racc (~> 1.4)
nokogiri (1.18.1-aarch64-linux-gnu)
nokogiri (1.18.2-aarch64-linux-musl)
racc (~> 1.4)
nokogiri (1.18.1-arm-linux-gnu)
nokogiri (1.18.2-arm-linux-gnu)
racc (~> 1.4)
nokogiri (1.18.1-arm64-darwin)
nokogiri (1.18.2-arm-linux-musl)
racc (~> 1.4)
nokogiri (1.18.1-x86_64-darwin)
nokogiri (1.18.2-arm64-darwin)
racc (~> 1.4)
nokogiri (1.18.1-x86_64-linux-gnu)
nokogiri (1.18.2-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.18.2-x86_64-linux-gnu)
racc (~> 1.4)
nokogiri (1.18.2-x86_64-linux-musl)
racc (~> 1.4)
optparse (0.6.0)
os (1.1.4)
Expand Down Expand Up @@ -258,12 +260,14 @@ GEM
xcpretty (~> 0.2, >= 0.0.7)

PLATFORMS
aarch64-linux
arm-linux
aarch64-linux-gnu
aarch64-linux-musl
arm-linux-gnu
arm-linux-musl
arm64-darwin
x86-linux
x86_64-darwin
x86_64-linux
x86_64-linux-gnu
x86_64-linux-musl

DEPENDENCIES
fastlane
Expand Down
14 changes: 7 additions & 7 deletions OSFilesystemLib.podspec → IONFilesystemLib.podspec
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
Pod::Spec.new do |spec|
spec.name = 'OSFilesystemLib'
spec.name = 'IONFilesystemLib'
spec.version = '0.0.1'

spec.summary = 'The `OSFilesystemLib` is a template library.'
spec.summary = 'The `IONFilesystemLib` is a template library.'
spec.description = <<-DESC
The `OSFilesystemLib` is a template library.
The `IONFilesystemLib` is a template library.
The `OSFilesystemLib` structure provides the main feature of the Library:
The `IONFilesystemLib` structure provides the main feature of the Library:
- ping: A simple echo function that returns the input string.
DESC

spec.homepage = 'https://github.com/ionic-team/OSFilesystemLib-iOS'
spec.homepage = 'https://github.com/ionic-team/IONFilesystemLib-iOS'
spec.license = { :type => 'MIT', :file => 'LICENSE' }
spec.author = { 'OutSystems Mobile Ecosystem' => '[email protected]' }

spec.source = { :http => "https://github.com/ionic-team/OSFilesystemLib-iOS/releases/download/#{spec.version}/OSFilesystemLib.zip", :type => "zip" }
spec.vendored_frameworks = "OSFilesystemLib.xcframework"
spec.source = { :http => "https://github.com/ionic-team/IONFilesystemLib-iOS/releases/download/#{spec.version}/IONFilesystemLib.zip", :type => "zip" }
spec.vendored_frameworks = "IONFilesystemLib.xcframework"

spec.ios.deployment_target = '14.0'
spec.swift_versions = ['5.0', '5.1', '5.2', '5.3', '5.4', '5.5', '5.6', '5.7', '5.8', '5.9']
Expand Down
Loading

0 comments on commit 055e50b

Please sign in to comment.