Skip to content

Commit

Permalink
Version Packages
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbuechner committed Apr 24, 2023
1 parent a94a9da commit 739cd1f
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 88 deletions.
118 changes: 108 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ on:
branches:
- main
workflow_dispatch:
inputs:
commit_message:
description: 'Custom commit message'
required: false
default: 'Version Packages'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

jobs:
build:
name: ${{ matrix.os }}-${{ github.workflow }}
name: Build ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand Down Expand Up @@ -48,6 +53,20 @@ jobs:
with:
submodules: true

- name: Bump version
shell: bash
run: |
if [ "${{ matrix.os }}" == "windows-latest" ]; then
RELEASE_VERSION=$(sed -nE 's/^##[[:space:]]+([0-9]+\.[0-9]+\.[0-9]+)/\1/p' CHANGELOG.md | head -1)
sed -i "s/set(VCPKG_FMT_TEMPLATE_VERSION .*)/set(VCPKG_FMT_TEMPLATE_VERSION $RELEASE_VERSION)/" CMakeLists.txt
elif [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
RELEASE_VERSION=$(sed -nE 's/^##[[:space:]]+([0-9]+\.[0-9]+\.[0-9]+)/\1/p' CHANGELOG.md | head -1)
sed -i "s/set(VCPKG_FMT_TEMPLATE_VERSION .*)/set(VCPKG_FMT_TEMPLATE_VERSION $RELEASE_VERSION)/" CMakeLists.txt
elif [ "${{ matrix.os }}" == "macos-latest" ]; then
RELEASE_VERSION=$(sed -nE 's/^##[[:space:]]+([0-9]+\.[0-9]+\.[0-9]+)/\1/p' CHANGELOG.md | head -1)
sed -i '' -E "s/set\(VCPKG_FMT_TEMPLATE_VERSION .*\)/set(VCPKG_FMT_TEMPLATE_VERSION $RELEASE_VERSION)/" CMakeLists.txt
fi
# Create the directory to store the vcpkg's binary cache.
- name: "Create directory '${{ env.VCPKG_DEFAULT_BINARY_CACHE }}'"
run: mkdir -p $VCPKG_DEFAULT_BINARY_CACHE
Expand Down Expand Up @@ -112,7 +131,7 @@ jobs:

# Package (Release configuration only).
- name: Package (Release configuration)
if: "contains(github.event.head_commit.message, 'ci(changesets): version packages')"
if: "contains(github.event.head_commit.message, 'Version Packages') || contains(github.event.inputs.commit_message, 'Version Packages')"
shell: bash
run: |
if [ "${{ matrix.os }}" == "windows-latest" ]; then
Expand All @@ -125,7 +144,7 @@ jobs:
# Upload packages as artifacts.
- name: Upload package artifacts
if: "success() && contains(github.event.head_commit.message, 'ci(changesets): version packages')"
if: "success() && contains(github.event.head_commit.message, 'Version Packages') || contains(github.event.inputs.commit_message, 'Version Packages')"
uses: actions/upload-artifact@v3
with:
name: packages-${{ matrix.os }}
Expand Down Expand Up @@ -175,21 +194,100 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Bump version
if: steps.changesets.outputs.published == 'true'
- name: Extract release version and notes from changelog
run: |
RELEASE_VERSION=$(sed -nE 's/^##[[:space:]]+([0-9]+\.[0-9]+\.[0-9]+)/\1/p' CHANGELOG.md | head -1)
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
echo "RELEASE_TAG=v$RELEASE_VERSION" >> $GITHUB_ENV
RELEASE_NOTES=$(awk -v ver="$RELEASE_VERSION" -v latest="## Latest Release" \
'BEGIN {RS=""; ORS="\n\n"; output=0} \
$0 ~ "## " ver {output=1; next} \
$0 ~ latest {output=0} \
output {print $0}' CHANGELOG.md)
if [ -z "$RELEASE_NOTES" ]; then
RELEASE_NOTES=$(awk -v ver="$RELEASE_VERSION" \
'BEGIN {RS=""; ORS="\n\n"; output=0} \
$0 ~ "## " ver {output=1; next} \
output {print $0}' CHANGELOG.md)
fi
RELEASE_NOTES=$(echo "$RELEASE_NOTES" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
echo "$RELEASE_NOTES" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Create and push release tag
if: "contains(github.event.head_commit.message, 'Version Packages') || contains(github.event.inputs.commit_message, 'Version Packages')"
run: |
git tag ${{ env.RELEASE_TAG }}
git push origin ${{ env.RELEASE_TAG }}
- name: Create Release
if: "contains(github.event.head_commit.message, 'Version Packages') || contains(github.event.inputs.commit_message, 'Version Packages')"
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.RELEASE_TAG }}
name: ${{ env.RELEASE_TAG }}
body: ${{ env.RELEASE_NOTES }}
draft: false
prerelease: false

- name: Commit version bump
if: "contains(github.event.head_commit.message, 'Version Packages') || contains(github.event.inputs.commit_message, 'Version Packages')"
run: |
pnpm version-bump
pnpm version-bump:commit
- name: Update changelog
if: steps.changesets.outputs.published == 'true'
if: "contains(github.event.head_commit.message, 'Version Packages') || contains(github.event.inputs.commit_message, 'Version Packages')"
run: |
pnpm changelog:latest
pnpm changelog:format
pnpm changelog:commit
- name: Trigger Upload Workflow
if: steps.changesets.outputs.published == 'true'
uses: benc-uk/workflow-dispatch@v1
upload:
name: Upload packages artifacts
if: "contains(github.event.head_commit.message, 'Version Packages') || contains(github.event.inputs.commit_message, 'Version Packages')"
needs: [build, publish]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Download packages-windows-latest artifact
uses: actions/download-artifact@v3
with:
name: packages-windows-latest
path: artifacts

- name: Download packages-ubuntu-latest artifact
uses: actions/download-artifact@v3
with:
name: packages-ubuntu-latest
path: artifacts

- name: Download packages-macos-latest artifact
uses: actions/download-artifact@v3
with:
workflow: Upload artifacts
name: packages-macos-latest
path: artifacts

- name: Get latest release
id: latest_release
run: |
RELEASE_ID=$(gh release list --repo $GITHUB_REPOSITORY | head -n 1 | awk '{print $1}')
echo "RELEASE_ID=$RELEASE_ID" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload release assets (packages)
run: |
for file in artifacts/*; do
[ -e "$file" ] || continue
echo "Uploading $file"
gh release upload $RELEASE_ID "$file" --clobber --repo $GITHUB_REPOSITORY
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48 changes: 0 additions & 48 deletions .github/workflows/upload-artifacts.yml

This file was deleted.

30 changes: 0 additions & 30 deletions cmake/vcpkg-fmt-template-cpack.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,6 @@ set(CPACK_PACKAGE_RELOCATABLE ON CACHE BOOL "Build relocatable package")
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
set(CPACK_RPM_PACKAGE_URL ${CPACK_PROJECT_URL})
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${CPACK_PROJECT_URL})
set(CPACK_RPM_PACKAGE_DESCRIPTION "A sample project that uses fmt from vcpkg.")
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "A sample project that uses fmt from vcpkg.")

if (CPACK_PACKAGE_NAME)
set(CPACK_RPM_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
set(CPACK_DEBIAN_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
else ()
set(CPACK_RPM_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}")
set(CPACK_DEBIAN_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}")
set(CPACK_RPM_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_DEBIAN_PACKAGE_NAME "${PROJECT_NAME}")
endif ()

if (CPACK_RPM_PACKAGE_RELEASE)
set(CPACK_RPM_FILE_NAME "${CPACK_RPM_FILE_NAME}-${CPACK_RPM_PACKAGE_RELEASE}")
endif ()
if (CPACK_DEBIAN_PACKAGE_RELEASE)
set(CPACK_DEBIAN_FILE_NAME "${CPACK_DEBIAN_FILE_NAME}-${CPACK_DEBIAN_PACKAGE_RELEASE}")
endif ()

if (CPACK_RPM_PACKAGE_ARCHITECTURE)
set(CPACK_RPM_FILE_NAME "${CPACK_RPM_FILE_NAME}.${CPACK_RPM_PACKAGE_ARCHITECTURE}")
endif ()
if (CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
set(CPACK_DEBIAN_FILE_NAME "${CPACK_DEBIAN_FILE_NAME}.${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
endif ()
set(CPACK_RPM_FILE_NAME "${CPACK_RPM_FILE_NAME}.rpm")
set(CPACK_DEBIAN_FILE_NAME "${CPACK_DEBIAN_FILE_NAME}.deb")

if (NOT CPACK_PACKAGE_RELOCATABLE)
# Depend on pkgconfig rpm to create the system pkgconfig folder
Expand Down

0 comments on commit 739cd1f

Please sign in to comment.