-
-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (137 loc) · 5.21 KB
/
version-controller.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
---
# .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
run: |
rm -rf scripts
git rm -r --cached scripts
ls -la
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 title = `from ${{ steps.determine_branch.outputs.current_branch }} - ${{ steps.get_commit.outputs.commit_message }} into ${{ steps.determine_branch.outputs.next_branch }}`;
const body = `Automatically created pull request for release ${{ steps.create_tag.outputs.tag_name }} 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 }}