How to run Xcode tests with yml? - xcode

It seems like it should be pretty simple, I just want to trigger a build and unit tests to be executed every time a developer pushes to their fork. GithubActions.
I’m creating a macOS app.
Here is what I'm trying. It doesn't work.
name: Smoke Test CI
on: [push, merge]
jobs:
build:
runs-on: macOS-latest
steps:
- uses: actions/checkout#v1
- name: Execute full install
- name: Xcodebuild Action
uses: sersoft-gmbh/xcodebuild-action#v1.3

Related

Run firebase emulators + vitest at once

The bounty expires in 7 days. Answers to this question are eligible for a +100 reputation bounty.
ARNON wants to draw more attention to this question:
What should I do to make it work? > I would like to run job 2 as soon as the emulator ports are open and finish job 1 only after job 2 finishes.
I'm trying to run two jobs at the same time.
First I need to run firebase emulators and when the ports are open, I need to run vitest.
This is what I'm doing at the moment:
name: Run Tests
on:
pull_request:
branches: [develop]
workflow_dispatch:
jobs:
job1:
name: Run Emulator
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- name: Use Node.js 18.14.0
uses: actions/setup-node#v3
with:
node-version: 18.14.0
cache: 'npm'
- name: Execute Emulator
env:
VITE_RELEASE_STAGE: testing
run: |
npm ci
npm install --save firebase-tools
npm run emulators
job2:
name: Run Unit Tests
needs: job1
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- name: Use Node.js 18.14.0
uses: actions/setup-node#v3
with:
node-version: 18.14.0
cache: 'npm'
- name: Execute Unit Tests
env:
VITE_RELEASE_STAGE: testing
run: |
npm ci
npm run test
The doors open perfectly, but the second job never runs.
Here lies my doubt. Because if I don't use needs the two will run at the same time and I will get an error in job2 because the ports will not be open in job 1.
I would like to run job 2 as soon as the emulator ports are open and finish job 1 only after job 2 finishes.
Does anyone know how I can resolve this?
EDIT
These are the two executed scripts that are in my package.json:
"test": "vitest",
"emulators": "firebase emulators:start --project celebrityfanalizer --import emulatorData"

GitHub Actions Matrix sharing the Same Code CheckOut

I tried to perform step actions/checkout#v3 once on chained jobs, but it seems like the "build" job does not get the code. I'm getting an error "can't find the project".
Can I call actions/checkout # v3 once for two jobs?
It works when I call the code checkout twice.
name: publish-nuget
on:
push:
branches:
- main
jobs:
prepare:
runs-on: ubuntu-latest
- name: Checkout code
uses: actions/checkout#v3
- name: Get package version
id: get_package_version
uses: kzrnm/get-net-sdk-project-versions-action#v1.3.0
with:
proj-path: ProjectOne.csproj
build:
needs: prepare
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout#v3
# Add the projects path below
strategy:
matrix:
projects: [
'ProjectOne.csproj',
'ProjectTwo.csproj',
]
steps:
- name: Pack NuGet
run: dotnet pack ${{ matrix.projects }} -p:PackageVersion=${{ env.PACKAGE_VERSION }} --configuration Release
It does not work when I call the code checkout once (on the 'prepare' job).
name: publish-nuget
on:
push:
branches:
- main
jobs:
prepare:
runs-on: ubuntu-latest
- name: Checkout code
uses: actions/checkout#v3
- name: Get package version
id: get_package_version
uses: kzrnm/get-net-sdk-project-versions-action#v1.3.0
with:
proj-path: ProjectOne.csproj
build:
needs: prepare
runs-on: ubuntu-latest
steps:
# Add the projects path below
strategy:
matrix:
projects: [
'ProjectOne.csproj',
'ProjectTwo.csproj',
]
steps:
- name: Pack NuGet
run: dotnet pack ${{ matrix.projects }} -p:PackageVersion=${{ env.PACKAGE_VERSION }} --configuration Release
Having a job being dependent on another job, is just for logical purposes and not state or artifact dependency sharing. You are actually runing the 2 jobs on 2 different agents. If you want to share something from the prepare job, you can use the cache or artifact API. E.g. using the cache API to cache the path 'somePath'. Same step for downloading the cache.
- name: Cached build artifacts
uses: actions/cache#v2
id: artifactcache
with:
path: somePath
key: buildArtifacts${{ github.run_number}}
As you are not gaining anything form splitting this up into 2 jobs, I would run everything in a single job instead.

How to run cron jobs in github action for a particular day and time

How to run cron jobs automatically every Thursday at 10:30 am Australian Standard time irrespective of any other action? I have tried the below, but not sure if it's running. Could someone please advise?
I have the schedule.yml file in my branch.
Should I add the schedule.yml somewhere else?
Branch: cypress-schedule-test-ci-100
.github\workflows\schedule.yml
name: Cypress E2E Tests
on:
schedule:
- cron: "30 10 * * 4"
env:
CYPRESS_BOOKING_PASSWORD: ${{ secrets.CYPRESS_BOOKING_PASSWORD }}
CYPRESS_BOOKING_FREE_USER_PASSWORD: ${{ secrets.CYPRESS_BOOKING_FREE_USER_PASSWORD }}
jobs:
install:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Install dependencies
uses: cypress-io/github-action#v2
with:
# just perform install
runTests: false
tests:
runs-on: ubuntu-22.04
needs: install
steps:
- name: Check out code
uses: actions/checkout#v2
- name: Install dependencies
uses: cypress-io/github-action#v2
with:
# perform installation
runTests: false
- name: Run E2E tests
run: npm run cy:run -- --env grepTags="#MainUITests+-#Failing",ENV="qaserver" --browser chrome
- name: Upload Results
uses: actions/upload-artifact#v3
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots
- uses: actions/upload-artifact#v2
if: always()
with:
name: cypress-videos
path: cypress/videos
While working with the schedule cron job, the following points need to keep in mind:
You can schedule a workflow to run at specific UTC times using POSIX cron syntax.
So, you might need to adjust it according to your time zone.
Scheduled workflows run on the latest commit on the default or base branch.
It should be scheduled for the default branch e.g. main. Apparently, this seems to be the reason why your scheduled job isn't working.
And,
Note: The schedule event can be delayed during periods of high loads of GitHub Actions workflow runs. High load times include the start of every hour. To decrease the chance of delay, schedule your workflow to run at a different time of the hour.
You need to account for such delays due to high loads.

GitHub Actions restrict job with tag validation using if condition or github ref

I have an application code which runs the maven builds we created snapshots and then create a tag created once the snapshot build is successful, and then we use the tag created in the snapshot build and then run the build using the tag for release using the GitHub actions workflows.
now I'm trying to run the release of the build workflow job only if the tag as matching and if the tag, not matches, skip the jobs or fails the jobs, let's say the tag will be created in the snapshot build and will use tag format as "<appname>-<app_build_type>-<github-actions-run_number>-<env>-origin/<branch>" and the actual tag looks like "java-maven-44-dev-origin/develop"
I was trying the below 2 methods workflows, but it is not at all working
1st Method is:
name: maven-release
on:
workflow_dispatch:
jobs:
checkout_code:
runs-on: [ubuntu-latest]
steps:
- name: Checkout
uses: actions/checkout#v3
with:
fetch-depth: 0
maven_build:
runs-on: [ubuntu-latest]
if: ${{ github.ref == 'refs/tags/*-origin/develop' }}
needs: checkout_code
steps:
- name: Run maven build
run: |
mvn clean install
2nd Method is:
name: maven-release
on:
workflow_dispatch:
jobs:
checkout_code:
runs-on: [ubuntu-latest]
steps:
- name: Checkout
uses: actions/checkout#v3
with:
fetch-depth: 0
maven_build:
runs-on: [ubuntu-latest]
if: contains(github.ref, 'refs/tags/*-origin/develop')
needs: checkout_code
steps:
- name: Run maven build
run: |
mvn clean install
I want to skip/fail the at job level only and no in run command, if anyone knows any solution to this or anyone can provide some suggestions on how to achieve this
Its it's possible for your use case, you could trigger your workflow on push and then apply your filter to the branch or tag
name: maven-release
on:
workflow_dispatch:
push:
tags:
- '*-origin/develop'
jobs:
checkout_code:
runs-on: [ubuntu-latest]
steps:
- name: Checkout
uses: actions/checkout#v3
with:
fetch-depth: 0
maven_build:
runs-on: [ubuntu-latest]
if: ${{ github.ref == 'refs/tags/*-origin/develop' }}
needs: checkout_code
steps:
- name: Run maven build
run: |
mvn clean install
The Github filter pattern cheat sheet
For the workflows for which each task needs to be executed only on a particular tag, then we can make use of below snipped
name: maven_build
on:
workflow_dispatch:
jobs:
checkout:
runs-on: [ubuntu-latest]
steps:
- name: Checkout
uses: actions/checkout#v3
with:
fetch-depth: 0
maven_build:
runs-on: [ubuntu-latest]
if: startsWith(github.ref, 'refs/tags/') && !contains(github.ref')
needs: checkout
steps:
- name: Run maven build command
run: |
mvn clean install
The above snippet will run only when the checkout branch matches a tag

How to stop GitHub Action build when SonarQube scan fails

I have a scan step built into my GitHub Action build and that is working fine. I reach out to my company's SonarQub instance and the scan is initiated. The problem I am having is trying to stop a build if there is a failure. For the life of me I can't seem to find a way to do that. Also, when I watch the scan it appears as though the next steps might be happening before it finishes (not positive on that but thought I would mention it). Any ideas??
name: Build, test, & deploy
on: [push]
jobs:
sonarqube:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
# Triggering SonarQube analysis as results of it are required by Quality Gate check
- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action#master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
- name: SonarQube Quality Gate check
uses: sonarsource/sonarqube-quality-gate-action#master
# Force to fail step after specific time
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ secrets.ADAM_SONAR_TOKEN }}
build:
name: Project build & package
if: "!contains(github.even.head_commit.message, '[skip-ci]')"
runs-on: ubuntu-latest
env:
#environment var for this job
#### the rest of the build is below this area - I didn't think it was necessary to include
You should use needs in your build job:
build:
needs: sonarqube
name: Project build & package
You can find information here: https://docs.github.com/en/actions/using-jobs/using-jobs-in-a-workflow
The answer is using "needs": https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idneeds

Resources