Skip to content

Merge pull request #1786 from KelvinTegelaar/dev #69

Merge pull request #1786 from KelvinTegelaar/dev

Merge pull request #1786 from KelvinTegelaar/dev #69

name: Generate Release Notes and Upload Production to Azure
on:
push:
branches:
- master
permissions:
contents: write
jobs:
release:
if: github.event.repository.fork == false && github.event_name == 'push'
name: Generate Release Notes and Upload to Azure
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Checkout Code
uses: actions/checkout@v4
with:
persist-credentials: false
# Read and Trim Version
- name: Read and Trim Version
id: get_version
run: |
if [ ! -f version_latest.txt ]; then
echo "Error: version_latest.txt not found!"
exit 1
fi
VERSION=$(cat version_latest.txt | tr -d '[:space:]')
if [ -z "$VERSION" ]; then
echo "Error: version_latest.txt is empty after trimming!"
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Exit if Tag Already Exists
- name: Check if Tag Exists
id: tag_check
run: |
git fetch --tags
if git rev-parse "refs/tags/${{ steps.get_version.outputs.version }}" >/dev/null 2>&1; then
echo "tag_exists=true" >> $GITHUB_ENV
echo "Tag ${{ steps.get_version.outputs.version }} already exists. Exiting workflow successfully."
else
echo "tag_exists=false" >> $GITHUB_ENV
fi
# Get Previous Tag
- name: Get Previous Tag
id: previous_tag
if: env.tag_exists == 'false'
run: |
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
echo "previous_tag=$PREV_TAG" >> $GITHUB_OUTPUT
echo "Previous tag: $PREV_TAG"
# Generate Release Notes
- name: Generate Release Notes
id: changelog
if: env.tag_exists == 'false'
uses: actions/github-script@v7
with:
script: |
const params = {
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: '${{ steps.get_version.outputs.version }}',
target_commitish: context.sha
};
const previousTag = '${{ steps.previous_tag.outputs.previous_tag }}';
if (previousTag) {
params.previous_tag_name = previousTag;
}
const { data } = await github.rest.repos.generateReleaseNotes(params);
core.setOutput('changelog', data.body);
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Create a new release tag
- name: Create GitHub Release
if: env.tag_exists == 'false'
uses: ncipollo/release-action@v1.14.0
with:
tag: ${{ steps.get_version.outputs.version }}
name: "v${{ steps.get_version.outputs.version }}"
draft: false
prerelease: false
makeLatest: true
body: ${{ steps.changelog.outputs.changelog }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Create ZIP File in a New Source Directory
- name: Prepare and Zip Release Files
if: env.tag_exists == 'false'
run: |
mkdir -p src/releases
zip -r src/releases/latest.zip . \
--exclude "./src/releases/*" \
--exclude ".*" \
--exclude ".*/**"
# Upload to Azure Blob Storage
- name: Azure Blob Upload with Destination folder defined
if: env.tag_exists == 'false'
uses: LanceMcCarthy/Action-AzureBlobUpload@v3.3.0
with:
connection_string: ${{ secrets.AZURE_CONNECTION_STRING }}
container_name: cipp-api
source_folder: src/releases/
destination_folder: /
delete_if_exists: true