Skip to content

Commit 55b1873

Browse files
committed
ci: better publish gh releases (try)
1 parent 3b0d8a0 commit 55b1873

File tree

5 files changed

+47
-37
lines changed

5 files changed

+47
-37
lines changed

.changeset/olive-melons-smash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"mobx-tanstack-query": patch
3+
---
4+
5+
ci: better publish gh release (try)

.github/workflows/version-or-publish.yml

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,47 +46,46 @@ jobs:
4646
- name: Create Release Pull Request
4747
uses: changesets/action@v1
4848
continue-on-error: false
49+
id: pub-or-release-pr
4950
with:
5051
version: pnpm changeset version
51-
publish: pnpm pub-ci
52+
publish: pnpm pub-ci # на этом этапе в ноде пишется process.env.PUBLISHED_GIT_TAG и process.env.PUBLISHED_VERSION_RELEASE_NOTES
5253
env:
5354
GITHUB_TOKEN: ${{ github.token }}
5455
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
5556
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
5657

57-
- name: Get latest tag after changeset
58-
id: after-tag
59-
continue-on-error: false
58+
- name: Export release variables
59+
id: export-release
6060
run: |
61-
git fetch --tags
62-
tag=$(git for-each-ref --sort=-creatordate --format '%(refname:short)' refs/tags | head -n 1)
63-
if [ -z "$tag" ]; then
64-
echo "new_tag=$last_tag" >> $GITHUB_OUTPUT
61+
# Проверяем существование переменных
62+
if [ -n "$PUBLISHED_GIT_TAG" ]; then
63+
echo "tag=$PUBLISHED_GIT_TAG" >> $GITHUB_OUTPUT
6564
else
66-
echo "new_tag=$tag" >> $GITHUB_OUTPUT
65+
echo "tag=" >> $GITHUB_OUTPUT
66+
fi
67+
68+
# Обрабатываем release notes
69+
if [ -n "$PUBLISHED_VERSION_RELEASE_NOTES" ]; then
70+
NOTES="$PUBLISHED_VERSION_RELEASE_NOTES"
71+
# Экранирование для GitHub Actions
72+
NOTES="${NOTES//'%'/'%25'}"
73+
NOTES="${NOTES//$'\n'/'%0A'}"
74+
NOTES="${NOTES//$'\r'/'%0D'}"
75+
echo "notes=$NOTES" >> $GITHUB_OUTPUT
76+
else
77+
echo "notes=" >> $GITHUB_OUTPUT
6778
fi
68-
69-
- name: Convert version to anchor format
70-
id: version_anchor
71-
run: |
72-
clean_version="${VERSION#v}"
73-
anchor_version="${clean_version//./}"
74-
echo "anchor_version=$anchor_version" >> $GITHUB_OUTPUT
75-
env:
76-
VERSION: ${{ steps.after-tag.outputs.new_tag }}
77-
7879
7980
- name: Create GitHub Release
80-
if: steps.before-tag.outputs.last_tag != steps.after-tag.outputs.new_tag
81+
if: steps.export-release.outputs.tag != ''
8182
continue-on-error: false
8283
uses: actions/create-release@v1
8384
env:
8485
GITHUB_TOKEN: ${{ github.token }}
8586
with:
86-
tag_name: ${{ steps.after-tag.outputs.new_tag }}
87-
release_name: ${{ steps.after-tag.outputs.new_tag }}
88-
body: |
89-
## [Changelog for release notes](https://github.com/js2me/mobx-tanstack-query/blob/master/CHANGELOG.md#${{ steps.version_anchor.outputs.anchor_version }})
90-
Changes: https://github.com/${{ github.repository }}/compare/${{ steps.before-tag.outputs.last_tag }}...${{ steps.after-tag.outputs.new_tag }}
87+
tag_name: ${{ steps.export-release.outputs.tag }}
88+
release_name: ${{ steps.export-release.outputs.tag }}
89+
body: ${{ steps.export-release.outputs.notes }}
9190
draft: false
9291
prerelease: false

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"commitfmt": "^1.0.0",
6161
"eslint": "^8.57.0",
6262
"js2me-eslint-config": "^1.0.6",
63-
"js2me-exports-post-build-script": "^3.0.5",
63+
"js2me-exports-post-build-script": "^4.1.1",
6464
"jsdom": "^25.0.1",
6565
"lefthook": "^1.11.13",
6666
"nodemon": "^3.1.0",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

post-build.mjs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
import { postBuildScript, publishScript } from 'js2me-exports-post-build-script';
1+
import { postBuildScript, publishScript, getInfoFromChangelog } from 'js2me-exports-post-build-script';
22

33
postBuildScript({
44
buildDir: 'dist',
55
rootDir: '.',
66
srcDirName: 'src',
77
filesToCopy: ['LICENSE', 'README.md', 'assets'],
88
updateVersion: process.env.PUBLISH_VERSION,
9-
onDone: (versionsDiff, { $ }, packageJson, { targetPackageJson }) => {
9+
onDone: (versionsDiff, targetPackageJson, { $ }) => {
1010
if (process.env.PUBLISH) {
1111
if (!process.env.CI) {
1212
$('pnpm test');
1313
$('pnpm changeset version');
1414
}
1515

16-
const nextVersion = versionsDiff?.next ?? packageJson.version;
16+
const nextVersion = versionsDiff?.next ?? targetPackageJson.data.version;
1717

18-
publishScript({
18+
const publishOutput = publishScript({
1919
gitTagFormat: '<tag>',
2020
nextVersion: nextVersion,
21-
currVersion: versionsDiff?.current,
2221
packageManager: 'pnpm',
2322
commitAllCurrentChanges: true,
2423
createTag: true,
@@ -29,7 +28,14 @@ postBuildScript({
2928
githubRepoLink: 'https://github.com/js2me/mobx-tanstack-query',
3029
cleanupCommand: 'pnpm clean',
3130
targetPackageJson
32-
})
31+
});
32+
33+
if (process.env.CI) {
34+
if (publishOutput.publishedGitTag) {
35+
const { whatChangesText } = getInfoFromChangelog(nextVersion, `${targetPackageJson.locationDir}/CHANGELOG.md`);
36+
process.env.PUBLISHED_VERSION_RELEASE_NOTES = whatChangesText;
37+
}
38+
}
3339
}
3440
}
3541
});

0 commit comments

Comments
 (0)