✨ feat(core): update cazira doc compiler #64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# .github/workflows/version-controller.yml | |
name: Version Controller | |
on: | |
push: | |
branches: | |
- dev | |
- test | |
- prod | |
- main | |
jobs: | |
version-controller: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
id: checkout_repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python | |
id: setup_python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.12' | |
- name: Install Dependencies | |
id: install_dependencies | |
run: | | |
pip install bump2version toml | |
- name: Get Current Version | |
id: get_version | |
run: | | |
VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['tool']['poetry']['version'])") | |
echo "current_version=$VERSION" >> $GITHUB_OUTPUT | |
- name: Get Latest Commit Message | |
id: get_commit | |
run: | | |
COMMIT_MESSAGE=$(git log -1 --pretty=%B) | |
echo "commit_message<<EOF" >> $GITHUB_OUTPUT | |
echo "$COMMIT_MESSAGE" >> $GITHUB_OUTPUT | |
echo "EOF" >> $GITHUB_OUTPUT | |
- name: Determine Branch | |
id: determine_branch | |
run: | | |
CURRENT_BRANCH=${GITHUB_REF#refs/heads/} | |
if [ "$CURRENT_BRANCH" = "dev" ]; then | |
NEXT_BRANCH="test" | |
elif [ "$CURRENT_BRANCH" = "test" ]; then | |
NEXT_BRANCH="prod" | |
elif [ "$CURRENT_BRANCH" = "prod" ]; then | |
NEXT_BRANCH="main" | |
else | |
NEXT_BRANCH="" | |
fi | |
echo "next_branch=$NEXT_BRANCH" >> $GITHUB_OUTPUT | |
echo "current_branch=$CURRENT_BRANCH" >> $GITHUB_OUTPUT | |
- name: Add Modules | |
id: add_modules | |
env: | |
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} | |
run: | | |
git config --global url."https://${ACCESS_TOKEN}@github.com/".insteadOf "https://github.com/" | |
git rm -r --cached scripts || true | |
rm -rf scripts | |
git submodule add -b ${{ steps.determine_branch.outputs.current_branch }} https://github.com/JuanVilla424/scripts.git | |
# - name: Run Changelog Generator | |
# id: run_changelog | |
# run: | | |
# python scripts/generate_changelog/main.py | |
- name: Check for Forbidden Character | |
id: check_arrow | |
run: | | |
if [[ "${{ steps.get_commit.outputs.commit_message }}" == *"→"* && "${{ steps.get_commit.outputs.commit_message }}" == *"Bump version:"* ]]; then | |
echo "contains_arrow=true" >> $GITHUB_OUTPUT | |
else | |
echo "contains_arrow=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Create Tag | |
id: create_tag | |
if: steps.check_arrow.outputs.contains_arrow == 'true' | |
run: | | |
VERSION=${{ steps.get_version.outputs.current_version }} | |
BRANCH_NAME=${{ steps.determine_branch.outputs.current_branch }} | |
TAG_NAME="v${VERSION}-${BRANCH_NAME}" | |
git tag "$TAG_NAME" | |
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT | |
continue-on-error: true | |
- name: Push Tag | |
id: push_tag | |
if: steps.check_arrow.outputs.contains_arrow == 'true' | |
run: | | |
git push origin "${{ steps.create_tag.outputs.tag_name }}" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Ensure on Current Branch | |
id: ensure_branch | |
if: steps.check_arrow.outputs.contains_arrow == 'true' | |
run: | | |
git checkout "${{ steps.determine_branch.outputs.current_branch }}" | |
- name: Create Pull Request | |
id: create_pull_request | |
if: steps.check_arrow.outputs.contains_arrow == 'true' && github.ref != 'refs/heads/main' | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const head = '${{ steps.determine_branch.outputs.current_branch }}'; | |
const base = '${{ steps.determine_branch.outputs.next_branch }}'; | |
const version = '${{ steps.create_tag.outputs.tag_name }}'; | |
const title = `🔖 From ${head} → Bump version: ${version} into ${base}`; | |
const body = `Automatically created pull request for release ${version} into ${base} branch.`; | |
const { data: existingPRs } = await github.rest.pulls.list({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
head: head, | |
base: base, | |
state: 'open' | |
}); | |
if (existingPRs.length === 0) { | |
const { data: pr } = await github.rest.pulls.create({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
head: head, | |
base: base, | |
title: title, | |
body: body | |
}); | |
console.log(`Created PR #${pr.number}: ${pr.html_url}`); | |
} else { | |
console.log(`PR already exists: ${existingPRs[0].html_url}`); | |
} | |
- name: Push Tag for Main Branch | |
id: push_tag_to_main | |
if: github.ref == 'refs/heads/main' && steps.check_arrow.outputs.contains_arrow == 'true' | |
run: | | |
VERSION=${{ steps.get_version.outputs.current_version }} | |
TAG_NAME="v${VERSION}" | |
git tag "$TAG_NAME" | |
git push origin "$TAG_NAME" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |