Skip to content

Commit

Permalink
Updated the template to create release using GH CLI
Browse files Browse the repository at this point in the history
(#description:

Updated the template to
create release using GH CLI

#)
  • Loading branch information
Farshad DASHTI authored and Farshad DASHTI committed Oct 8, 2024
1 parent 5725a92 commit 240cd73
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 70 deletions.
154 changes: 84 additions & 70 deletions .github/workflows/nuget-package-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,84 +39,98 @@ jobs:
- name: Set up curl and jq
run: sudo apt-get install -y curl jq

- name: Check for custom version in commit message or check the feed for the latest version and increment it
id: check_custom_version
run: |
PROJECT_NAME=${{ inputs.project_name }} # Add the project name from inputs
# Search the last 10 commits for the version update indicator
COMMIT_HASH=$(git log -n 10 --pretty=format:"%H %s" | grep -P '\(#update '"$PROJECT_NAME"' package version to \d+\.\d+\.\d+\)' | grep -oP '^\w+' | head -n 1)
if [[ -n "$COMMIT_HASH" ]]; then
echo "Found commit with version update indicator: $COMMIT_HASH"
# Create a project-specific tag using project name and commit hash
TAG_NAME="${PROJECT_NAME}-processed-nuget-version-${COMMIT_HASH}"
# Check if the commit is already tagged for this project
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
echo "This commit has already been processed for version update in $PROJECT_NAME. Skipping."
else
# Extract the version from the commit message
CUSTOM_VERSION=$(git show -s --format=%s $COMMIT_HASH | grep -oP '\(#update '"$PROJECT_NAME"' package version to \K([0-9]+\.[0-9]+\.[0-9]+)')
if [[ -n "$CUSTOM_VERSION" ]]; then
echo "Using custom version: $CUSTOM_VERSION"
echo "NEW_VERSION=$CUSTOM_VERSION" >> $GITHUB_ENV
# Tag the commit with the project-specific tag
git tag "$TAG_NAME"
git push origin "$TAG_NAME"
else
echo "Failed to extract version from commit message. Exiting."
exit 1
fi
fi
fi
if [[ -z "$CUSTOM_VERSION" ]]; then
echo "No unprocessed custom version found in the last 10 commits for $PROJECT_NAME. Proceeding to fetch and increment the latest version from the feed."
# Fetch the latest version and increment it for the specific package
PACKAGE_ID="${{ inputs.nuget_package_name }}"
FEED_URL="https://nuget.pkg.github.com/DFE-Digital/query?q=$PACKAGE_ID"
LATEST_VERSION=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "$FEED_URL" | jq -r '.data[0].version')
if [[ -z "$LATEST_VERSION" || "$LATEST_VERSION" == "null" ]]; then
echo "No existing version found in the feed. Defaulting to version 1.0.0"
NEW_VERSION="1.0.0"
else
echo "Latest version is $LATEST_VERSION"
IFS='.' read -r -a VERSION_PARTS <<< "$LATEST_VERSION"
NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.$((VERSION_PARTS[2] + 1))"
echo "Incrementing to new version: $NEW_VERSION"
fi
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
fi
- name: Install GitHub CLI
run: sudo apt-get install -y gh

- name: Build, pack and publish
working-directory: ${{ inputs.project_path }}
run: |
dotnet build -c Release
dotnet pack -c Release -p:PackageVersion=${{ env.NEW_VERSION }} --output .
dotnet nuget push "*.nupkg" --api-key ${{ secrets.GITHUB_TOKEN }} --source https://nuget.pkg.github.com/DFE-Digital/index.json
- name: Authenticate GitHub CLI
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: echo "${GITHUB_TOKEN}" | gh auth login --with-token

- name: Get Release Description
id: extract_description
run: |
DESCRIPTION=$(git log -1 --pretty=format:"%s" | grep -oP '\(#description:.*\)' | sed 's/#description: //')
# Extracts multiline description between (#description: and #)
DESCRIPTION=$(git log -1 --pretty=format:"%b" | awk '/\(#description:/{flag=1; next} /\#\)/{flag=0} flag')
if [[ -z "$DESCRIPTION" ]]; then
DESCRIPTION="No release notes provided."
fi
echo "RELEASE_DESCRIPTION=$DESCRIPTION" >> $GITHUB_ENV

echo "RELEASE_DESCRIPTION<<EOF" >> $GITHUB_ENV
echo "$DESCRIPTION" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV

- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ inputs.nuget_package_name }}-${{ env.NEW_VERSION }}
release_name: Release ${{ env.NEW_VERSION }} for ${{ inputs.nuget_package_name }}
body: ${{ env.RELEASE_DESCRIPTION }}
draft: false
prerelease: false
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "${{ inputs.nuget_package_name }}-${{ env.NEW_VERSION }}" \
--title "Release ${{ env.NEW_VERSION }} for ${{ inputs.nuget_package_name }}" \
--notes "${{ env.RELEASE_DESCRIPTION }}" \
--draft=false \
--prerelease=false
# - name: Check for custom version in commit message or check the feed for the latest version and increment it
# id: check_custom_version
# run: |
# PROJECT_NAME=${{ inputs.project_name }} # Add the project name from inputs

# # Search the last 10 commits for the version update indicator
# COMMIT_HASH=$(git log -n 10 --pretty=format:"%H %s" | grep -P '\(#update '"$PROJECT_NAME"' package version to \d+\.\d+\.\d+\)' | grep -oP '^\w+' | head -n 1)

# if [[ -n "$COMMIT_HASH" ]]; then
# echo "Found commit with version update indicator: $COMMIT_HASH"
# # Create a project-specific tag using project name and commit hash
# TAG_NAME="${PROJECT_NAME}-processed-nuget-version-${COMMIT_HASH}"

# # Check if the commit is already tagged for this project
# if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
# echo "This commit has already been processed for version update in $PROJECT_NAME. Skipping."
# else
# # Extract the version from the commit message
# CUSTOM_VERSION=$(git show -s --format=%s $COMMIT_HASH | grep -oP '\(#update '"$PROJECT_NAME"' package version to \K([0-9]+\.[0-9]+\.[0-9]+)')

# if [[ -n "$CUSTOM_VERSION" ]]; then
# echo "Using custom version: $CUSTOM_VERSION"
# echo "NEW_VERSION=$CUSTOM_VERSION" >> $GITHUB_ENV

# # Tag the commit with the project-specific tag
# git tag "$TAG_NAME"
# git push origin "$TAG_NAME"
# else
# echo "Failed to extract version from commit message. Exiting."
# exit 1
# fi
# fi
# fi

# if [[ -z "$CUSTOM_VERSION" ]]; then
# echo "No unprocessed custom version found in the last 10 commits for $PROJECT_NAME. Proceeding to fetch and increment the latest version from the feed."

# # Fetch the latest version and increment it for the specific package
# PACKAGE_ID="${{ inputs.nuget_package_name }}"
# FEED_URL="https://nuget.pkg.github.com/DFE-Digital/query?q=$PACKAGE_ID"
# LATEST_VERSION=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "$FEED_URL" | jq -r '.data[0].version')

# if [[ -z "$LATEST_VERSION" || "$LATEST_VERSION" == "null" ]]; then
# echo "No existing version found in the feed. Defaulting to version 1.0.0"
# NEW_VERSION="1.0.0"
# else
# echo "Latest version is $LATEST_VERSION"
# IFS='.' read -r -a VERSION_PARTS <<< "$LATEST_VERSION"
# NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.$((VERSION_PARTS[2] + 1))"
# echo "Incrementing to new version: $NEW_VERSION"
# fi

# echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
# fi

# - name: Build, pack and publish
# working-directory: ${{ inputs.project_path }}
# run: |
# dotnet build -c Release
# dotnet pack -c Release -p:PackageVersion=${{ env.NEW_VERSION }} --output .
# dotnet nuget push "*.nupkg" --api-key ${{ secrets.GITHUB_TOKEN }} --source https://nuget.pkg.github.com/DFE-Digital/index.json

1 change: 1 addition & 0 deletions src/DfE.CoreLibs.Caching/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dotnet add package DfE.CoreLibs.Caching

## Usage


**Usage in Handlers**

1. **Service Registration:** You use `ICacheService` in your handlers to store and retrieve data from memory to avoid unnecessary processing and database queries. Here's how you register the caching service:
Expand Down

0 comments on commit 240cd73

Please sign in to comment.