Skip to content

Commit 613110b

Browse files
Merge pull request #272 from StartAutomating/ugit-docker
ugit 0.4.4
2 parents e61bd78 + 7f29524 commit 613110b

23 files changed

+814
-39
lines changed

.github/workflows/TestAndPublish.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,43 @@ jobs:
594594
- name: PSA
595595
uses: StartAutomating/PSA@main
596596
id: PSA
597+
- name: Log in to the Container registry (on branch)
598+
uses: docker/login-action@master
599+
with:
600+
registry: ${{ env.REGISTRY }}
601+
username: ${{ github.actor }}
602+
password: ${{ secrets.GITHUB_TOKEN }}
603+
- name: Extract Docker Metadata (for branch)
604+
if: ${{github.ref_name != 'main' && github.ref_name != 'master' && github.ref_name != 'latest'}}
605+
id: meta
606+
uses: docker/metadata-action@master
607+
with:
608+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
609+
- name: Extract Docker Metadata (for main)
610+
if: ${{github.ref_name == 'main' || github.ref_name == 'master' || github.ref_name == 'latest'}}
611+
id: metaMain
612+
uses: docker/metadata-action@master
613+
with:
614+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
615+
flavor: latest=true
616+
- name: Build and push Docker image (from main)
617+
if: ${{github.ref_name == 'main' || github.ref_name == 'master' || github.ref_name == 'latest'}}
618+
uses: docker/build-push-action@master
619+
with:
620+
context: .
621+
push: true
622+
tags: ${{ steps.metaMain.outputs.tags }}
623+
labels: ${{ steps.metaMain.outputs.labels }}
624+
- name: Build and push Docker image (from branch)
625+
if: ${{github.ref_name != 'main' && github.ref_name != 'master' && github.ref_name != 'latest'}}
626+
uses: docker/build-push-action@master
627+
with:
628+
context: .
629+
push: true
630+
tags: ${{ steps.meta.outputs.tags }}
631+
labels: ${{ steps.meta.outputs.labels }}
597632
env:
598633
AT_PROTOCOL_HANDLE: mrpowershell.bsky.social
599634
AT_PROTOCOL_APP_PASSWORD: ${{ secrets.AT_PROTOCOL_APP_PASSWORD }}
635+
REGISTRY: ghcr.io
636+
IMAGE_NAME: ${{ github.repository }}

Build/GitHub/Jobs/buildugit.psd1

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,56 @@
2828
name = 'PSA'
2929
uses = 'StartAutomating/PSA@main'
3030
id = 'PSA'
31+
},
32+
@{
33+
'name'='Log in to the Container registry (on branch)'
34+
'uses'='docker/login-action@master'
35+
'with'=@{
36+
'registry'='${{ env.REGISTRY }}'
37+
'username'='${{ github.actor }}'
38+
'password'='${{ secrets.GITHUB_TOKEN }}'
39+
}
40+
},
41+
@{
42+
name = 'Extract Docker Metadata (for branch)'
43+
if = '${{github.ref_name != ''main'' && github.ref_name != ''master'' && github.ref_name != ''latest''}}'
44+
'id'='meta'
45+
'uses'='docker/metadata-action@master'
46+
'with'=@{
47+
'images'='${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}'
48+
}
49+
},
50+
@{
51+
name = 'Extract Docker Metadata (for main)'
52+
if = '${{github.ref_name == ''main'' || github.ref_name == ''master'' || github.ref_name == ''latest''}}'
53+
'id'='metaMain'
54+
'uses'='docker/metadata-action@master'
55+
'with'=@{
56+
'images'='${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}'
57+
'flavor'='latest=true'
58+
}
59+
},
60+
@{
61+
name = 'Build and push Docker image (from main)'
62+
if = '${{github.ref_name == ''main'' || github.ref_name == ''master'' || github.ref_name == ''latest''}}'
63+
uses = 'docker/build-push-action@master'
64+
'with'=@{
65+
'context'='.'
66+
'push'='true'
67+
'tags'='${{ steps.metaMain.outputs.tags }}'
68+
'labels'='${{ steps.metaMain.outputs.labels }}'
69+
}
70+
},
71+
@{
72+
name = 'Build and push Docker image (from branch)'
73+
if = '${{github.ref_name != ''main'' && github.ref_name != ''master'' && github.ref_name != ''latest''}}'
74+
uses = 'docker/build-push-action@master'
75+
with = @{
76+
'context'='.'
77+
'push'='true'
78+
'tags'='${{ steps.meta.outputs.tags }}'
79+
'labels'='${{ steps.meta.outputs.labels }}'
80+
}
3181
}
3282
)
3383
}

Build/ugit.GitHubWorkflow.PSDevOps.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ Push-Location ($PSScriptRoot | Split-Path)
88
New-GitHubWorkflow -Name "Analyze, Test, Tag, and Publish" -On Push, PullRequest, Demand -Job PowerShellStaticAnalysis,
99
TestPowerShellOnLinux,
1010
TagReleaseAndPublish,
11-
buildugit -OutputPath .\.github\workflows\TestAndPublish.yml -Env @{
11+
buildugit -OutputPath .\.github\workflows\TestAndPublish.yml -Env ([Ordered]@{
1212
"AT_PROTOCOL_HANDLE" = "mrpowershell.bsky.social"
1313
"AT_PROTOCOL_APP_PASSWORD" = '${{ secrets.AT_PROTOCOL_APP_PASSWORD }}'
14-
}
14+
"REGISTRY" = "ghcr.io"
15+
"IMAGE_NAME" = '${{ github.repository }}'
16+
})
1517

1618
New-GitHubWorkflow -On Issue,
1719
Demand -Job RunGitPub -Name OnIssueChanged -OutputPath .\.github\workflows\OnIssue.yml

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
## ugit 0.4.4:
2+
3+
> Like It? [Star It](https://github.com/StartAutomating/ugit)
4+
> Love It? [Support It](https://github.com/sponsors/StartAutomating)
5+
6+
* ugit a container! (#262, #263, #264)
7+
* `docker run --interactive --tty ghcr.io/startautomating/ugit`
8+
* `git checkout` improvements
9+
* `git checkout -PullRequest [int]` (#178)
10+
* `git checkout -NewBranchName [string]` (#266)
11+
* `git checkout -ResetBranchName [string]` (#267)
12+
* `git checkout -Detach [switch]` (#268)
13+
* `git checkout -ResetPath [string]` (#269)
14+
* `git checkout -FromBranch [string]` (#270)
15+
* `git checkout -RevisionNumber/-ParentNumber [int]` (#271)
16+
* `git sparse-checkout` improvements
17+
* `git sparse-checkout -FileFilter [string[]]` ( Fixes #257 )
18+
* `git sparse-checkout -DirectoryFilter [string[]]` ( Fixes #258 )
19+
* `git branch -Remote [switch]` (#185)
20+
* `git config --list` outputs as objects (#265)
21+
* `git --format json` outputs as objects (#239)
22+
23+
---
24+
125
## ugit 0.4.3:
226

327
* Cloning Improvements:

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
FROM mcr.microsoft.com/powershell
2+
3+
RUN apt-get update && apt-get install -y git curl ca-certificates libc6 libgcc1
4+
25
ENV PSModulePath ./Modules
6+
37
COPY . ./Modules/ugit
4-
RUN pwsh -c "New-Item -Path /root/.config/powershell/Microsoft.PowerShell_profile.ps1 -Value 'Import-Module ugit' -Force"
5-
RUN apt-get update && apt-get install -y git curl ca-certificates libc6 libgcc1
68

9+
RUN pwsh -c "New-Item -ItemType File -Path \$Profile -Force -Value 'Import-Module ugit'"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<#
2+
.SYNOPSIS
3+
git branch input extension
4+
.DESCRIPTION
5+
Extends the parameters for git branch, making it easier to use from PowerShell.
6+
.EXAMPLE
7+
git branch -Remote
8+
#>
9+
[ValidatePattern('^git branch')]
10+
[Management.Automation.Cmdlet("Use","Git")]
11+
[CmdletBinding(PositionalBinding=$false)]
12+
param(
13+
# If set, will add the --remote flag to the command.
14+
[Parameter(ValueFromPipelineByPropertyName)]
15+
[Alias('Remotes')]
16+
[switch]
17+
$Remote
18+
)
19+
20+
if ($Remote) {
21+
"--remote"
22+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<#
2+
.SYNOPSIS
3+
git checkout input extension
4+
.DESCRIPTION
5+
Extends the parameters for git checkout, making it easier to use from PowerShell.
6+
7+
If the -PullRequest parameter is provided, the branch will be fetched from the remote.
8+
9+
If the -BranchName parameter is provided, the branch will be checked out.
10+
#>
11+
[ValidatePattern('^git checkout')]
12+
[Management.Automation.Cmdlet("Use","Git")]
13+
[CmdletBinding(PositionalBinding=$false)]
14+
param(
15+
# The branch name.
16+
[Parameter(ValueFromPipelineByPropertyName)]
17+
[string]
18+
$BranchName,
19+
20+
# The number of the pull request.
21+
# If no Branch Name is provided, the branch will be `PR-$PullRequest`.
22+
[Parameter(ValueFromPipelineByPropertyName)]
23+
[int]
24+
$PullRequest,
25+
26+
# The name of a new branch
27+
[Parameter(ValueFromPipelineByPropertyName)]
28+
[Alias('New','NewBranch')]
29+
[string]
30+
$NewBranchName,
31+
32+
# The name of a branch to reset.
33+
[Parameter(ValueFromPipelineByPropertyName)]
34+
[Alias('ResetBranch')]
35+
[string]
36+
$ResetBranchName,
37+
38+
# One or more specific paths to reset.
39+
# This will overwrite the contents of the files with the contents of the index.
40+
[Parameter(ValueFromPipelineByPropertyName)]
41+
[Alias('Reset')]
42+
[string[]]
43+
$ResetPath,
44+
45+
# The name of the branch to checkout from.
46+
# This is only used when the -ResetPath parameter is provided.
47+
# It defaults to `HEAD`.
48+
[Parameter(ValueFromPipelineByPropertyName)]
49+
[string]
50+
$FromBranch = 'HEAD',
51+
52+
# The revision number to checkout.
53+
# This is only used when the -ResetPath parameter is provided.
54+
# If provided, this will checkout the Nth most recent parent.
55+
# Eg. HEAD~2
56+
[Parameter(ValueFromPipelineByPropertyName)]
57+
[int]
58+
$RevisionNumber,
59+
60+
# The pattern number to checkout.
61+
# This is only used when the -ResetPath parameter is provided.
62+
# If provided, this will checkout the Nth most recent parent.
63+
# Eg. HEAD^2
64+
[Parameter(ValueFromPipelineByPropertyName)]
65+
[int]
66+
$ParentNumber,
67+
68+
# If set, will checkout a branch in a detached state.
69+
[Parameter(ValueFromPipelineByPropertyName)]
70+
[switch]
71+
$Detach
72+
)
73+
74+
if ($Detach) {
75+
"--detach"
76+
}
77+
78+
if ($PullRequest) {
79+
$remoteName = git remote | Select-Object -ExpandProperty RemoteName | Select-Object -First 1
80+
if (-not $BranchName) {
81+
$BranchName = "PR-$PullRequest"
82+
}
83+
$fetchedBranch = git fetch $remoteName "pull/$PullRequest/head:$BranchName"
84+
if (-not $fetchedBranch) {
85+
return $BranchName
86+
}
87+
$BranchName
88+
}
89+
elseif ($NewBranchName) {
90+
"-b"
91+
$NewBranchName
92+
}
93+
elseif ($ResetBranchName) {
94+
if ($PSCmdlet -and $PSCmdlet.ShouldProcess("Reset branch $ResetBranchName")) {
95+
"-B" # Beware of capital B in git
96+
$ResetBranchName
97+
}
98+
}
99+
elseif ($BranchName) {
100+
$BranchName
101+
}
102+
103+
if ($ResetPath) {
104+
if ($ParentNumber) {
105+
"$FromBranch^$ParentNumber"
106+
} elseif ($RevisionNumber) {
107+
"$FromBranch~$RevisionNumber"
108+
} else {
109+
"$FromBranch"
110+
}
111+
112+
foreach ($pathToReset in $ResetPath) {
113+
$pathToReset
114+
}
115+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<#
2+
.SYNOPSIS
3+
git config list extension
4+
.DESCRIPTION
5+
Parses the output of git config --list int a PowerShell object.
6+
.EXAMPLE
7+
git config --list
8+
.EXAMPLE
9+
git config --global --list
10+
.EXAMPLE
11+
git config --list --local
12+
.EXAMPLE
13+
git config --list --show-origin
14+
#>
15+
[Management.Automation.Cmdlet("Out","Git")] # It extends Out-Git
16+
[ValidatePattern('^[\S]{0,}git config[\s\S]{1,}--list')]
17+
param()
18+
19+
begin {
20+
$configLines = @()
21+
}
22+
23+
process {
24+
$configLines += "$gitOut"
25+
}
26+
27+
end {
28+
$configEntries = [Ordered]@{}
29+
30+
# Only lines containing an = are considered configuration entries
31+
foreach ($configLine in $configLines -match '=') {
32+
# Split the line into key and value
33+
$key, $value = $configLine -split '=', 2
34+
# If the key starts with file:, replace spaces with ? and convert to URI
35+
if ($key -match '^file:') {
36+
$key = $key -replace '\s', '?' -as [uri]
37+
}
38+
# If there are no entries, set the value
39+
if (-not $configEntries[$key]) {
40+
$configEntries[$key] = $value
41+
} else {
42+
# If there are multiple entries, convert to array
43+
$configEntries[$key] = @($configEntries[$key]) + $value
44+
}
45+
}
46+
47+
# If there were any entries,
48+
if ($configEntries.Count) {
49+
# create a custom object
50+
$configObject = [PSCustomObject]$configEntries
51+
# decorate it as a 'git.config.list' object
52+
$configObject.PSTypeNames.insert(0,'git.config.list')
53+
# and output it.
54+
$configObject
55+
} else {
56+
# If there were no entries, output the original lines
57+
$configLines
58+
}
59+
}
60+
61+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<#
2+
.SYNOPSIS
3+
git json format
4+
.DESCRIPTION
5+
Parses the output of git format, if the results are a series of json objects
6+
.EXAMPLE
7+
git branch --format "{'ref':'%(refname:short)','parent':'%(parent)'}"
8+
#>
9+
[Management.Automation.Cmdlet("Out","Git")] # It's an extension for Out-Git
10+
[ValidatePattern("\s-{2}format.+?[\[\{].+?[\]\}]", Options = 'IgnoreCase,IgnorePatternWhitespace'
11+
)]
12+
param()
13+
14+
15+
process {
16+
$gitOutJson = try {
17+
if ($gitOut) { $gitOut | ConvertFrom-Json}
18+
} catch {
19+
$null
20+
}
21+
if ($gitOutJson) {
22+
$gitOutJson
23+
return
24+
}
25+
else {
26+
return $gitOut
27+
}
28+
}

0 commit comments

Comments
 (0)