Skip to content

Commit 1083dfc

Browse files
committed
fix: version workflow
1 parent 220b6f8 commit 1083dfc

File tree

2 files changed

+102
-10
lines changed

2 files changed

+102
-10
lines changed

.github/workflows/publish-conan.yml

Lines changed: 91 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,42 @@ on:
44
push:
55
tags:
66
- 'v*'
7+
workflow_dispatch:
8+
inputs:
9+
publish:
10+
description: 'Publish to Conan Center (must be set to "true")'
11+
required: true
12+
type: boolean
13+
default: false
714

815
jobs:
9-
publish:
16+
extract-version:
1017
runs-on: ubuntu-latest
18+
outputs:
19+
version: ${{ steps.version.outputs.version }}
20+
tag: ${{ steps.version.outputs.tag }}
21+
steps:
22+
- name: Extract version from tag
23+
id: version
24+
run: |
25+
if [ "${{ github.event_name }}" = "push" ]; then
26+
TAG=${GITHUB_REF#refs/tags/}
27+
VERSION=${TAG#v}
28+
else
29+
# For workflow_dispatch, use the tag input or default
30+
TAG=${GITHUB_REF#refs/tags/}
31+
VERSION=${TAG#v}
32+
fi
33+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
34+
echo "tag=${TAG}" >> $GITHUB_OUTPUT
35+
echo "Tag: ${TAG}, Version: ${VERSION}"
36+
37+
publish-conan:
38+
needs: extract-version
39+
runs-on: ubuntu-latest
40+
if: |
41+
(github.event_name == 'workflow_dispatch' && inputs.publish == true) ||
42+
(github.event_name == 'push' && vars.PUBLISH_TO_CONAN == 'true')
1143
permissions:
1244
contents: write
1345
pull-requests: write
@@ -18,13 +50,6 @@ jobs:
1850
with:
1951
fetch-depth: 0
2052

21-
- name: Extract version from tag
22-
id: version
23-
run: |
24-
VERSION=${GITHUB_REF#refs/tags/v}
25-
echo "version=${VERSION}" >> $GITHUB_OUTPUT
26-
echo "Tag: ${GITHUB_REF}, Version: ${VERSION}"
27-
2853
- name: Setup Git
2954
run: |
3055
git config --global user.name "github-actions[bot]"
@@ -54,5 +79,62 @@ jobs:
5479
CONAN_INDEX_DIR: ${{ github.workspace }}/conan-center-index
5580
GITHUB_TOKEN: ${{ secrets.CONAN_INDEX_PAT || secrets.GITHUB_TOKEN }}
5681
run: |
57-
./scripts/publish-conan-version.sh "${{ steps.version.outputs.version }}"
82+
./scripts/publish-conan-version.sh "${{ needs.extract-version.outputs.version }}"
83+
84+
create-release:
85+
needs: extract-version
86+
runs-on: ubuntu-latest
87+
if: github.event_name == 'push'
88+
permissions:
89+
contents: write
90+
91+
steps:
92+
- name: Checkout repository
93+
uses: actions/checkout@v4
94+
with:
95+
fetch-depth: 0
96+
97+
- name: Generate release notes
98+
id: release_notes
99+
run: |
100+
TAG="${{ needs.extract-version.outputs.tag }}"
101+
VERSION="${{ needs.extract-version.outputs.version }}"
102+
103+
# Try to extract release notes from CHANGELOG.md if it exists
104+
if [ -f CHANGELOG.md ]; then
105+
# Extract section for this version (format: ## [version] or ## [version] - date)
106+
# Use awk to extract from the version heading until the next ## heading or --- separator
107+
RELEASE_NOTES=$(awk -v version="${VERSION}" '
108+
BEGIN { in_section = 0 }
109+
/^## \[/ {
110+
if (in_section) exit
111+
if ($0 ~ "\\[" version "\\]") in_section = 1
112+
}
113+
/^---$/ { if (in_section) exit }
114+
in_section { print }
115+
' CHANGELOG.md)
116+
else
117+
RELEASE_NOTES=""
118+
fi
119+
120+
# If no notes found, create a simple one
121+
if [ -z "$RELEASE_NOTES" ]; then
122+
RELEASE_NOTES="## Release ${VERSION}
123+
124+
This release includes the latest changes and improvements."
125+
fi
126+
127+
# Use multiline output
128+
echo "notes<<EOF" >> $GITHUB_OUTPUT
129+
echo "$RELEASE_NOTES" >> $GITHUB_OUTPUT
130+
echo "EOF" >> $GITHUB_OUTPUT
131+
132+
- name: Create GitHub Release
133+
uses: softprops/action-gh-release@v1
134+
with:
135+
tag_name: ${{ needs.extract-version.outputs.tag }}
136+
name: Release ${{ needs.extract-version.outputs.version }}
137+
body: ${{ steps.release_notes.outputs.notes }}
138+
draft: false
139+
prerelease: ${{ contains(needs.extract-version.outputs.version, '-rc') || contains(needs.extract-version.outputs.version, '-alpha') || contains(needs.extract-version.outputs.version, '-beta') }}
58140

scripts/publish-conan-version.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ else
8181
cd "${CONAN_INDEX_DIR}"
8282
if [ "${DRY_RUN}" != true ]; then
8383
git fetch upstream master
84+
git fetch origin master 2>/dev/null || true
85+
# We merge upstream to get latest recipe structure, but create branches from origin/master
86+
# to avoid including workflow changes that require 'workflow' scope
8487
git checkout master 2>/dev/null || git checkout -b master
8588
git merge upstream/master || true
8689
fi
@@ -274,7 +277,14 @@ fi
274277

275278
# Create branch and commit
276279
echo "Creating branch and committing..."
277-
git checkout -b "${BRANCH_NAME}" 2>/dev/null || git checkout "${BRANCH_NAME}"
280+
# Create branch from origin/master (fork's state) to avoid including workflow changes from merge
281+
# This prevents requiring 'workflow' scope when pushing
282+
if git show origin/master >/dev/null 2>&1; then
283+
git checkout -b "${BRANCH_NAME}" origin/master 2>/dev/null || git checkout "${BRANCH_NAME}"
284+
else
285+
# Fallback: create from current branch if origin/master doesn't exist
286+
git checkout -b "${BRANCH_NAME}" 2>/dev/null || git checkout "${BRANCH_NAME}"
287+
fi
278288
git add "${RECIPE_DIR}/"
279289
git commit -m "Add influxdb-cpp-rest/${VERSION}
280290

0 commit comments

Comments
 (0)