Skip to content

Commit

Permalink
🚧Improve release workflow (#152)
Browse files Browse the repository at this point in the history
* Start work for issue #150

* refactor: change master branch references to main

* ci: update release workflow to use reusable workflow

* ci: add runs-on capability to release workflow

* ci: improve status checks by using repo vars

* ci: update reusable workflow reference versions to latest

* ci: create workflow to add newly created issues to the org project

* ci: create sync bot workflow

* ci: create sync issue to pr workflow

* ci: create sync status check workflow

* force status checks

* ci: improve run names for status checks

* ci: improve job names

* ci: remove job from status checks
  • Loading branch information
CalvinWilkinson authored Jul 13, 2023
1 parent dad48f6 commit b98838d
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 135 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/add-new-issue-to-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: 🤖Add New Issue To Project


defaults:
run:
shell: pwsh


on:
issues:
types: opened


env:
GITHUB_TOKEN: ${{ secrets.CICD_REST_API }}


jobs:
add_issue_to_project:
name: Add Issue ${{ github.event.issue.number }} To Project
runs-on: ubuntu-latest
steps:
- name: Add To Project
run: |
# Get the raw json data using the GH CLI
$rawProjectsJsonData = gh project list --owner ${{ vars.ORGANIZATION_NAME }} --format=json;
Write-Host "::group::Raw Project JSON Data";
Write-Host $rawProjectsJsonData;
Write-Host "::endgroup::";
# Pipe the raw data into jq to format it into a more usable format
$formattedJsonData = $rawProjectsJsonData | jq "[.projects[] | { title: .title, number: .number }]"
Write-Host "::group::Formatted Project JSON Data";
Write-Host $formattedJsonData;
Write-Host "::endgroup::";
$orgProjects = $formattedJsonData | ConvertFrom-Json;
# Get the project that matches the org project name repo variable
$projects = $orgProjects.Where({ $_.title -eq "${{ vars.ORG_PROJECT_NAME }}" });
if ($projects.Count -eq 0) {
Write-Host "::error::The project '${{ vars.ORG_PROJECT_NAME }}' was not found. Check that the organization variable 'ORG_PROJECT_NAME' exists and is set correctly?";
exit 1;
}
$projNumber = $projects[0].number;
$issueUrl = "https://github.com/${{ vars.ORGANIZATION_NAME }}/${{ vars.PROJECT_NAME }}/issues/${{ github.event.issue.number }}";
# Add the newly created issue to the project
gh project item-add $projNumber --owner ${{ vars.ORGANIZATION_NAME }} --url $issueUrl;
42 changes: 7 additions & 35 deletions .github/workflows/build-status-check.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,18 @@
name: ✅Build Status Check
run-name: ✅Build Status Check ${{ github.base_ref == 'main' && '(Release Build)' || '(Debug Build)' }}


on:
workflow_dispatch:
pull_request:
branches:
- master
branches: main


jobs:
determine_build_config:
name: Determine Build Configuration
runs-on: ubuntu-latest
outputs:
build-config: ${{ steps.get-build-config.outputs.build-config }}
steps:
- name: Get Build Config
id: get-build-config
shell: pwsh
run: |
# If the destination branch that the pull request is merging into is the master, do a release build
if ( "${{ github.base_ref }}" -eq "master") {
"build-config=Release" >> $env:GITHUB_OUTPUT;
} else { # Any other branch than master, do a debug build
"build-config=Debug" >> $env:GITHUB_OUTPUT;
}
# Build Main Projects
build_project:
name: Build Project
needs: [determine_build_config]
uses: KinsonDigital/Infrastructure/.github/workflows/[email protected]
with:
project-name: "VersionMiner"
build-config: ${{ needs.determine_build_config.outputs.build-config }}
net-sdk-version: 7.0.203

build_tests_project:
name: Build Tests Project
needs: [determine_build_config]
uses: KinsonDigital/Infrastructure/.github/workflows/[email protected]
name: Build Status Check
uses: KinsonDigital/Infrastructure/.github/workflows/[email protected]
with:
project-name: "VersionMinerTests"
build-config: ${{ needs.determine_build_config.outputs.build-config }}
net-sdk-version: 7.0.203
project-name: ${{ vars.PROJECT_NAME }}
build-config: "Debug"
net-sdk-version: ${{ vars.NET_SDK_VERSION }}
122 changes: 52 additions & 70 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,88 +1,70 @@
name: 🚀Release
run-name: 🚀${{ inputs.release_type }} Release ${{ inputs.dry-run == true && '(Dry Run)' || '' }}


defaults:
run:
shell: pwsh


env:
runs-on: ubuntu-latest


on:
workflow_dispatch:
inputs:
release_type:
description: "Release Type"
description: The type of release to validate. Either 'Preview' or 'Production'.
required: true
type: choice
options:
- Preview
- Production
options: [Preview, Production]
runs-on:
description: The type of runner to run the workflow on.
required: false
type: choice
options: [ubuntu-latest, windows-latest, macos-latest]
default: ubuntu-latest
dry-run:
required: false
description: If true, the release will not be created.
default: false
type: boolean


jobs:
release:
name: Release
runs-on: ubuntu-latest
determine_build_config:
name: Determine Build Configuration
runs-on: ${{ inputs.runs-on }}
outputs:
build-config: "${{ steps.get-build-config.outputs.build-config }}"
steps:
- name: Validate Branch
run: |
$branch = "${{ github.ref }}";
if ($branch -ne "refs/heads/master") {
Write-Host "::error::Release workflow can only run on the $branch branch";
exit 1;
}
- name: Checkout
uses: actions/checkout@v3

- name: Build Main Project
run: dotnet build "${{ github.workspace }}/VersionMiner/VersionMiner.csproj" -c Release;

- name: Run Unit Tests
run: dotnet test "${{ github.workspace }}/Testing/VersionMinerTests/VersionMinerTests.csproj";

- name: Set Up Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: Get Version From C# Project File
id: get-version
uses: KinsonDigital/[email protected]
with: # github action output is 'version'
repo-owner: KinsonDigital
repo-name: VersionMiner
repo-token: ${{ secrets.CICD_TOKEN }}
branch-name: "${{ github.ref }}"
trim-start-from-branch: "refs/heads/"
file-format: xml # Not case sensitive
file-path: "VersionMiner/VersionMiner.csproj"
version-keys: Version

- name: Validate Tag
run: deno run --allow-run "${{ github.workspace }}/.github/cicd/validate-tag.ts" "${{ inputs.release_type }}" "v${{ steps.get-version.outputs.version }}";

- name: Validate Release Notes
run: deno run --allow-read "${{ github.workspace }}/.github/cicd/validate-notes.ts" "${{ inputs.release_type }}" "v${{ steps.get-version.outputs.version }}";

- name: Preview Release
uses: softprops/action-gh-release@v1
if: inputs.release_type == 'Preview'
with:
name: "🚀Preview Release - v${{ steps.get-version.outputs.version }}"
body_path: "${{ github.workspace }}/Documentation/ReleaseNotes/PreviewReleases/Release-Notes-v${{ steps.get-version.outputs.version }}.md"
files: "${{ github.workspace }}/Documentation/ReleaseNotes/PreviewReleases/Release-Notes-v${{ steps.get-version.outputs.version }}.md"
tag_name: "v${{ steps.get-version.outputs.version }}"
prerelease: true
draft: false

- name: Production Release
uses: softprops/action-gh-release@v1
if: inputs.release_type == 'Production'
with:
name: "🚀Production Release - v${{ steps.get-version.outputs.version }}"
body_path: "${{ github.workspace }}/Documentation/ReleaseNotes/ProductionReleases/Release-Notes-v${{ steps.get-version.outputs.version }}.md"
files: "${{ github.workspace }}/Documentation/ReleaseNotes/ProductionReleases/Release-Notes-v${{ steps.get-version.outputs.version }}.md"
tag_name: "v${{ steps.get-version.outputs.version }}"
prerelease: false
draft: false
- name: Get Build Config
id: get-build-config
run: |
# If the branch that the workflow is running on is the required branch for the release, do a release build
if ( "${{ github.base_ref }}" -eq "main") {
"build-config=Release" >> $env:GITHUB_OUTPUT;
echo "Release build created.";
} else { # Any other branch than the release branch, do a debug build
"build-config=Debug" >> $env:GITHUB_OUTPUT;
echo "Debug build created.";
}
perform_release:
name: Performing ${{ inputs.release_type }} Release of ${{ vars.PROJECT_NAME }} (${{ needs.determine_build_config.outputs.build-config }})
needs: determine_build_config
uses: KinsonDigital/Infrastructure/.github/workflows/[email protected]
with:
project-name: "${{ vars.PROJECT_NAME }}"
release-type: "${{ inputs.release_type }}"
run-branch: "${{ github.ref_name }}"
net-sdk-version: "${{ vars.NET_SDK_VERSION }}"
relative-release-notes-dir-path: "${{ vars.SCRIPT_RELATIVE_DIR_PATH }}"
release-notes-file-name-prefix: "${{ vars.RELEASE_NOTES_FILE_NAME_PREFIX }}"
build-config: "${{ needs.determine_build_config.outputs.build-config }}"
cicd-scripts-version: "${{ vars.CICD_SCRIPTS_VERSION}}"
pr-include-notes-label: "${{ vars.PR_INCLUDE_NOTES_LABEL }}"
runs-on: ${{ inputs.runs-on }}
dry-run: ${{ inputs.dry-run }}
53 changes: 53 additions & 0 deletions .github/workflows/sync-bot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: 🤖Sync Bot


defaults:
run:
shell: pwsh


on:
issues:
types: [labeled, unlabeled, assigned, unassigned, milestoned, demilestoned]


jobs:
sync_bot:
name: Sync Bot
if: ${{ !github.event.issue.pull_request }}
runs-on: ubuntu-latest
steps:
- name: Set Up Deno
if: startsWith(github.ref_name, 'feature/')
uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: Run Sync Bot (Issue Change)
if: startsWith(github.ref_name, 'feature/')
run: |
$scriptUrl = "${{ vars.SCRIPT_BASE_URL }}/${{ vars.CICD_SCRIPTS_VERSION }}/${{ vars.SCRIPT_RELATIVE_DIR_PATH}}/sync-bot-status-check.ts";
$issueNumber = "${{ github.event.issue.number }}";
echo "Project Name: ${{ vars.PROJECT_NAME }}";
echo "Issue: $issueNumber";
if ($manuallyExecuted -and $issueNumber -eq "0") {
echo "The issue or PR number must be a value greater than 0.";
exit 1;
}
<# Deno Args:
1. Project Name
2. Issue Number
3. Event Type - set to issue event type
4. GitHub token
#>
deno run `
--allow-net `
"$scriptUrl" `
"${{ vars.PROJECT_NAME }}" `
"$issueNumber" `
"issue" `
"${{ secrets.CICD_REST_API }}";
51 changes: 51 additions & 0 deletions .github/workflows/sync-issue-to-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: 🔄️Sync Issue To PR


defaults:
run:
shell: pwsh


on:
pull_request:
types: opened
issue_comment: # This event is triggered when creating issue and pr comments
types: created


jobs:
sync_issue_to_pr:
name: Start Sync Process
if: |
github.event_name == 'issue_comment' ||
github.event_name == 'pull_request' && startsWith(github.head_ref, 'feature/')
runs-on: ubuntu-latest
steps:
- name: Set Up Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: Sync
run: |
$eventName = "${{ github.event_name }}";
$scriptUrl = "${{ vars.SCRIPT_BASE_URL }}/${{ vars.CICD_SCRIPTS_VERSION }}/${{ vars.SCRIPT_RELATIVE_DIR_PATH}}/sync-issue-to-pr.ts";
$prNumber = $eventName -eq "pull_request" ? "${{ github.event.number }}" : "${{ github.event.issue.number }}";
$command = $eventName -eq "issue_comment" ? "${{ github.event.comment.body }}" : "[initial-sync]";
echo "Event Name: $eventName";
echo "Organization Name: ${{ vars.ORGANIZATION_NAME }}";
echo "Project Name: ${{ vars.PROJECT_NAME }}";
echo "Requested By: ${{ github.event.sender.login }}";
echo "PR Number: $prNumber";
echo "Comment: $command";
deno run `
--allow-net `
"$scriptUrl" `
"${{ vars.ORGANIZATION_NAME}}" `
"${{ vars.PROJECT_NAME }}" `
"${{ github.event.sender.login }}" `
"$prNumber" `
"$command" `
"${{ secrets.CICD_REST_API }}";
Loading

0 comments on commit b98838d

Please sign in to comment.