Skip to content

WIP Version bumping #27

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

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
67 changes: 67 additions & 0 deletions .github/workflows/_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
name: _build
run-name: Build - ${{ inputs.project-name }}

on:
workflow_call:
inputs:
project-name:
type: string
required: true
project-path:
type: string
required: true

jobs:
build:
name: Build ${{ inputs.project-name }}
runs-on: ubuntu-22.04
steps:
- name: Get pinned .NET version
id: dotnet-version
run: echo "value=$(cat global.json | jq -r '.sdk.version')" >> $GITHUB_OUTPUT

- name: Set up dotnet
uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0
with:
dotnet-version: ${{ steps.dotnet-version.outputs.value }}

- name: Checkout Repo
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
fetch-depth: 0

- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-

- name: Install dependencies
run: dotnet restore ${{ inputs.project-path }}/${{ inputs.project-name }}.csproj

- name: Build
run: dotnet build --verbosity minimal ${{ inputs.project-path }}/${{ inputs.project-name }}.csproj

- name: .NET Publish ${{ inputs.project-name }}
run: |
echo "Publish"
dotnet publish ${{ inputs.project-path }}/${{ inputs.project-name }}.csproj \
-c Release --no-restore \
-o ./tmp/publish-${{ inputs.project-name }}

- name: Zip ${{ inputs.project-name }} Artifact
run: |
cd ./tmp/publish-${{ inputs.project-name }}
zip -r ${{ inputs.project-name }}.zip .
mv ${{ inputs.project-name }}.zip ../../
pwd
ls -atlh ../../

- name: Upload project artifact
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: ${{ inputs.project-name }}.zip
path: ./${{ inputs.project-name }}.zip
if-no-files-found: error
80 changes: 80 additions & 0 deletions .github/workflows/_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
name: _version
run-name: Get Version

on:
workflow_call:
inputs:
file:
type: string
required: false
default: 'Directory.Build.props'
bump-type:
type: string
required: false
outputs:
version:
description: "bumped version"
value: ${{ jobs.version.outputs.version }}
current-version:
description: "Version read from file"
value: ${{ jobs.version.outputs.current-version }}

jobs:
version:
name: Get Version
runs-on: ubuntu-22.04
outputs:
current-version: ${{ steps.version.outputs.current-version }}
version: ${{ steps.bump-version.outputs.value }}
steps:
- name: Checkout Repo
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
fetch-depth: 0

- name: Get Version
id: version
env:
_FILE: ${{ inputs.file }}
_BUMP_TYPE: ${{ inputs.bump-type }}
run: |
ls -la
git fetch --prune --tags

base_version=$(cat ./${_FILE} |
grep -o "<VersionPrefix>.*</VersionPrefix>" |
grep -Eo "[0-9]+\.[0-9]+\.[0-9]+"
)

echo " current version: $base_version"
echo "current-version=$base_version" >> $GITHUB_OUTPUT

- name: Bump Version
id: bump-version
env:
_BUMP_TYPE: ${{ inputs.bump-type }}
_BASE_VERSION: ${{ steps.version.outputs.current-version }}
run: |

echo "Calculating next version..."

major_version=$(echo $_BASE_VERSION | grep -Eo "[0-9]+" | head -1)
minor_version=$(echo $_BASE_VERSION | grep -Eo "[0-9]+" | sed -n 2p)
patch_version=$(echo $_BASE_VERSION | grep -Eo "[0-9]+" | sed -n 3p)

if [[ "$_BUMP_TYPE" == "major" ]]; then
major_version=$((${major_version##*.} + 1))
minor_version="0"
patch_version="0"
elif [[ "$_BUMP_TYPE" == "minor" ]]; then
minor_version=$((${minor_version##*.} + 1))
patch_version="0"
elif [[ "$_BUMP_TYPE" == "patch" ]]; then
patch_version=$((${patch_version##*.} + 1))
fi


echo " version: $major_version.$minor_version.$patch_version"
echo "value=$major_version.$minor_version.$patch_version" >> $GITHUB_OUTPUT
echo "Done"
126 changes: 126 additions & 0 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
name: Bump version

on:
workflow_dispatch:
inputs:
bump-type:
description: 'The type of bump to perform'
required: true
default: patch
type: 'choice'
options:
- major
- minor
- patch
workflow_call:
inputs:
bump-type:
type: string
default: patch



permissions:
pull-requests: write
contents: write
deployments: write

jobs:

version:
name: Get bumped project version
uses: ./.github/workflows/_version.yml
with:
bump-type: ${{ inputs.bump-type }}

update:
name: Update version
runs-on: ubuntu-22.04
needs:
- version
env:
_FILE: Directory.Build.props
_VERSION: ${{ needs.version.outputs.version }}

outputs:
PR_NEEDED: ${{ steps.commit.outputs.pr_needed }}
BRANCH_NAME: ${{ steps.branch_name.outputs.branch_name }}

steps:
- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
ref: main
fetch-depth: 0

- name: Generate branch name
id: branch_name
run: |
BRANCH=version-bump/$_VERSION
echo "branch_name=$BRANCH" >> $GITHUB_OUTPUT

- name: "Create version bump branch"
env:
BRANCH: ${{ steps.branch_name.outputs.branch_name }}
run: |
git switch -c $BRANCH
git push -u origin $BRANCH -f

- name: Update version
run: |
_FILE="./${_FILE}"

sed -i -e "s|<VersionPrefix>.*</VersionPrefix>|<VersionPrefix>$_VERSION</VersionPrefix>|g" $_FILE

- name: Commit and push changes
id: commit
env:
BRANCH: ${{ steps.branch_name.outputs.branch_name }}
run: |
git config --local user.email "[email protected]"
git config --local user.name "passwordless-bot"
if [ -n "$(git status --porcelain)" ]; then
git commit -m "Update to version ${{ env._VERSION }}" -a
git push -u origin $BRANCH
echo "pr_needed=true" >> $GITHUB_OUTPUT
else
echo "No changes to commit!";
echo "pr_needed=false" >> $GITHUB_OUTPUT
echo "### :mega: No changes to commit! PR was ommited." >> $GITHUB_STEP_SUMMARY
fi

pr:
name: Create PR
runs-on: ubuntu-22.04
needs:
- version
- update
env:
_VERSION: ${{ needs.version.outputs.version }}
_BASE_BRANCH: main
_HEAD_BRANCH: ${{ needs.update.outputs.BRANCH_NAME }}
_PR_TITLE: "Version bump to ${{ needs.version.outputs.version }}"
steps:
- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
fetch-depth: 0

- name: Create PR for ${{ env._HEAD_BRANCH }}
id: create-pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_URL=$(gh pr create --title "${{ env._PR_TITLE }}" \
--base "${{ env._BASE_BRANCH }}" \
--head "${{ env._HEAD_BRANCH }}" \
--label "automated pr" \
--body "
## Automated PR
- Base Branch: ${{ env._BASE_BRANCH }}
- Head Branch: ${{ env._HEAD_BRANCH }}
- Version: ${{ env._VERSION }}

")
echo "pr_number=${PR_URL##*/}" >> $GITHUB_OUTPUT
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: CI

on:
workflow_dispatch:

permissions:
id-token: write
contents: read
checks: write

jobs:
build:
uses: ./.github/workflows/_build.yml
with:
project-name: Sdk
project-path: ./src/Sdk
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
name: Release to NuGet
name: Publish to NuGet

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0

- name: Setup dotnet
uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a #v3.0.3

- name: Build
run: dotnet build -c Release
- name: Test
run: dotnet test -c Release --no-build

- name: Pack nugets
run: dotnet pack -c Release --no-build --output .

- name: Push to NuGet
run: dotnet nuget push "*.nupkg" --api-key ${{secrets.nuget_api_key}} --source https://api.nuget.org/v3/index.json
66 changes: 66 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
name: Create GitHub Release

on:
workflow_dispatch:
inputs:
dry-run:
description: "Dry run release"
required: true
default: false
type: boolean

jobs:
setup:
name: Setup
runs-on: ubuntu-22.04
outputs:
release_version: ${{ steps.version.outputs.version }}
branch-name: ${{ steps.branch.outputs.branch-name }}
steps:
- name: Branch check
if: ${{ github.event.inputs.dry-run == 'false' }}
run: |
if [[ "$GITHUB_REF" != "refs/heads/main" ]]; then
echo "==================================="
echo "[!] Can only release from the 'main' branches"
echo "==================================="
exit 1
fi

version:
name: Get project version
uses: ./.github/workflows/_version.yml
needs:
- setup
with:
project-name: Sdk
project-path: ./src/Sdk
bump-type: ""

release:
name: Create GitHub Release
runs-on: ubuntu-22.04
needs:
- setup
- version
steps:
- name: Download latest main build
uses: bitwarden/gh-actions/download-artifacts@f096207b7a2f31723165aee6ad03e91716686e78
with:
workflow: ci.yml
workflow_conclusion: success
branch: main
artifacts: "Sdk.zip"

- name: Create release
if: ${{ github.event.inputs.dry-run == 'false' }}
uses: ncipollo/release-action@a2e71bdd4e7dab70ca26a852f29600c98b33153e # v1.12.0
with:
artifacts: "Sdk.zip"
commit: ${{ github.sha }}
tag: "v${{ needs.version.outputs.current-version }}"
name: "Version ${{ needs.version.outputs.current-version }}"
body: "<insert release notes here>"
token: ${{ secrets.GITHUB_TOKEN }}
draft: true
Loading