From f04591ef8bb50ce08a800c89248d7f651e99fae8 Mon Sep 17 00:00:00 2001 From: Bartosz Polaczyk Date: Sat, 4 Sep 2021 18:58:09 +0200 Subject: [PATCH 1/8] Add Github workflows CI --- .github/workflows/ci.yaml | 27 +++++++++++++++++++++++++++ .gitignore | 1 + Rakefile | 19 +------------------ 3 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..04d4958 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,27 @@ +name: CI + +on: [pull_request] + +jobs: + SwiftLint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: SwiftLint + uses: norio-nomura/action-swiftlint@3.1.0 + with: + args: --strict + + macOS: + runs-on: macOS-latest + env: + XCODE_VERSION: ${{ '12.4' }} + steps: + - name: Select Xcode + run: "sudo xcode-select -s /Applications/Xcode_$XCODE_VERSION.app" + - name: Checkout + uses: actions/checkout@v1 + - name: Build and Run + run: rake build[release] + - name: Test + run: rake test diff --git a/.gitignore b/.gitignore index 17c8d90..22ad899 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /*.xcodeproj DerivedData /.swiftpm/ +releases \ No newline at end of file diff --git a/Rakefile b/Rakefile index 3776079..51ec022 100644 --- a/Rakefile +++ b/Rakefile @@ -1,32 +1,15 @@ # encoding: utf-8 -require 'open-uri' -require 'shellwords' ################################ # Rake configuration ################################ -# Make sure environment is UTF-8 (CI sometimes thinks it's ASCII) -ENV['LANG'] = 'en_US.UTF-8' -ENV['LANGUAGE'] = 'en_US.UTF-8' -ENV['LC_ALL'] = 'en_US.UTF-8' -Encoding.default_external = Encoding::UTF_8 -Encoding.default_internal = Encoding::UTF_8 - -# Environment variables (you can override those by adding parameters -# to task definitions in buildconf/tasks) -CONFIG = ENV['CONFIG'] || 'debug' -CI = !!ENV['TEAMCITY_VERSION'] -GIT_REF = ENV['GITHUB_REF'] - # Paths DERIVED_DATA_DIR = File.join('.build').freeze RELEASES_ROOT_DIR = File.join('releases').freeze EXECUTABLE_NAME = 'XCRemoteCache' EXECUTABLE_NAMES = ['xclibtool', 'xcpostbuild', 'xcprebuild', 'xcprepare', 'xcswiftc', 'xcld'] -SCHEME = 'XCRemoteCacheApp' -TEST_SCHEME = 'XCRemoteCacheTests' PROJECT_NAME = 'XCRemoteCache' SWIFTLINT_ENABLED = true @@ -58,7 +41,7 @@ end desc 'build package artifacts' task :build, [:configuration, :sdks] do |task, args| # Set task defaults - args.with_defaults(:configuration => CONFIG.downcase, :sdks => ['macos']) + args.with_defaults(:configuration => 'debug', :sdks => ['macos']) unless args.configuration == 'Debug'.downcase || args.configuration == 'Release'.downcase fail("Unsupported configuration. Valid values: ['Debug', 'Release']. Found '#{args.configuration}''") From 890777b7613570fafc4301805a986d54bb91d35a Mon Sep 17 00:00:00 2001 From: Bartosz Polaczyk Date: Sat, 4 Sep 2021 19:06:42 +0200 Subject: [PATCH 2/8] Fix Rake testing invocation --- Rakefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index 51ec022..17e401d 100644 --- a/Rakefile +++ b/Rakefile @@ -88,8 +88,7 @@ def spm_build(configuration) end def bash(command) - escaped_command = Shellwords.escape(command) - system "bash -c #{escaped_command}" + system "bash -c \"#{command}\"" end def spm_test() From 45cae2b411772ff8d8b94c9331db19f3a4f1f6a9 Mon Sep 17 00:00:00 2001 From: Bartosz Polaczyk Date: Sat, 4 Sep 2021 19:12:13 +0200 Subject: [PATCH 3/8] Prepare arch support --- Rakefile | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Rakefile b/Rakefile index 17e401d..ed01c90 100644 --- a/Rakefile +++ b/Rakefile @@ -39,7 +39,7 @@ task :autocorrect => [:prepare] do end desc 'build package artifacts' -task :build, [:configuration, :sdks] do |task, args| +task :build, [:configuration, :arch, :sdks, :is_archive] do |task, args| # Set task defaults args.with_defaults(:configuration => 'debug', :sdks => ['macos']) @@ -54,7 +54,7 @@ task :build, [:configuration, :sdks] do |task, args| # Build build_paths = [] args.sdks.each do |sdk| - spm_build(args.configuration) + spm_build(args.configuration, args.arch) # Path of the executable looks like: `.build/(debug|release)/XCRemoteCache` build_path_base = File.join(DERIVED_DATA_DIR, args.configuration) @@ -67,7 +67,7 @@ task :build, [:configuration, :sdks] do |task, args| if args.configuration == 'Release'.downcase puts "Creating release zip" - package = create_release_zip(build_paths[0]) + create_release_zip(build_paths[0]) end end @@ -81,9 +81,12 @@ end # Helper functions ################################ -def spm_build(configuration) +def spm_build(configuration, arch) spm_cmd = "swift build "\ "-c #{configuration}" + "#{arch.nil? ? "" : "--triple #{arch}"} "\ + "--disable-sandbox" + p spm_cmd system(spm_cmd) or abort "Build failure" end @@ -102,14 +105,19 @@ end def create_release_zip(build_paths) release_dir = RELEASES_ROOT_DIR - output_artifact_basename = "#{PROJECT_NAME}.zip" - library_file = File.join(release_dir, output_artifact_basename) - + # Create and move files into the release directory mkdir_p release_dir build_paths.each {|p| cp_r p, release_dir } + + # Get the current version from the Swift Version file + version = get_version + unless version + fail("Version not found") + end + output_artifact_basename = "#{PROJECT_NAME}-#{version}.zip" Dir.chdir(release_dir) do # -X: no extras (uid, gid, file times, ...) @@ -118,5 +126,8 @@ def create_release_zip(build_paths) # List contents of zip file system("unzip -l #{output_artifact_basename}") or abort "unzip failure" end - library_file +end + +def get_version + "0.2.26" end From 381294ea630e4ade633fe84e6196843d771989bb Mon Sep 17 00:00:00 2001 From: Bartosz Polaczyk Date: Sat, 4 Sep 2021 19:17:03 +0200 Subject: [PATCH 4/8] Disable strict swiftlint check --- .github/workflows/ci.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 04d4958..733f488 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,8 +9,6 @@ jobs: - uses: actions/checkout@v1 - name: SwiftLint uses: norio-nomura/action-swiftlint@3.1.0 - with: - args: --strict macOS: runs-on: macOS-latest From 141b919ba703efccc416c126a6d0978c70b165f4 Mon Sep 17 00:00:00 2001 From: Bartosz Polaczyk Date: Sun, 5 Sep 2021 21:55:49 +0200 Subject: [PATCH 5/8] Add releasing actions --- .github/workflows/release.yaml | 46 ++++++++++++++++++++++++++++++++++ .gitignore | 3 ++- Rakefile | 16 +++--------- 3 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..76dd7d8 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,46 @@ +name: release_binaries +on: + release: + types: created + +jobs: + macOS: + name: Add macOS binaries to release + runs-on: macOS-latest + env: + XCODE_VERSION: ${{ '12.4' }} + steps: + - name: Select Xcode + run: "sudo xcode-select -s /Applications/Xcode_$XCODE_VERSION.app" + - name: Checkout + uses: actions/checkout@v1 + - name: Set tag name + run: echo "TAG_NAME=$(echo $GITHUB_REF | cut -c 11-)" >> $GITHUB_ENV + - name: Build x86_64-apple-macosx + run: "rake 'build[release, x86_64-apple-macosx]'" + - name: Save x86_64 executable to be lipo'd later + run: "mkdir -p tmp && unzip releases/XCRemoteCache.zip -d tmp/xcremotecache-x86_64" + - name: Clean releases dir to not conflict with other archs + run: "rm -rf releases" + - name: Build arm64-apple-macosx + run: "rake 'build[release, arm64-apple-macosx]'" + - name: Save arm64 executable to be lipo'd later + run: "mkdir -p tmp && unzip releases/XCRemoteCache.zip -d tmp/xcremotecache-arm64" + - name: Clean releases dir to not conflict with other files to attach + run: "rm -rf releases" + - name: Zip x86_64-apple-macosx release + run: "mkdir -p releases && zip -j releases/XCRemoteCache-macOS-x86_64-$TAG_NAME.zip LICENSE README.md tmp/xcremotecache-x86_64/*" + - name: Zip arm64-apple-macosx release + run: "zip -j releases/XCRemoteCache-macOS-arm64-$TAG_NAME.zip LICENSE README.md tmp/xcremotecache-arm64/*" + - name: Lipo macOS executables + run: "mkdir -p tmp/xcremotecache && ls tmp/xcremotecache-x86_64 | xargs -I {} lipo -create -output tmp/xcremotecache/{} tmp/xcremotecache-x86_64/{} tmp/xcremotecache-arm64/{}" + - name: Zip x86_64-arm64-apple-macosx release + run: "zip -j releases/XCRemoteCache-macOS-arm64-x86_64-$TAG_NAME.zip LICENSE README.md tmp/xcremotecache/*" + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v1-release + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: releases/* + file_glob: true + tag: ${{ github.ref }} + overwrite: true diff --git a/.gitignore b/.gitignore index 22ad899..8f32b09 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ /*.xcodeproj DerivedData /.swiftpm/ -releases \ No newline at end of file +releases +tmp/ \ No newline at end of file diff --git a/Rakefile b/Rakefile index ed01c90..1fa46c9 100644 --- a/Rakefile +++ b/Rakefile @@ -83,7 +83,7 @@ end def spm_build(configuration, arch) spm_cmd = "swift build "\ - "-c #{configuration}" + "-c #{configuration} "\ "#{arch.nil? ? "" : "--triple #{arch}"} "\ "--disable-sandbox" p spm_cmd @@ -112,22 +112,14 @@ def create_release_zip(build_paths) cp_r p, release_dir } - # Get the current version from the Swift Version file - version = get_version - unless version - fail("Version not found") - end - output_artifact_basename = "#{PROJECT_NAME}-#{version}.zip" + output_artifact_basename = "#{PROJECT_NAME}.zip" Dir.chdir(release_dir) do # -X: no extras (uid, gid, file times, ...) + # -x: exclude .DS_Store # -r: recursive - system("zip -X -r #{output_artifact_basename} .") or abort "zip failure" + system("zip -X -x '*.DS_Store' -r #{output_artifact_basename} .") or abort "zip failure" # List contents of zip file system("unzip -l #{output_artifact_basename}") or abort "unzip failure" end end - -def get_version - "0.2.26" -end From 571c1a72f4da38d0ab13e98b1473de34208c36d4 Mon Sep 17 00:00:00 2001 From: Bartosz Polaczyk Date: Mon, 6 Sep 2021 07:51:46 +0200 Subject: [PATCH 6/8] Include add binaries in zip --- .github/workflows/release.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 76dd7d8..64ea809 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -29,13 +29,13 @@ jobs: - name: Clean releases dir to not conflict with other files to attach run: "rm -rf releases" - name: Zip x86_64-apple-macosx release - run: "mkdir -p releases && zip -j releases/XCRemoteCache-macOS-x86_64-$TAG_NAME.zip LICENSE README.md tmp/xcremotecache-x86_64/*" + run: "mkdir -p releases && zip -jr releases/XCRemoteCache-macOS-x86_64-$TAG_NAME.zip LICENSE README.md tmp/xcremotecache-x86_64" - name: Zip arm64-apple-macosx release - run: "zip -j releases/XCRemoteCache-macOS-arm64-$TAG_NAME.zip LICENSE README.md tmp/xcremotecache-arm64/*" + run: "zip -jr releases/XCRemoteCache-macOS-arm64-$TAG_NAME.zip LICENSE README.md tmp/xcremotecache-arm64" - name: Lipo macOS executables run: "mkdir -p tmp/xcremotecache && ls tmp/xcremotecache-x86_64 | xargs -I {} lipo -create -output tmp/xcremotecache/{} tmp/xcremotecache-x86_64/{} tmp/xcremotecache-arm64/{}" - name: Zip x86_64-arm64-apple-macosx release - run: "zip -j releases/XCRemoteCache-macOS-arm64-x86_64-$TAG_NAME.zip LICENSE README.md tmp/xcremotecache/*" + run: "zip -jr releases/XCRemoteCache-macOS-arm64-x86_64-$TAG_NAME.zip LICENSE README.md tmp/xcremotecache" - name: Upload binaries to release uses: svenstaro/upload-release-action@v1-release with: From 4ea6c2b33dd2847e31c01a0703d03d1450166232 Mon Sep 17 00:00:00 2001 From: Bartosz Polaczyk Date: Mon, 6 Sep 2021 08:15:56 +0200 Subject: [PATCH 7/8] Disable SPM sandbox --- Rakefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index 1fa46c9..f366603 100644 --- a/Rakefile +++ b/Rakefile @@ -84,9 +84,7 @@ end def spm_build(configuration, arch) spm_cmd = "swift build "\ "-c #{configuration} "\ - "#{arch.nil? ? "" : "--triple #{arch}"} "\ - "--disable-sandbox" - p spm_cmd + "#{arch.nil? ? "" : "--triple #{arch}"} " system(spm_cmd) or abort "Build failure" end From 5a313594e545dff3998284100cd848456057a6cb Mon Sep 17 00:00:00 2001 From: Bartosz Polaczyk Date: Mon, 6 Sep 2021 08:21:17 +0200 Subject: [PATCH 8/8] Add CI badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d66a314..a15969d 100755 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ XCRemoteCache is a remote cache tool for Xcode projects. It reuses target artifacts generated on a remote machine, served from a simple REST server. +[![Build Status](https://github.com/spotify/XCRemoteCache/workflows/CI/badge.svg)](https://github.com/spotify/XCRemoteCache/workflows/CI/badge.svg) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) ## How and Why?