Closed
Description
Question
Hello, I want to know if it is possible to update a JSON file using the resulting tag of the semantic release before upload the release to GitHub.
I tried something, but my plugin.json
file is not updated by the CI/CD, should I use the assets key in the TOML file to specify the path to my JSON file, or manually add commit and push in the CI/CD script ?
Configuration
I use GitHub Action to run semantic release, here is the CI/CD:
name: "Run Semantic Release"
on:
push:
branches: [main]
jobs:
release:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9"]
poetry-version: ["1.8.3"]
permissions:
contents: write
id-token: write
concurrency: release
steps:
#----------------------------------------------
# Check-out repository
#----------------------------------------------
- name: Check out code
uses: actions/checkout@v4
#----------------------------------------------
# Setup Workflow
#----------------------------------------------
- name: Setup Workflow
uses: ./.github/actions/setup
with:
python-version: ${{ matrix.python-version }}
poetry-version: ${{ matrix.poetry-version }}
load-cache: true
#----------------------------------------------
# Run Semantic Release
#----------------------------------------------
- name: Python Semantic Release
id: release
uses: python-semantic-release/python-semantic-release@v8.0.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
#----------------------------------------------
# Install JQ to parse JSON
#----------------------------------------------
- name: Install JQ
run: sudo apt-get update && sudo apt-get install jq
shell: bash
#----------------------------------------------
# Update Plugin Version
#----------------------------------------------
- name: Update Plugin Version
env:
tag: ${{ steps.release.outputs.tag }}
run: |
#!/bin/bash
# Update the version in plugin.json directly
jq --arg version "$tag" '.version = $version' plugin.json > tmp.json && mv tmp.json plugin.json
shell: bash
#----------------------------------------------
# Publish
#----------------------------------------------
- name: Publish package ditributions to GitHub Releases
uses: python-semantic-release/upload-to-gh-release@main
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Semantic Release Configuration:
[tool.semantic_release]
version_variables = ["python-lib/salesforecast_v2/__init__.py:__version__"]
version_toml = ["pyproject.toml:tool.poetry.version"]
assets = []
tag_format = "{version}"
commit_message = "conf: update plugin to {version} version"
[tool.semantic_release.branches.main]
match = "main"
[tool.semantic_release.commit_parser_options]
allowed_tags = [
"add",
"rm",
"build",
"conf",
"config",
"cfg",
"ci",
"docs",
"feat",
"fix",
"perf",
"style",
"refacto",
"test",
]
minor_tags = ["feat"]
patch_tags = ["fix", "perf"]
[tool.semantic_release.publish]
dist_glob_patterns = ["dist/*"]
Thanks in advance for your help !