Skip to content

undid the draft as to make it fully CD #21

undid the draft as to make it fully CD

undid the draft as to make it fully CD #21

Workflow file for this run

##################################
# CD Pipeline
# Goal:
# The goal of this pipeline is to continuous update the released assets.
# This will both include a real version.
# Additionally this will keep an pre-release version updated with merges and features that have not yet been put in a release.
#
# Logic:
# 1. Retrieve the version and check against refs/tags
# 2a. If the tag does not exist:
# - Create the tag
# - Build and release the assets
# 2b. If the tag exists:
# - Overwrite the "unreleased/beta" version with the currently merged version.
#
# Additional:
# - A manual overwrite option with an ability to overwrite the version if necessary.
##################################
name: CD
on:
push:
branches:
- main
- contiuousDelivery
workflow_dispatch:
inputs:
overwrite_version:
description: 'Overwrite the version'
type: boolean
default: false
jobs:
##################################
# Verify Version
# First retrieves the version.
# Then checks if that specific TAG already exists.
# Output:
# VERSION: The retrieved version from the VERSION file.
# TAG_EXISTS: Boolean indicating if the tag already exists.
##################################
verify_version:
runs-on: ubuntu-latest
name: "Verify Version"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Verify Version"
id: version
run: |
VERSION=$(grep -A 1 '\[workspace.package\]' Cargo.toml | grep 'version' | sed -E 's/.*version = "([^"]+)".*/\1/')
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "Retrieving version: $VERSION"
- name: "Check if tag exists"
id: tag_check
run: |
VERSION=${{ steps.version.outputs.VERSION }}
if git rev-parse "$VERSION" >/dev/null 2>&1; then
echo "TAG_EXISTS=true" >> $GITHUB_OUTPUT
echo "Tag $VERSION already exists"
else
echo "TAG_EXISTS=false" >> $GITHUB_OUTPUT
echo "Tag $VERSION does not exist"
fi
- name: "Determine Release Strategy"
id: strategy
run: |
VERSION=${{ steps.version.outputs.VERSION }}
TAG_EXISTS=${{ steps.tag_check.outputs.TAG_EXISTS }}
OVERWRITE_VERSION=${{ github.event.inputs.overwrite_version == 'true' && 'true' || 'false' }}
if [ "$OVERWRITE_VERSION" = "true" ]; then
echo "STRATEGY=overwrite-version" >> $GITHUB_OUTPUT
echo "PRERELEASE=false" >> $GITHUB_OUTPUT
echo "Strategy: Overwriting version tag ($VERSION)"
elif [ "$TAG_EXISTS" = "true" ]; then
echo "STRATEGY=update-beta" >> $GITHUB_OUTPUT
echo "PRERELEASE=true" >> $GITHUB_OUTPUT
echo "Strategy: Updating beta tag with current version"
else
echo "STRATEGY=create-release" >> $GITHUB_OUTPUT
echo "PRERELEASE=false" >> $GITHUB_OUTPUT
echo "Strategy: Creating new release tag ($VERSION)"
fi
- name: "Final Version Tag"
id: final_tag
run: |
VERSION=${{ steps.version.outputs.VERSION }}
STRATEGY=${{ steps.strategy.outputs.STRATEGY }}
if [ "$STRATEGY" = "update-beta" ]; then
echo "VERSION=Unreleased" >> $GITHUB_OUTPUT
fi
if [ "$STRATEGY" = "create-release" ]; then
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
fi
if [ "$STRATEGY" = "overwrite-version" ]; then
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
fi
echo "Final version tag: $VERSION"
outputs:
VERSION: ${{ steps.final_tag.outputs.VERSION }}
TAG: "${{ steps.final_tag.outputs.VERSION }}"
TAG_EXISTS: ${{ steps.tag_check.outputs.TAG_EXISTS }}
STRATEGY: ${{ steps.strategy.outputs.STRATEGY }}
PRERELEASE: ${{ steps.strategy.outputs.PRERELEASE }}
parse_changelog:
runs-on: ubuntu-latest
needs: verify_version
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Parse Changelog
id: release_notes
run: |
VERSION=${{ needs.verify_version.outputs.VERSION }}
# Remove 'v' prefix if present for changelog lookup
CHANGELOG_VERSION=${VERSION#v}
RELEASE_NOTES=$(awk -v ver="$CHANGELOG_VERSION" '
/^## \[/ {
if (found) exit
if (index($0, "[" ver "]") > 0) found = 1
next
}
found { print }
' CHANGELOG.md)
# Store in a temporary file
echo "$RELEASE_NOTES" > release_notes.txt
echo "body<<EOF" >> "$GITHUB_OUTPUT"
printf '%s\n' "$RELEASE_NOTES" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: "Display Release Notes"
run: |
echo "Release Notes for version ${{ needs.verify_version.outputs.VERSION }}:"
echo ""
cat release_notes.txt
outputs:
body: ${{ steps.release_notes.outputs.body }}
package_and_release:
needs: [verify_version, parse_changelog]
name: "Package and Release"
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: dtolnay/rust-toolchain@stable
- name: "Create Release Folder"
run: |
mkdir "$env:RUNNER_TEMP\release\Mods\tech\DCS-gRPC"
mkdir "$env:RUNNER_TEMP\release\Scripts\DCS-gRPC"
mkdir "$env:RUNNER_TEMP\release\Scripts\Hooks"
mkdir "$env:RUNNER_TEMP\release\Docs\DCS-gRPC\protos"
shell: pwsh
- name: "Main Code"
run: |
cargo build --release
shell: pwsh
- name: "Copy Build Artifacts"
run: |
Copy-Item "target\release\dcs_grpc.dll" "$env:RUNNER_TEMP\release\Mods\tech\DCS-gRPC\dcs_grpc.dll"
Copy-Item "target\release\dcs_grpc.pdb" "$env:RUNNER_TEMP\release\Mods\tech\DCS-gRPC\dcs_grpc.pdb"
shell: pwsh
- name: "Copy Scripts"
run: |
Copy-Item -Recurse -Force "lua\DCS-gRPC" "$env:RUNNER_TEMP\release\Scripts\"
Copy-Item -Recurse -Force "lua\Hooks" "$env:RUNNER_TEMP\release\Scripts\"
shell: pwsh
- name: "Docs"
run: |
Copy-Item "README.md" "$env:RUNNER_TEMP\release\Docs\DCS-gRPC\README.md"
Copy-Item "CHANGELOG.md" "$env:RUNNER_TEMP\release\Docs\DCS-gRPC\CHANGELOG.md"
Copy-Item "STATUS.md" "$env:RUNNER_TEMP\release\Docs\DCS-gRPC\STATUS.md"
shell: pwsh
- name: "Copy Proto Files"
run: |
Copy-Item -Recurse -Force "protos\*" "$env:RUNNER_TEMP\release\Docs\DCS-gRPC\protos"
shell: pwsh
- name: "Zip Release Folder"
run: |
Compress-Archive -Path "$env:RUNNER_TEMP\release\*" -DestinationPath "$env:RUNNER_TEMP\DCS-gRPC-${{ needs.verify_version.outputs.VERSION }}.zip"
shell: pwsh
- uses: actions/upload-artifact@v7
with:
name: DCS-gRPC-${{ needs.verify_version.outputs.VERSION }}.zip
path: ${{ runner.temp }}\DCS-gRPC-${{ needs.verify_version.outputs.VERSION }}.zip
retention-days: 1
- name: Remove existing tag if it exists
if: ${{ needs.verify_version.outputs.STRATEGY == 'overwrite-version' || needs.verify_version.outputs.STRATEGY == 'update-beta' }}
id: check_tag
shell: pwsh
run: |
$TAG = "${{ needs.verify_version.outputs.TAG }}"
$tagExists = git tag | Where-Object { $_ -eq $TAG }
if ($tagExists) {
Write-Host "Tag exists. Removing it..."
git push origin ":refs/tags/$TAG" 2>$null || $true
git tag -d $TAG 2>$null || $true
}
Write-Host "Ready to create fresh tag: $TAG"
- name: Create new tag
shell: pwsh
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions@github.com"
$TAG = "${{ needs.verify_version.outputs.TAG }}"
git tag $TAG
git push origin $TAG
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.verify_version.outputs.TAG }}
release_name: Release ${{ needs.verify_version.outputs.TAG }}
body: ${{ needs.parse_changelog.outputs.body }}
draft: false
prerelease: ${{ needs.verify_version.outputs.PRERELEASE }}