Swift Package Github Action CI [duplicate] - github

I have swift package for iOS apps (it needs UIKit to run). I wan't to build this package using Github action this is how my workflow looks like
name: Swift
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout#v2
- uses: YOCKOW/Action-setup-swift#master
with:
swift-version: '5.3'
- name: Build
run: swift build -v
- name: Run tests
run: swift test -v
When I run this build I got error: no such module 'UIKit'.
So I have 2 options:
make my package UIKit independent (actually don't know how)
configure build to run on iOS specifically
What should I do?

We're using xcodebuild instead of swift build to do platform specific CI from GitHub Actions. See specific example at https://github.com/firebase/firebase-ios-sdk/blob/master/.github/workflows/spm.yml and https://github.com/firebase/firebase-ios-sdk/blob/master/scripts/build.sh#L540

The simplest approach as of 2022 is to use xcodebuild like stated above.
Condensed to the basics, the script can be as simple as this:
# This workflow will build a Swift project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift
name: Build and Test
on:
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout#v3
# Sanity check to make sure we use a valid device in the next step
- name: List available devices
run: xcrun simctl list devicetypes
#generic/platform=iOS is sufficient for just building, - but need to specify concrete destination for tests
- name: Build and run tests
run: xcodebuild test -scheme YourSchemeNameHere -destination 'platform=iOS Simulator,name=iPhone 13 Pro' #or any other name from the list of sim devices
This is enough to build the project and run tests on it.
In some cases you may need to install a later version of Swift than what's available by default on Github Actions, - you can use a third party step for that and use xcode-select.

Related

Working directory is not working in my Github action

I'm starting to use Github actions. When I ran the process in my Ubuntu server, one of the config options was to select the work folder, by default, I leave _work. But previously, I had my repository in another folder.
So, I'm trying to add a specific value for working-directory to my yml, file but is not using the value in the build process.
YML File:
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
defaults:
run:
working-directory: /../../../../var/www/mysite.com
jobs:
deployment:
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout#v3
- name: Use Node.js
uses: actions/setup-node#v3
with:
node-version: '14.x'
- name: Install dependencies
run: yarn
- name: Build
run: yarn build
- name: Restart server application
run: pm2 restart pm2_script.json
The process ran ok, but is doing all the process (checkout, build, etc) inside _work and not inside working-directory
What I'm doing wrong?
Thanks!!

Getting a issue while setting up the yml file for GithubActions

I am new at using Github Actions,Have written below ios.yml file and getting error like
Error: Process completed with exit code 70. on execution.
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
name: Build and Test default scheme using any available iPhone simulator
runs-on: macos
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Set Default Scheme
run: sudo xcodebuild clean build test -workspace testing.xcworkspace -scheme "testing" -sdk iphonesimulator -destination "platform=iOS Simulator,OS=15.4,name=iphone 8" CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO```
Try removing CODE_SIGN_IDENTITY="" and test

How To Run GitHub Actions - .NET Framework Unit Test

I have a Sample Solution with a simple .NET Framework 4.8 Library Project.
this Solution has also a Unit Test Project for this Library. This Test Project has a Test which will succeed and one Test which will fail.
Now i want to upload this to github and it should Run the Test Project. But i cant figure out, how i can run the Test Project. All Tutorials are for .NET Core 5+
my actual workflow file looks like this:
name: .NET Framework Desktop
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
strategy:
matrix:
configuration: [Release]
runs-on: self-hosted # For a list of available runner types, refer to
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
env:
Solution_Name: SelfHostedPDMTest.sln # Replace with your solution name, i.e. MyWpfApp.sln.
Test_Project_Path: TestProjectTest.csproj # Replace with the path to your test project, i.e. MyWpfApp.Tests\MyWpfApp.Tests.csproj.
Wap_Project_Directory: your-wap-project-directory-name # Replace with the Wap project directory relative to the solution, i.e. MyWpfApp.Package.
Wap_Project_Path: your-wap-project-path # Replace with the path to your Wap project, i.e. MyWpf.App.Package\MyWpfApp.Package.wapproj.
steps:
- name: Checkout
uses: actions/checkout#v3
with:
fetch-depth: 0
# Install the .NET Core workload
- name: Install .NET
uses: actions/setup-dotnet#v2
with:
dotnet-version: 5.0.x
# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild#v1.0.2
# Execute all unit tests in the solution
- name: Execute unit tests
run: dotnet test
# Restore the application to populate the obj folder with RuntimeIdentifiers
- name: Restore the application
run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration
env:
Configuration: ${{ matrix.configuration }}
Appx_Bundle_Platforms: x86|x64
Appx_Package_Build_Mode: StoreUpload
This is a sample Workflow from github.
i know the selected .net version is 5.0.x but 4.8.x is not possible.
and also dotnet test would run a .NET Core Test and not a .NET Framework Test.
Maybe someone has a good workflow file or can help me to start?
Try the below as documented
- name: Run vstests
uses: microsoft/vstest-action#v1.0.0
with:
testAssembly: TestProject.dll
searchFolder: .\TestProject\bin\Debug\
runInParallel: true

How to replace a API key with a Secret in code during Github Actions Job?

I usually hide my API key in an XML file and use .gitignore along with getString() to retrieve my API key.
I'm trying to use Github Actions to automate Gradle build and Release of debug apk's. Due to the XML file not being uploaded to the repo, it obviously fails.
Is there any way to store my key in Github Secrets and then replace the code with the secret?
Current code: headers["token"]= getString(R.string.token)
Replaced code in Github actions server : headers["token"]="MY_API_KEY_FROM_SECRETS"
Here's my YAML file that I was using:
name: Gradle build test and release
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: set up JDK 1.8
uses: actions/setup-java#v1
with:
java-version: 1.8
#I'd like to replace the api key here in code from secrets
- name: Make Gradle executable
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Build Debug APK
run: ./gradlew assembleDebug
- name: Releasing using Hub
uses: ShaunLWM/action-release-debugapk#master
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
APP_FOLDER: app
RELEASE_TITLE: New Build
BODY: github.event.head_commit.message
prerelease: true
Sure, this is possible. You haven't said what file you'd like modified, but this should be easy enough to do with a one-liner (replacing FILENAME with your config file name):
- run: perl -pi -e 's/getString\(R\.string\.token\)/"$ENV{TOKEN}"/' FILENAME
env:
TOKEN: ${{ secrets.TOKEN }}
If you prefer Ruby or some other scripting language, you can use that instead. You could also use sed, but I prefer this approach because it means that the value is never available in ps output (even if this is a locked down VM).

How to build Flutter in GitHub Actions CI/CD

I'm trying out GitHub Actions to build my Flutter app but I don't know which container image to choose from.
Is there a trusted container image that I can use for Flutter?
What are the adjustments I need to make so that the Flutter SDK is available during my build step?
Run flutter pub get
/__w/_temp/46389e95-36bc-464e-ab34-41715eb4dccb.sh: 1: /__w/_temp/46389e95-36bc-464e-ab34-41715eb4dccb.sh: flutter: not found
##[error]Process completed with exit code 127.
I adapted the dart.yml file generated by GitHub Actions to look like this:
name: Dart CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
container:
image: google/dart:latest
steps:
- uses: actions/checkout#v1
- name: Install dependencies
run: flutter pub get
- name: Run tests
run: flutter test
You don't need to use a flutter specific container, there is a Flutter Action available that runs on the default Windows, Linux and macOS containers.
This means that building your flutter app is as simple as using the action (you will also need the Java action) and then running the flutter build command. The following example runs an aot build:
on: push
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
# The flutter action needs java so include it
- uses: actions/setup-java#v1
with:
java-version: '12.x'
# Include the flutter action
- uses: subosito/flutter-action#v1
with:
channel: 'stable'
# Get flutter packages
- run: flutter pub get
# Build :D
- run: flutter build aot
I wrote a blog post about building and testing flutter using actions if you'd like to learn more.
I let my one running without Docker.
You could try to install flutter and run flutter pub get. I used in my example subosito/flutter-action#v1
name: CI
on:
pull_request:
branches:
- development
- master
jobs:
test:
name: Flutter Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- uses: actions/setup-java#v1
with:
java-version: '12.x'
- uses: subosito/flutter-action#v1
with:
flutter-version: '1.7.8+hotfix.4'
- run: flutter doctor
- run: flutter pub get
- run: flutter test
#Rezwan provided the link to the image I was looking for.
I'm still not able to run it due to the following issues:
https://github.com/cirruslabs/docker-images-flutter/issues/27
GitHub Actions workflow error: Cannot create file, path = '/github/home/.flutter'
I leave here a link to the production project with the app in the stores.
Maybe it saves time for somebody, I would be glad to have it when I implement it.
Uses secret keys for signing releases.
Create .apks for different flavors.
Add the build number to the files.
Create a GitHub release.
https://github.com/AgoraDesk-LocalMonero/agoradesk-app-foss/blob/main/.github/workflows/build_from_tags_ci.yml