Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify main GitHub action to include other configurations and auto-generated changelog #830

Merged
merged 26 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bbc9213
Added other configurations to ci.
soumyamahunt Mar 25, 2021
f1dbe3b
Added ignored paths and robust version checking.
soumyamahunt Mar 25, 2021
a15921d
Implement selecting configuration based on event triggered.
soumyamahunt Mar 25, 2021
5108473
Fix typo.
soumyamahunt Mar 25, 2021
76842b8
Fix json error
soumyamahunt Mar 25, 2021
3cedd6d
Fix typo.
soumyamahunt Mar 25, 2021
d24f0bf
Fix action failure.
soumyamahunt Mar 25, 2021
aeb2a32
Fix failure in debug mode.
soumyamahunt Mar 25, 2021
de6f36e
Update branch.
soumyamahunt Mar 26, 2021
1767228
Fix typo.
soumyamahunt Mar 26, 2021
419d9cc
Fix typo.
soumyamahunt Mar 26, 2021
5909267
Update action and automated changelog.
soumyamahunt Mar 27, 2021
4192a93
Merge branch 'master' into github-action
soumyamahunt Mar 27, 2021
3a4b78e
Refactor task.
soumyamahunt Mar 27, 2021
3a43a4f
Merge branch 'github-action' of https://github.com/soumyamahunt/Notep…
soumyamahunt Mar 27, 2021
26718a5
Refactor action.
soumyamahunt Mar 27, 2021
a372b7b
Refactor action.
soumyamahunt Mar 27, 2021
826466d
Refactor action.
soumyamahunt Mar 27, 2021
a7af94f
Fix typo.
soumyamahunt Mar 27, 2021
8db0b46
Implement testing for arm in debug configuration.
soumyamahunt Mar 28, 2021
6bb661e
Fix typo.
soumyamahunt Mar 28, 2021
641bc9d
Added more paths to ignore.
soumyamahunt Mar 28, 2021
7d8e5ca
Implement manually triggering release.
soumyamahunt Mar 28, 2021
624aefc
Update GitHub release process.
soumyamahunt Mar 28, 2021
fb55d0c
Fix typo.
soumyamahunt Mar 28, 2021
02a1599
Combine codeql-analysis in main action.
soumyamahunt Mar 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@ name: CodeQL Analysis

on:
push:
paths-ignore:
- '**.md'
- 'ScreenShots/**'
- '.whitesource'
- 'azure-pipelines.yml'
pull_request:
paths-ignore:
- '**.md'
- 'ScreenShots/**'
- '.whitesource'
- 'azure-pipelines.yml'
schedule:
- cron: '0 8 * * *'

Expand Down
181 changes: 129 additions & 52 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,96 @@
name: Notepads CI/CD Pipeline

on: [push, pull_request, workflow_dispatch]
on:
push:
paths-ignore:
- '**.md'
- 'ScreenShots/**'
- '.whitesource'
- 'azure-pipelines.yml'
pull_request:
paths-ignore:
- '**.md'
- 'ScreenShots/**'
- '.whitesource'
- 'azure-pipelines.yml'
workflow_dispatch:

jobs:
ci:
setup:
runs-on: windows-latest
outputs:
new_version: ${{ steps.tag_generator.outputs.new_version }}
new_version_tag: ${{ steps.tag_generator.outputs.new_tag }}
is_push_to_master: ${{ steps.step_conditionals_handler.outputs.is_push_to_master }}
env:
SOLUTION_NAME: src\Notepads.sln
CONFIGURATION: Production
DEFAULT_DIR: ${{ github.workspace }}
matrix: ${{ steps.set_matrix.outputs.matrix }}
steps:
- name: Steps' conditionals handler
id: step_conditionals_handler
- name: Setup strategy matrix
id: set_matrix
shell: pwsh
run: |
$IS_PUSH_TO_MASTER = 'false'
$IS_NOT_PR = 'true'
if ( ($env:GITHUB_EVENT_NAME -ceq 'push') -and ($env:GITHUB_REF -ceq 'refs/heads/master') ) {
$IS_PUSH_TO_MASTER = 'true'
}
if ( $env:GITHUB_EVENT_NAME -ceq 'pull_request' ) {
$IS_NOT_PR = 'false'
$MATRIX = '{
"include": [
{
"configuration": "Production",
"appxBundlePlatforms": "x64",
"runSonarCloudScan": true,
"debug": false,
"release": false
}
]
}'
if ( ($env:GITHUB_EVENT_NAME -ceq 'pull_request') -or ($env:GITHUB_EVENT_NAME -ceq 'push') ) {
$MATRIX = '{
"include": [
{
"configuration": "Debug",
"appxBundlePlatforms": "x86|x64",
"runSonarCloudScan": false,
"debug": true,
"release": false
},{
"configuration": "Release",
"appxBundlePlatforms": "x86|x64|ARM64",
"runSonarCloudScan": false,
"debug": false,
"release": false
},{
"configuration": "Production",
"appxBundlePlatforms": "x86|x64|ARM64",
"runSonarCloudScan": true,
"debug": false,
"release": false
}
]
}'
$MATRIX_OBJ = $MATRIX | ConvertFrom-Json
if ( ($env:GITHUB_EVENT_NAME -ceq 'push') -and ($env:GITHUB_REF -ceq 'refs/heads/master') ) {
$MATRIX_OBJ.include | % { if ( $_.configuration -eq "$env:RELEASE_CONFIGURATION" ) { $_.release = $true } }
}
if ( $env:GITHUB_EVENT_NAME -ceq 'pull_request' ) {
$MATRIX_OBJ.include | % { if ( $_.configuration -eq "$env:RELEASE_CONFIGURATION" ) { $_.runSonarCloudScan = $false } }
}
$MATRIX = $MATRIX_OBJ | ConvertTo-Json -depth 32
}
echo "::set-output name=is_push_to_master::$(echo $IS_PUSH_TO_MASTER)"
echo "::set-output name=is_not_pr::$(echo $IS_NOT_PR)"
echo "::set-output name=matrix::$($MATRIX -replace ' *\r*\n*', '')"
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
GITHUB_REF: ${{ github.ref }}
RELEASE_CONFIGURATION: Production

- if: steps.step_conditionals_handler.outputs.is_not_pr == 'true'
ci:
needs: setup
runs-on: windows-latest
strategy:
matrix: ${{ fromJson(needs.setup.outputs.matrix) }}
outputs:
changelog: ${{ steps.tag_generator.outputs.changelog }}
new_version: "${{ steps.tag_generator.outputs.new_version }}.0"
new_version_tag: "v${{ steps.tag_generator.outputs.new_version }}.0"
is_release: ${{ matrix.release }}
env:
SOLUTION_NAME: src\Notepads.sln
CONFIGURATION: ${{ matrix.configuration }}
DEFAULT_DIR: ${{ github.workspace }}
steps:
- if: matrix.runSonarCloudScan
name: Set up JDK 11
id: Setup_JDK
uses: actions/setup-java@v1
Expand All @@ -50,26 +108,47 @@ jobs:
fetch-depth: 50
token: ${{ secrets.GITHUB_TOKEN }}

- if: steps.step_conditionals_handler.outputs.is_push_to_master == 'true'
- if: matrix.release
name: Check latest tag
id: check_latest_tag
shell: pwsh
run: |
$LATEST_TAG = git -c 'versionsort.suffix=-' ls-remote --exit-code --refs --sort='version:refname' --tags "https://github.com/$env:GIT_REPOSITORY.git" '*.*.*' | tail --lines=1 | cut --delimiter='/' --fields=3
$LATEST_VERSION = [System.Version]::Parse($LATEST_TAG -replace 'v')
echo "::set-output name=semver::$(echo "$($LATEST_VERSION.Major).$($LATEST_VERSION.Minor).$($LATEST_VERSION.Build)")"
env:
GIT_REPOSITORY: ${{ github.repository }}

- if: matrix.release && steps.check_latest_tag.outputs.semver != ''
name: Bump GitHub tag
id: tag_generator
uses: mathieudutour/github-tag-action@v5
uses: soumyamahunt/github-tag-action@test-other-ver-support
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this your own version of tag action?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to comment about this, I opened a PR in the action repo that will allow notepads to use the tag action without having to follow semver style tags. Currently I am keeping this for testing, but if the PR accepted we will follow the main repo.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jasonstein I have some suggestion about release strategy. Right now any push commit with the proper format triggers a release, the drawback of this is the changelog will only contain that specific commit and you will have to later modify changelog. What I want to propose is trigger release with workflow_dispatch event with an input, this way we can always follow the format for all commits and the changelog will be generated from appropriate commits without requiring you to modify anything later.

100% agreed.

with:
github_token: ${{ secrets.GITHUB_TOKEN }}
latest_ver: ${{ steps.check_latest_tag.outputs.semver }}
default_bump: false
dry_run: true

- if: steps.step_conditionals_handler.outputs.is_push_to_master == 'true' && steps.tag_generator.outputs.new_version != ''
name: Update Package.appxmanifest version
id: update_appxmanifest
- if: matrix.release && steps.tag_generator.outputs.new_version != ''
name: Update tag and manifest
id: update
shell: pwsh
run: |
$APPXMANIFEST_PATH = 'src/Notepads/Package.appxmanifest'
git config --global user.name $env:GIT_USER_NAME
git config --global user.email $env:GIT_USER_EMAIL
git tag -a -m "$env:NEW_VERSION_TAG" $env:NEW_VERSION_TAG
git push --follow-tags
$xml = [xml](Get-Content $APPXMANIFEST_PATH)
$xml.Package.Identity.SetAttribute('Version', "$env:NEW_VERSION.0")
$xml.Package.Identity.SetAttribute('Version', "$env:NEW_VERSION")
$xml.save($APPXMANIFEST_PATH)
env:
NEW_VERSION: ${{ steps.tag_generator.outputs.new_version }}
GIT_USER_NAME: ${{ secrets.GIT_USER_NAME }}
GIT_USER_EMAIL: ${{ secrets.GIT_USER_EMAIL }}
APPXMANIFEST_PATH: src\Notepads\Package.appxmanifest
NEW_VERSION: "${{ steps.tag_generator.outputs.new_version }}.0"
NEW_VERSION_TAG: "v${{ steps.get_assembly_version.outputs.version_tag }}.0"

- if: steps.step_conditionals_handler.outputs.is_not_pr == 'true'
- if: matrix.runSonarCloudScan
name: Cache SonarCloud packages
id: cache_sonar_packages
uses: actions/cache@v2
Expand All @@ -78,7 +157,7 @@ jobs:
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- if: steps.step_conditionals_handler.outputs.is_not_pr == 'true'
- if: matrix.runSonarCloudScan
name: Cache SonarCloud scanner
id: cache_sonar_scanner
uses: actions/cache@v2
Expand All @@ -87,15 +166,15 @@ jobs:
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner

- if: steps.step_conditionals_handler.outputs.is_not_pr == 'true' && steps.cache_sonar_scanner.outputs.cache-hit != 'true'
- if: matrix.runSonarCloudScan && steps.cache_sonar_scanner.outputs.cache-hit != 'true'
name: Install SonarCloud scanner
id: install_sonar_scanner
shell: pwsh
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner

- if: steps.step_conditionals_handler.outputs.is_not_pr == 'true'
- if: matrix.runSonarCloudScan
name: Initialize SonarCloud scanner
id: init_sonar_scanner
shell: pwsh
Expand All @@ -109,25 +188,22 @@ jobs:
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

- if: steps.step_conditionals_handler.outputs.is_push_to_master == 'true'
- if: matrix.release && steps.tag_generator.outputs.new_version != ''
name: Create PFX certificate for AppxBundle
id: create_pfx_cert
shell: pwsh
run: |
$BASE64_STR = $env:BASE64_STR
$TARGET_FILE = "$env:DEFAULT_DIR\cert.pfx"
$FROM_BASE64_STR = [Convert]::FromBase64String($BASE64_STR)
[IO.File]::WriteAllBytes($TARGET_FILE, $FROM_BASE64_STR)
$FROM_BASE64_STR = [System.Convert]::FromBase64String("$env:BASE64_STR")
[System.IO.File]::WriteAllBytes($TARGET_FILE, $FROM_BASE64_STR)
env:
BASE64_STR: ${{ secrets.PACKAGE_CERTIFICATE_BASE64 }}

- name: Restore the application
id: restore_application
shell: pwsh
run: |
msbuild $env:SOLUTION_NAME `
/t:Restore `
/p:Configuration=$env:CONFIGURATION
msbuild $env:SOLUTION_NAME /t:Restore

- name: Build and generate bundles
id: build_app
Expand All @@ -148,14 +224,14 @@ jobs:
PLATFORM: x64
UAP_APPX_PACKAGE_BUILD_MODE: StoreUpload
APPX_BUNDLE: Always
APPX_PACKAGE_SIGNING_ENABLED: ${{ steps.step_conditionals_handler.outputs.is_push_to_master }}
APPX_BUNDLE_PLATFORMS: x86|x64|ARM64
APPX_PACKAGE_SIGNING_ENABLED: ${{ matrix.release }}
APPX_BUNDLE_PLATFORMS: ${{ matrix.appxBundlePlatforms }}
ARTIFACTS_DIR: ${{ github.workspace }}\Artifacts
PACKAGE_CERTIFICATE_KEYFILE: ${{ github.workspace }}\cert.pfx
PACKAGE_CERTIFICATE_PASSWORD: ${{ secrets.PACKAGE_CERTIFICATE_PWD }}
APP_CENTER_SECRET: ${{ secrets.APP_CENTER_SECRET }}

- if: steps.step_conditionals_handler.outputs.is_not_pr == 'true'
- if: matrix.runSonarCloudScan
name: Send SonarCloud results
id: send_sonar_results
shell: pwsh
Expand All @@ -166,7 +242,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.SONAR_GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

- if: steps.step_conditionals_handler.outputs.is_push_to_master == 'true'
- if: matrix.release && steps.tag_generator.outputs.new_version != ''
name: Upload build artifacts
id: upload_artifacts
uses: actions/upload-artifact@v1
Expand All @@ -176,12 +252,12 @@ jobs:

cd:
# "This job will execute when the workflow is triggered on a 'push event', the target branch is 'master' and the commit is intended to be a release."
if: needs.ci.outputs.is_push_to_master == 'true' && needs.ci.outputs.new_version != ''
needs: ci
if: needs.ci.outputs.is_release && needs.ci.outputs.new_version != ''
needs: [ setup, ci ]
runs-on: windows-latest
env:
NEW_ASSEMBLY_VERSION: "${{ needs.ci.outputs.new_version }}.0"
NEW_TAG: ${{ needs.ci.outputs.new_version_tag }}
NEW_VERSION: ${{ needs.ci.outputs.new_version }}
NEW_VERSION_TAG: ${{ needs.ci.outputs.new_version_tag }}
steps:
- name: Checkout repository
id: checkout_repo
Expand All @@ -198,8 +274,9 @@ jobs:
id: create_release
uses: actions/create-release@v1
with:
tag_name: ${{ env.NEW_TAG }}
release_name: Notepads ${{ env.NEW_TAG }}
tag_name: ${{ env.NEW_VERSION_TAG }}
release_name: Notepads ${{ env.NEW_VERSION_TAG }}
body: ${{ needs.ci.outputs.changelog }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -208,8 +285,8 @@ jobs:
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: Artifacts/Notepads_${{ env.NEW_ASSEMBLY_VERSION }}_Production_Test/Notepads_${{ env.NEW_ASSEMBLY_VERSION }}_x86_x64_ARM64_Production.msixbundle
asset_name: Notepads_${{ env.NEW_ASSEMBLY_VERSION }}_x86_x64_ARM64.msixbundle
asset_path: Artifacts/Notepads_${{ env.NEW_VERSION }}_Production_Test/Notepads_${{ env.NEW_VERSION }}_x86_x64_ARM64_Production.msixbundle
asset_name: Notepads_${{ env.NEW_VERSION }}_x86_x64_ARM64.msixbundle
asset_content_type: application/zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down