Skip to content

Commit

Permalink
update release process
Browse files Browse the repository at this point in the history
  • Loading branch information
Hau-Hau committed Sep 20, 2024
1 parent afd8321 commit affdeca
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 72 deletions.
45 changes: 45 additions & 0 deletions .github/actions/has-changes-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Has Changes
description: Checks if project has any changes since last release
inputs:
project:
required: true
description: "EncryptedConfigValue.Module | EncryptedConfigValue.AspNetCore"
outputs:
result:
description: "true | false"
value: "${{ steps.validate.outputs.result }}"
runs:
using: "composite"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true

- name: Validate
shell: bash
id: validate
run: |
hash_current=$(git rev-parse HEAD)
echo "hash_current=$hash_current"
if [ -z "$hash_current" ]; then
echo "result=false" >> $GITHUB_OUTPUT
exit 0
fi
hash_of_last_release=$(git tag -l "${{ inputs.project }}/*" | sort -V | tail -n 1 | xargs -I {} git rev-list -n 1 {})
echo "hash_of_last_release=$hash_of_last_release"
if [ -z "$hash_of_last_release" ]; then
echo "result=false" >> $GITHUB_OUTPUT
exit 0
fi
has_differences=$(git diff --quiet "$hash_current:./${{ inputs.project }}" "$hash_of_last_release:./${{ inputs.project }}" && echo false || echo true)
echo "has_differences=$has_differences"
if [ -z "$has_differences" ]; then
echo "result=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "result=true"
echo "result=true" >> $GITHUB_OUTPUT
66 changes: 66 additions & 0 deletions .github/actions/update-nuspec-file-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Update nuspec file
description: Update .nuspec file
inputs:
GITHUB_TOKEN:
description: 'GITHUB_TOKEN'
required: true
project:
required: true
description: "Allowed values: EncryptedConfigValue.Module | EncryptedConfigValue.AspNetCore"
runs:
using: "composite"
steps:
- name: Setup env variables
shell: bash
run: |
TARGET_BRANCH_NAME="bot/${{ inputs.project }}/update-nuspec"
echo "TARGET_BRANCH_NAME=$TARGET_BRANCH_NAME" >> $GITHUB_ENV
- name: Setup git
shell: bash
run: |
git config --global user.name "GitHub Action"
git config --global user.email "action@github.com"
IS_TARGET_BRANCH_EXISTS=$(git ls-remote --heads origin $TARGET_BRANCH_NAME | grep -q "refs/heads/$TARGET_BRANCH_NAME" && echo true || echo false)
echo "IS_TARGET_BRANCH_EXISTS=$IS_TARGET_BRANCH_EXISTS" >> $GITHUB_ENV
if [[ "$IS_TARGET_BRANCH_EXISTS" == "true" ]]; then
git fetch origin $TARGET_BRANCH_NAME:$TARGET_BRANCH_NAME
git checkout $TARGET_BRANCH_NAME
git reset --hard origin/main
else
git checkout -b $TARGET_BRANCH_NAME
fi
- uses: ./.github/actions/setup-dotnet-action

- name: Build
shell: bash
run: dotnet build ./EncryptedConfigValue.sln --configuration Release

- name: Update ${{ inputs.project }}.nuspec
shell: pwsh
run: |
pwsh ./Scripts/UpdateNuspec.ps1 -CsprojPath "./${{ inputs.project }}/${{ inputs.project }}.csproj" -NuspecPath "./${{ inputs.project }}/${{ inputs.project }}.nuspec" -ReadmePath "./Readme.md"
- name: Commit changes
shell: bash
run: |
git add --all .
git commit -m "Update ${{ inputs.project }}.nuspec"
if [[ "$IS_TARGET_BRANCH_EXISTS" == "true" ]]; then
git push --force origin $TARGET_BRANCH_NAME
else
git push --set-upstream origin $TARGET_BRANCH_NAME
fi
- name: Create Pull Request
shell: bash
run: |
pr_id=$(gh pr list --base main --head $TARGET_BRANCH_NAME --json number --jq '.[0].number')
if [ -z "$pr_id" ]; then
gh pr create -B main -H $TARGET_BRANCH_NAME --title 'Release ${{ inputs.project }}' --body "**⚠️ Attention: This Pull Request Will Initiate the Release Process of ${{ inputs.project }}! ⚠️**"
else
gh pr edit $pr_id --title 'Release ${{ inputs.project }}' --body "**⚠️ Attention: This Pull Request Will Initiate the Release Process of ${{ inputs.project }}! ⚠️**"
fi
env:
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
53 changes: 33 additions & 20 deletions .github/workflows/release.EncryptedConfigValue.Net.Module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,33 @@ jobs:
RESULT: ${{ steps.validate.outputs.RESULT }}
steps:
- uses: actions/checkout@v4

- name: Setup git
run: |
git fetch origin main:main
git checkout main
with:
fetch-depth: 0
fetch-tags: true

- name: Validate
id: validate
run: |
hash_current=$(git rev-parse HEAD)
hash_of_last_release=$(git log --tags="EncryptedConfigValue.Net.Module/*" --simplify-by-decoration --pretty="format:%H %D" | grep 'EncryptedConfigValue.Net.Module/' | head -n 1 | awk '{print $1}')
has_differences=$(git diff --quiet $hash_current:./.github/ $hash_of_last_release:./.github/ && echo false || echo true)
RESULT="$([[ "$has_differences" == true ]] && echo true || echo false)"
echo "RESULT=$RESULT" >> $GITHUB_OUTPUT
if [ -z "$hash_current" ]; then
echo "RESULT=false" >> $GITHUB_OUTPUT
exit 0
fi
hash_of_last_release=$(git tag -l "EncryptedConfigValue.Net.Module/*" | sort -V | tail -n 1 | xargs -I {} git rev-list -n 1 {})
if [ -z "$hash_of_last_release" ]; then
echo "RESULT=false" >> $GITHUB_OUTPUT
exit 0
fi
has_differences=$(git diff --quiet "$hash_current:./EncryptedConfigValue.Module" "$hash_of_last_release:./EncryptedConfigValue.Module" && echo false || echo true)
if [ -z "$has_differences" ]; then
echo "RESULT=false" >> $GITHUB_OUTPUT
exit 0
fi
# RESULT="$([[ "$has_differences" == true ]] && echo true || echo false)"
echo "RESULT=true" >> $GITHUB_OUTPUT
test:
needs: [validate]
Expand All @@ -53,13 +66,12 @@ jobs:
run: |
git config --global user.name "GitHub Action"
git config --global user.email "action@github.com"
git fetch origin main:main
git checkout main
- uses: ./.github/actions/setup-dotnet-action

- name: Build
run: dotnet build ./EncryptedConfigValue.sln --configuration Release
run: |
dotnet build ./EncryptedConfigValue.sln --configuration Release
- name: Update EncryptedConfigValue.Net.Module.nuspec
shell: pwsh
Expand Down Expand Up @@ -95,13 +107,13 @@ jobs:
# dotnet nuget push "./EncryptedConfigValue.Module/bin/Release/EncryptedConfigValue.Net.Module.$version.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} -src https://api.nuget.org/v3/index.json
# release-github:
# needs: [update-nuspec]
# runs-on: ubuntu-latest
# permissions:
# contents: write
# pull-requests: write
# steps:
# # release-github:
# # needs: [update-nuspec]
# # runs-on: ubuntu-latest
# # permissions:
# # contents: write
# # pull-requests: write
# # steps:


tag:
Expand All @@ -117,4 +129,5 @@ jobs:
run: |
version=$(sed -n 's:.*<version>\(.*\)</version>.*:\1:p' ./EncryptedConfigValue.Module/EncryptedConfigValue.Net.Module.nuspec)
hash=$(sed -n 's:.*commit="\([^"]*\)".*:\1:p' ./EncryptedConfigValue.Module/EncryptedConfigValue.Net.Module.nuspec)
git tag -a "EncryptedConfigValue.Net.Module/$version" -m "EncryptedConfigValue.Net.Module v$version" $hash
git tag -a "EncryptedConfigValue.Net.Module/$version" -m "EncryptedConfigValue.Net.Module v$version" $hash
git push origin tag "EncryptedConfigValue.Net.Module/$version"
95 changes: 43 additions & 52 deletions .github/workflows/update-nuspec.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Update nuspec files

on:
workflow_dispatch:
pull_request:
types: [closed]
branches:
Expand All @@ -11,65 +12,55 @@ concurrency:
cancel-in-progress: true

jobs:
update-nuspec-files:
validate:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
outputs:
result-module: ${{ steps.validate.outputs.result-module }}
result-aspnetcore: ${{ steps.validate.outputs.result-aspnetcore }}

steps:
- uses: actions/checkout@v4

- name: Setup env variables
run: |
TARGET_BRANCH_NAME="bot/update-nuspec"
echo "TARGET_BRANCH_NAME=$TARGET_BRANCH_NAME" >> $GITHUB_ENV
- name: Setup git
run: |
git config --global user.name "GitHub Action"
git config --global user.email "action@github.com"
git fetch origin $TARGET_BRANCH_NAME:$TARGET_BRANCH_NAME
IS_TARGET_BRANCH_EXISTS=$(git ls-remote --heads origin $TARGET_BRANCH_NAME | grep -q "refs/heads/$TARGET_BRANCH_NAME" && echo true || echo false)
echo "IS_TARGET_BRANCH_EXISTS=$IS_TARGET_BRANCH_EXISTS" >> $GITHUB_ENV
if [[ "$IS_TARGET_BRANCH_EXISTS" == "true" ]]; then
git checkout $TARGET_BRANCH_NAME
git reset --hard main
else
git checkout -b $TARGET_BRANCH_NAME
fi
- uses: ./.github/actions/setup-dotnet-action

- name: Build
run: dotnet build ./EncryptedConfigValue.sln --configuration Release
- uses: ./.github/actions/has-changes-action
id: has-changes-module
with:
project: EncryptedConfigValue.Module

- name: Update EncryptedConfigValue.Net.Module.nuspec
shell: pwsh
run: |
pwsh ./Scripts/UpdateNuspec.ps1 -CsprojPath "./EncryptedConfigValue.Module/EncryptedConfigValue.Module.csproj" -NuspecPath "./EncryptedConfigValue.Module/EncryptedConfigValue.Net.Module.nuspec" -ReadmePath "./Readme.md"
- uses: ./.github/actions/has-changes-action
id: has-changes-aspnetcore
with:
project: EncryptedConfigValue.AspNetCore

- name: Update EncryptedConfigValue.Net.AspNetCore.nuspec
shell: pwsh
- name: Validate
id: validate
run: |
pwsh ./Scripts/UpdateNuspec.ps1 -CsprojPath "./EncryptedConfigValue.AspNetCore/EncryptedConfigValue.AspNetCore.csproj" -NuspecPath "./EncryptedConfigValue.AspNetCore/EncryptedConfigValue.Net.AspNetCore.nuspec" -ReadmePath "./Readme.md" -ExplicitDependenciesFromCsproj "./EncryptedConfigValue/EncryptedConfigValue.csproj"
echo "result-module=${{ steps.has-changes-module.outputs.result }}" >> $GITHUB_OUTPUT
echo "result-aspnetcore=${{ steps.has-changes-aspnetcore.outputs.result }}" >> $GITHUB_OUTPUT
- name: Commit changes
run: |
git add --all .
git commit -m "Update nuspec files"
if [[ "$IS_TARGET_BRANCH_EXISTS" == "true" ]]; then
git push --force origin $TARGET_BRANCH_NAME
else
git push --set-upstream origin $TARGET_BRANCH_NAME
fi
module:
needs: [validate]
if: needs.validate.outputs.result-module == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/update-nuspec-file-action
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
project: EncryptedConfigValue.Module

- name: Create Pull Request
run: |
pr_id=$(gh pr list --base main --head $TARGET_BRANCH_NAME --json number --jq '.[0].number')
if [ -z "$pr_id" ]; then
gh pr create -B main -H $TARGET_BRANCH_NAME --title 'Release' --body "**⚠️ Attention: This Pull Request Will Initiate the Release Process! ⚠️**"
else
gh pr edit $pr_id --title 'Release' --body "**⚠️ Attention: This Pull Request Will Initiate the Release Process! ⚠️**"
fi
env:
aspnetcore:
needs: [validate]
if: needs.validate.outputs.result-aspnetcore == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/update-nuspec-file-action
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
project: EncryptedConfigValue.AspNetCore

0 comments on commit affdeca

Please sign in to comment.