-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (93 loc) · 3.69 KB
/
semantic-release.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
name: Release Workflow
on:
workflow_dispatch:
inputs:
releaseType:
description: 'Type of release (major, minor, patch, prerelease). Set "auto" for automatic determination.'
required: false
default: 'auto'
type: choice
options:
- auto
- prerelease
- patch
- minor
- major
noop:
type: boolean
description: 'Run in dry-run mode? Set to "true" to enable.'
required: true
default: false
prerelease_token:
type: string
description: 'Prerelease token to use for prerelease versions.'
required: false
default: 'rc'
add_branch_date:
type: boolean
description: 'Add branch and data to release name.'
required: false
default: false
jobs:
release:
runs-on: ubuntu-latest
concurrency: release
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false # Do not store credentials as they will be configured manually
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install Dependencies
run: pip install python-semantic-release
- name: Get Current Date
id: get-date
run: echo "CURRENT_DATE=$(date +%Y%m%d)" >> $GITHUB_ENV
- name: Configure git
env:
REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
run: |
git config user.name 'github-actions'
git config user.email 'github-actions@github.com'##
# Inject the token directly into the remote URL securely
git remote set-url origin https://${{ github.actor }}:${REPO_ACCESS_TOKEN}@github.com/${{ github.repository }}.git
- name: Python Semantic Release
env:
GH_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} # This ensures the token is safely injected from your repository secrets
REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
CURRENT_DATE: $(date +%Y%m%d) # Set the current date in the format YYYYMMDD
run: |
release_type="${{ github.event.inputs.releaseType }}"
prerelease_token="${{ github.event.inputs.prerelease_token }}"
add_branch_date="${{ github.event.inputs.add_branch_date }}"
# flags following "version" command
version_flags=""
# top level flags for semantic-release
toplevel_flags=""
# Add --noop if requested
if [[ "${{ github.event.inputs.noop }}" == "true" ]]; then
toplevel_flags="$toplevel_flags --noop"
fi
# Check releaseType and format accordingly
if [[ "$release_type" != "auto" ]]; then
version_flags="$version_flags --$release_type"
fi
# Check for prerelease token and add it if present
if [[ "$prerelease_token" != "" ]]; then
version_flags="$version_flags --prerelease-token $prerelease_token"
fi
# Add build metadata if add_branch_date is true
if [[ "$add_branch_date" == "true" ]]; then
metadata=$(echo $(basename $GITHUB_REF) | sed 's/refs\/heads\///') # Extract branch name from GITHUB_REF
build_metadata="--build-metadata $metadata.$CURRENT_DATE"
version_flags="$version_flags $build_metadata"
fi
# Run semantic-release with the constructed flags
echo "Running semantic-release with flags (top-level): $toplevel_flags, (version): $version_flags"
GH_TOKEN=${REPO_ACCESS_TOKEN} semantic-release $toplevel_flags version $version_flags