<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://logicwiki.co.uk/index.php?action=history&amp;feed=atom&amp;title=Github_scripts_and_actions</id>
		<title>Github scripts and actions - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://logicwiki.co.uk/index.php?action=history&amp;feed=atom&amp;title=Github_scripts_and_actions"/>
		<link rel="alternate" type="text/html" href="http://logicwiki.co.uk/index.php?title=Github_scripts_and_actions&amp;action=history"/>
		<updated>2026-10-28T04:25:28Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>http://logicwiki.co.uk/index.php?title=Github_scripts_and_actions&amp;diff=2332&amp;oldid=prev</id>
		<title>AliIybar: Created page with &quot;Category:CICD Category:Github  == Release Script == &lt;pre&gt; param(     [string]$sourceBranch = &quot;main&quot;,     [string]$targetBranch,     [string]$repository = (Get-Location...&quot;</title>
		<link rel="alternate" type="text/html" href="http://logicwiki.co.uk/index.php?title=Github_scripts_and_actions&amp;diff=2332&amp;oldid=prev"/>
				<updated>2024-05-09T13:08:54Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&lt;a href=&quot;/index.php?title=Category:CICD&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Category:CICD (page does not exist)&quot;&gt;Category:CICD&lt;/a&gt; &lt;a href=&quot;/index.php?title=Category:Github&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Category:Github (page does not exist)&quot;&gt;Category:Github&lt;/a&gt;  == Release Script == &amp;lt;pre&amp;gt; param(     [string]$sourceBranch = &amp;quot;main&amp;quot;,     [string]$targetBranch,     [string]$repository = (Get-Location...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:CICD]]&lt;br /&gt;
[[Category:Github]]&lt;br /&gt;
&lt;br /&gt;
== Release Script ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
param(&lt;br /&gt;
    [string]$sourceBranch = &amp;quot;main&amp;quot;,&lt;br /&gt;
    [string]$targetBranch,&lt;br /&gt;
    [string]$repository = (Get-Location) # Set default value to current directory&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
# Function to extract PR numbers from commit messages&lt;br /&gt;
function Get-PRNumbersFromCommits {&lt;br /&gt;
    param (&lt;br /&gt;
        [string]$sourceBranch,&lt;br /&gt;
        [string]$targetBranch,&lt;br /&gt;
        [switch]$Verbose&lt;br /&gt;
    )&lt;br /&gt;
&lt;br /&gt;
    # Find the common ancestor (the point of divergence) of the two branches&lt;br /&gt;
    $commonAncestor = git merge-base $sourceBranch $targetBranch&lt;br /&gt;
&lt;br /&gt;
    if ($Verbose) {&lt;br /&gt;
        Write-Host &amp;quot;Common ancestor: $commonAncestor&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    # Prepare the argument list for the git command&lt;br /&gt;
    $gitArguments = @('log', '--oneline', &amp;quot;$commonAncestor..$sourceBranch&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    # Execute the git command and capture the output&lt;br /&gt;
    $logOutput = Start-Process git -ArgumentList $gitArguments -NoNewWindow -Wait -PassThru -RedirectStandardOutput 'gitOutput.txt'&lt;br /&gt;
    $mergeCommits = Get-Content 'gitOutput.txt' -Raw&lt;br /&gt;
    Remove-Item 'gitOutput.txt' -ErrorAction SilentlyContinue&lt;br /&gt;
&lt;br /&gt;
    if ($Verbose) {&lt;br /&gt;
        Write-Host &amp;quot;Log output:`n$mergeCommits&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    # Split the output into individual lines (commits)&lt;br /&gt;
    $commitArray = $mergeCommits -split '\r?\n'&lt;br /&gt;
&lt;br /&gt;
    if ($Verbose) {&lt;br /&gt;
        Write-Host &amp;quot;Number of merge commits: $($commitArray.Length)&amp;quot;&lt;br /&gt;
        Write-Host &amp;quot;Merge Commits:&amp;quot;&lt;br /&gt;
        $commitArray | ForEach-Object { Write-Host $_ }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    # List to store PR numbers&lt;br /&gt;
    $prNumbers = @()&lt;br /&gt;
&lt;br /&gt;
    foreach ($commit in $commitArray) {&lt;br /&gt;
        if ($Verbose) {&lt;br /&gt;
            Write-Host &amp;quot;Processing commit: $commit&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        # If the commit message matches the merge PR pattern, extract the PR number&lt;br /&gt;
        if ($commit -match &amp;quot;Merge pull request #(?&amp;lt;number&amp;gt;\d+)&amp;quot;) {&lt;br /&gt;
            $prNumbers += $matches.number&lt;br /&gt;
            if ($Verbose) {&lt;br /&gt;
                Write-Host &amp;quot;Match found: $($matches.number)&amp;quot;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    if ($Verbose) {&lt;br /&gt;
        Write-Host &amp;quot;PR numbers extracted: $prNumbers&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    return $prNumbers&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Step 0: Preparation&lt;br /&gt;
# Navigate to the repository directory; this is crucial before any git operations&lt;br /&gt;
if ($repository) {&lt;br /&gt;
    Set-Location -Path $repository&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Fetch the latest changes from the remote repository&lt;br /&gt;
git fetch origin&lt;br /&gt;
&lt;br /&gt;
# Checkout both branches to ensure they exist locally&lt;br /&gt;
git checkout $sourceBranch&lt;br /&gt;
git pull &amp;amp;&amp;amp; git push&lt;br /&gt;
git checkout $targetBranch&lt;br /&gt;
git pull &amp;amp;&amp;amp; git push&lt;br /&gt;
&lt;br /&gt;
# Switch back to the original branch or the source branch (based on your preference)&lt;br /&gt;
git checkout $sourceBranch&lt;br /&gt;
&lt;br /&gt;
# Section 1: Create Title&lt;br /&gt;
$packageJsonPath = Join-Path $repository &amp;quot;package.json&amp;quot; # path to package.json&lt;br /&gt;
if (-Not (Test-Path -Path $packageJsonPath -PathType Leaf)) {&lt;br /&gt;
    throw &amp;quot;Cannot find package.json in the repository path: $repository&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
$packageJsonContent = Get-Content $packageJsonPath | Out-String | ConvertFrom-Json&lt;br /&gt;
$version = $packageJsonContent.version&lt;br /&gt;
$title = &amp;quot;$targetBranch Release $version&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Section 2: Create Description&lt;br /&gt;
$description = &amp;quot;&amp;quot;&lt;br /&gt;
$prNumbers = Get-PRNumbersFromCommits -sourceBranch $sourceBranch -targetBranch $targetBranch&lt;br /&gt;
&lt;br /&gt;
foreach ($number in $prNumbers) {&lt;br /&gt;
    $description += &amp;quot;`n- #$number&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# If no PR numbers were found, use the title as the description&lt;br /&gt;
if ([string]::IsNullOrWhiteSpace($description)) {&lt;br /&gt;
    $description = $title&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Section 3: Create PR&lt;br /&gt;
$prOutput = gh pr create -B $targetBranch -H $sourceBranch -t $title -b $description 2&amp;gt;&amp;amp;1&lt;br /&gt;
Write-Host &amp;quot;PR creation output: $prOutput&amp;quot;  # Log the output for debugging&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if ($LASTEXITCODE -eq 0) {&lt;br /&gt;
    # Attempt to extract URL&lt;br /&gt;
    $prLink = [regex]::Match($prOutput, 'https?://\S+').Value&lt;br /&gt;
&lt;br /&gt;
    if ([string]::IsNullOrWhiteSpace($prLink) -or $prLink -eq 'True') {&lt;br /&gt;
        Write-Host &amp;quot;PR seems to be created, but failed to extract URL from the output. Check the repository on GitHub for the new PR.&amp;quot;&lt;br /&gt;
    } else {&lt;br /&gt;
        Write-Host &amp;quot;Pull Request created successfully: $prLink&amp;quot;&lt;br /&gt;
        Start-Process $prLink&lt;br /&gt;
    }&lt;br /&gt;
} else {&lt;br /&gt;
    Write-Error &amp;quot;Failed to create pull request: $prOutput&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Action to build and push nuget package to Github Nuget == &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
name: Deploy:GithubNuget:Staging&lt;br /&gt;
&lt;br /&gt;
on:&lt;br /&gt;
  push:&lt;br /&gt;
    branches: [ Staging ]&lt;br /&gt;
env:&lt;br /&gt;
  DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1&lt;br /&gt;
  DOTNET_NOLOGO: true&lt;br /&gt;
  NuGetDirectory: ${{ github.workspace }}/nuget&lt;br /&gt;
  &lt;br /&gt;
jobs:&lt;br /&gt;
  Deploy:&lt;br /&gt;
    runs-on: ubuntu-latest&lt;br /&gt;
&lt;br /&gt;
    steps:&lt;br /&gt;
    - uses: actions/checkout@v4&lt;br /&gt;
      with:&lt;br /&gt;
          fetch-depth: 0&lt;br /&gt;
    - name: Extract version from package.json&lt;br /&gt;
      run: |&lt;br /&gt;
        VERSION=$(jq -r '.version' package.json)&lt;br /&gt;
        echo &amp;quot;VERSION=$VERSION&amp;quot; &amp;gt;&amp;gt; $GITHUB_ENV&lt;br /&gt;
    &lt;br /&gt;
    - name: Setup .NET&lt;br /&gt;
      uses: actions/setup-dotnet@v3&lt;br /&gt;
      with:&lt;br /&gt;
        dotnet-version: '7.x'&lt;br /&gt;
    &lt;br /&gt;
    - name: Restore Packages&lt;br /&gt;
      run: dotnet restore&lt;br /&gt;
&lt;br /&gt;
    - name: Build &lt;br /&gt;
      run: dotnet build --no-restore --configuration Release -p:DisableGitVersionTask=true&lt;br /&gt;
    &lt;br /&gt;
    - name: Publish&lt;br /&gt;
      run: dotnet pack BookingOnline.Helpers/BookingOnline.Helpers.csproj -p:PackageVersion=${{ env.VERSION }}-beta  --configuration Release -p:DisableGitVersionTask=true --output ${{ env.NuGetDirectory }}&lt;br /&gt;
&lt;br /&gt;
    - name: Publish to Github Nuget Package Registery&lt;br /&gt;
      run: dotnet nuget push ${{ env.NuGetDirectory }}/BookingOnline.Helpers.${{ env.VERSION }}-beta.nupkg -k ${{ secrets.PACKAGES_TOKEN }} -s https://nuget.pkg.github.com/BookingOnline --skip-duplicate&lt;br /&gt;
         &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>AliIybar</name></author>	</entry>

	</feed>