# Develop GitHub Actions with Swift

I am an avid fan and user of GitHub Actions. Actions are individual tasks that you can combine to create jobs and customize your CI/CD workflow.

You can write your own actions to use in your workflow and share those actions with the GitHub community.

You cannot literally write GitHub actions exclusively in Swift as actions are natively  Docker container actions or JavaScript actions.

| Type      | Operating system      |
|------------|-------------|
| Docker container | Linux |
| JavaScript         | Linux, macOS, Windows            |

But you can use Swift to build large portions of your GitHub action. Here is a proposal on how to do it:

![Untitled Diagram-3.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1614209216807/zMmEF-LbQ.png)

A good example is the  [swift-create-xcframework](https://github.com/unsignedapps/swift-create-xcframework)  GitHub Action.

%[https://github.com/unsignedapps/swift-create-xcframework]

In its  [action.yml](https://github.com/unsignedapps/swift-create-xcframework/blob/main/action.yml) file you see that the action is built with JavaScript.

```xml
runs:
  using: node12
  main: action.js
```

But the javascript code only parses the options and the heavy lifting is delegated to a particular [Swift package](https://github.com/unsignedapps/swift-create-xcframework/blob/main/Package.swift) which resides in the same repository.

In order to install a Swift package first use [Homebrew](https://brew.sh) to install [Mint](https://github.com/yonaskolb/Mint).

```Javascript
// install mint if its not installed
await installUsingBrewIfRequired("mint")

async function installUsingBrewIfRequired (package) {
    if (await isInstalled(package)) {
        core.info(package + " is already installed.")

    } else {
        core.info("Installing " + package)
        await exec.exec('brew', [ 'install', package ])
    }
}
```

Mint is able to install executable Swift packages and therefore is used to install the Swift package which is co-located with the action code.

```JavaScript
// install ourselves if not installed
await installUsingMintIfRequired('swift-create-xcframework', 'unsignedapps/swift-create-xcframework')

async function installUsingMintIfRequired (command, package) {
    if (await isInstalled(command)) {
        core.info(command + " is already installed")

    } else {
        core.info("Installing " + package)
        await exec.exec('mint', [ 'install', 'unsignedapps/swift-create-xcframework@' + scxVersion ])
    }
}
```

Finally the executable Swift package gets called.
```Javascript
await exec.exec('swift-create-xcframework', options)
```

I hope this recipe is helpful for people who wondered how to leverage their Swift expertise when it comes to GitHub action development.
 
