Skip to content

Instantly share code, notes, and snippets.

@pwc3
Last active May 12, 2020 02:50
Show Gist options
  • Save pwc3/bfc1144d89275e980c1a6b6ad29985a4 to your computer and use it in GitHub Desktop.
Save pwc3/bfc1144d89275e980c1a6b6ad29985a4 to your computer and use it in GitHub Desktop.
Generate GitRevision.swift for inclusion in an Xcode project
#!/usr/bin/env bash
set -euo pipefail
cat <<SWIFT
//
// GitRevision.swift
//
// This file was automatically generated. Do not edit manually. It will be overwritten on every build.
//
// IMPORTANT: This file must be added to .gitignore or it will dirty the working tree every time there is a build.
//
/// Information about the current Git revision.
struct GitRevision {
/// The name of the current branch.
static let branch = "$(git rev-parse --abbrev-ref HEAD)"
/// The abbreviated hash of the current commit.
static let commit = "$(git rev-parse --short HEAD)"
/// Whether the working tree is clean. If false, indicates that there are uncommitted or untracked files in the working tree.
static let clean = $([[ -z $(git status -s) ]] && echo 'true' || echo 'false')
/// Build timestamp. Set when this file was generated at the beginning of the build process.
static let timestamp = "$(date +%Y-%m-%dT%H:%M:%S)"
/// A string summarizing the current Git revision.
static var description: String {
return "\(commit)\(clean ? "" : "-dirty") \(branch) \(timestamp)"
}
}
SWIFT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment