Skip to content

Commit

Permalink
Copy all source
Browse files Browse the repository at this point in the history
  • Loading branch information
kpgalligan committed Dec 11, 2024
1 parent 9cd9141 commit 96323ef
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 24 deletions.
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ inputs:
required: false
tagVersion:
description: 'Version string to use in the tag. Should follow semver rules: https://semver.org/.'
required: true
required: false
remoteRepo:
description: 'Repo we are publishing to in [org]/[repo] format.'
required: true
Expand All @@ -25,6 +25,8 @@ inputs:
remoteRepoUrl:
description: 'Full url for the repo we are publishing to. Defaults to "https://github.com/${remoteRepo}.git".'
required: false
packageFileOnly:
description: 'Set to "true" if you only want to share the `Package.swift` file.'
localPackagePath:
description: 'Local path to Package.swift'
required: false
Expand Down
60 changes: 49 additions & 11 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

52 changes: 41 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as core from '@actions/core'
import simpleGit from 'simple-git'

Check failure on line 2 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Using exported name 'simpleGit' as identifier for default export
import * as fs from 'fs'
import * as path from 'node:path'

function notEmpty(p: string | undefined) {

Check failure on line 6 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Missing return type on function
return p && p.trim().length > 0
Expand All @@ -19,6 +20,7 @@ export async function run(): Promise<void> {
const tagVersion: string = core.getInput('tagVersion')
const remoteRepo: string = core.getInput('remoteRepo')
let remoteRepoUrl: string = core.getInput('remoteRepoUrl')
const packageFileOnly: string = core.getInput('packageFileOnly')
let localPackagePath: string = core.getInput('localPackagePath')
let remotePackagePath: string = core.getInput('remotePackagePath')
const remoteBranch: string = core.getInput('remoteBranch')
Expand All @@ -28,6 +30,7 @@ export async function run(): Promise<void> {
core.debug(`tagVersion: ${tagVersion}`)
core.debug(`remoteRepo: ${remoteRepo}`)
core.debug(`remoteRepoUrl: ${remoteRepoUrl}`)
core.debug(`packageFileOnly: ${packageFileOnly}`)
core.debug(`localPackagePath: ${localPackagePath}`)
core.debug(`remotePackagePath: ${remotePackagePath}`)
core.debug(`remoteBranch: ${remoteBranch}`)
Expand All @@ -36,11 +39,11 @@ export async function run(): Promise<void> {
remoteRepoUrl = notEmpty(remoteRepoUrl) ? remoteRepoUrl : `https://github.com/${remoteRepo}.git`

Check failure on line 39 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Replace `·?·remoteRepoUrl` with `⏎····?·remoteRepoUrl⏎···`
localPackagePath = notEmpty(localPackagePath) ? localPackagePath : ''
remotePackagePath = notEmpty(remotePackagePath) ? remotePackagePath : ''
const packageFileOnlyBool = packageFileOnly === 'true'

assertNotEmpty(commitMessage, "'commitMessage' cannot be empty")
assertNotEmpty(tagVersion, "'tagVersion' cannot be empty")
assertNotEmpty(remoteRepo, "'remoteRepo' cannot be empty")
assertNotEmpty(remoteBranch, "'remoteBranch' cannot be empty")
assertNotEmpty(commitMessage, '\'commitMessage\' cannot be empty')

Check failure on line 44 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Replace `'\'commitMessage\'·cannot·be·empty'` with `"'commitMessage'·cannot·be·empty"`
assertNotEmpty(remoteRepo, '\'remoteRepo\' cannot be empty')

Check failure on line 45 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Replace `'\'remoteRepo\'·cannot·be·empty'` with `"'remoteRepo'·cannot·be·empty"`
assertNotEmpty(remoteBranch, '\'remoteBranch\' cannot be empty')

Check failure on line 46 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Replace `'\'remoteBranch\'·cannot·be·empty'` with `"'remoteBranch'·cannot·be·empty"`

try {
const git = simpleGit()
Expand All @@ -49,15 +52,42 @@ export async function run(): Promise<void> {
await git.raw('branch', 'remote_swift_package', 'FETCH_HEAD')
await git.raw('worktree', 'add', '.git/tmp/remote_swift_package', 'remote_swift_package')

Check failure on line 53 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Replace `'worktree',·'add',·'.git/tmp/remote_swift_package',·'remote_swift_package'` with `⏎······'worktree',⏎······'add',⏎······'.git/tmp/remote_swift_package',⏎······'remote_swift_package'⏎····`

const packageSource = fs.readFileSync(`.${localPackagePath}/Package.swift`, 'utf8')
fs.writeFileSync(`.git/tmp/remote_swift_package${remotePackagePath}/Package.swift`, packageSource)
if (packageFileOnlyBool) {
const packageSource = fs.readFileSync(`.${localPackagePath}/Package.swift`, 'utf8')

Check failure on line 56 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Replace ``.${localPackagePath}/Package.swift`,·'utf8'` with `⏎········`.${localPackagePath}/Package.swift`,⏎········'utf8'⏎······`
fs.writeFileSync(`.git/tmp/remote_swift_package${remotePackagePath}/Package.swift`, packageSource)
} else {
const files = fs.readdirSync('.')

for (const file of files) {
if (file === '.git' || file === '.github') {
continue
}

const filePath = path.join('.', file) // Get full path
const stats = fs.statSync(filePath) // Get file stats

if (stats.isFile()) {
fs.copyFileSync(filePath, `.git/tmp/remote_swift_package/${file}`)
console.log(`File: ${filePath}`)
} else if (stats.isDirectory()) {
fs.cpSync(filePath, `.git/tmp/remote_swift_package/${file}`, { recursive: true })
console.log(`Directory: ${filePath}`)
}
}
}

const worktreeGit = simpleGit('.git/tmp/remote_swift_package')
await worktreeGit.raw('fetch', '--tags') // Get release tag
await worktreeGit.add('.')
await worktreeGit.commit(commitMessage)
await worktreeGit.raw('tag', '-fa', tagVersion, '-m', tagMessage)
await worktreeGit.raw('push', '--follow-tags', remoteRepoUrl, `remote_swift_package:${remoteBranch}`)
if (tagVersion) {
await worktreeGit.raw('fetch', '--tags') // Get release tag
await worktreeGit.add('.')
await worktreeGit.commit(commitMessage)
await worktreeGit.raw('tag', '-fa', tagVersion, '-m', tagMessage)
await worktreeGit.raw('push', '--follow-tags', remoteRepoUrl, `remote_swift_package:${remoteBranch}`)
} else {
await worktreeGit.add('.')
await worktreeGit.commit(commitMessage)
await worktreeGit.raw('push', remoteRepoUrl, remoteBranch)
}
} catch (error) {
// Fail the workflow run if an error occurs
if (error instanceof Error) core.setFailed(error.message)
Expand Down

0 comments on commit 96323ef

Please sign in to comment.