-
-
Notifications
You must be signed in to change notification settings - Fork 17
154 lines (140 loc) · 5.48 KB
/
version-bump.yaml
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
143
144
145
146
147
148
149
150
151
152
153
154
---
name: Version bump ⬆
on:
push:
branches:
- main
workflow_dispatch:
workflow_call:
secrets:
REPO_GITHUB_TOKEN:
description: Github token with write access to the repo
required: false
inputs:
disable-precommit-autoupdate:
description: Disable precommit autoupdate
required: false
default: false
type: boolean
vbump-after-release:
description: Whether the vbump workflow is running after a release has been published
required: false
default: false
type: boolean
package-subdirectory:
description: Subdirectory in the repository, where the R package is located.
required: false
type: string
default: "."
concurrency:
group: vbump-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
vbump:
name: Bump version ⤴
runs-on: ubuntu-latest
if: |
!(contains(github.event.commits[0].message, '[skip vbump]') ||
contains(github.event.head_commit.message, '[skip vbump]')
)
container:
image: docker.io/rocker/tidyverse:latest
steps:
- name: Setup token 🔑
id: github-token
run: |
if [ "${{ secrets.REPO_GITHUB_TOKEN }}" == "" ]; then
echo "REPO_GITHUB_TOKEN is empty. Substituting it with GITHUB_TOKEN."
echo "token=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_OUTPUT
else
echo "Using REPO_GITHUB_TOKEN."
echo "token=${{ secrets.REPO_GITHUB_TOKEN }}" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Checkout repo 🛎
uses: actions/checkout@v4
with:
token: ${{ steps.github-token.outputs.token }}
- name: Bump version in DESCRIPTION 📜
if: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || inputs.vbump-after-release == true }}
run: desc::desc_bump_version("dev", normalize = TRUE)
shell: Rscript {0}
working-directory: ${{ inputs.package-subdirectory }}
- name: Update Date field 📅
run: if (desc::desc_has_fields("Date")) desc::desc_set("Date", Sys.Date())
shell: Rscript {0}
working-directory: ${{ inputs.package-subdirectory }}
- name: Bump version in NEWS.md 📰
run: |
if [ -f NEWS.md ]
then {
git config --global --add safe.directory $(pwd)
DESC_VERSION=$(R --slave -e 'cat(paste(desc::desc_get_version()))' | tr -d '\n' | xargs)
NEWS_VERSION=$(awk '/^#+ /{print $3,$4; exit}' NEWS.md | tr -d '\n' | xargs)
FIRST_NEWS_LINE=$(head -1 NEWS.md)
if [ "${{ inputs.vbump-after-release }}" == "true" ]; then
# Add a new section with the released version that will be vbumped below.
printf "$FIRST_NEWS_LINE\n\n" | cat - NEWS.md > temp-news.md
mv temp-news.md NEWS.md
fi
# Replace only the first occurence of $NEWS_VERSION,
# but only if it's not already set to (development version)
if [ $NEWS_VERSION != "(development version)" ]
then {
sed -i "0,/$NEWS_VERSION/s/$NEWS_VERSION/$DESC_VERSION/" NEWS.md
}
fi
echo "NEW_PKG_VERSION=${DESC_VERSION}" >> $GITHUB_ENV
}
fi
shell: bash
working-directory: ${{ inputs.package-subdirectory }}
- name: Check if a pre-commit config exists
id: precommit-config-exists
uses: andstor/file-existence-action@v3
with:
files: ".pre-commit-config.yaml"
- name: Setup Python 🐍
if: |
inputs.disable-precommit-autoupdate != 'true' &&
steps.precommit-config-exists.outputs.files_exists == 'true'
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Precommit autoupdate 🅿️
if: |
inputs.disable-precommit-autoupdate != 'true' &&
steps.precommit-config-exists.outputs.files_exists == 'true'
run: |
git config --global --add safe.directory $(pwd)
python -m pip -q install pre-commit
pre-commit autoupdate
- name: Checkout to main 🛎
if: ${{ inputs.vbump-after-release == true }}
run: |
git fetch origin main
git checkout main
git pull origin main
- name: Set file pattern to commit ⚙️
id: file-pattern
run: |
if [[ "${{ inputs.package-subdirectory }}" == "." || "${{ inputs.package-subdirectory }}" == "" ]]; then
FILE_PATTERN="NEWS.md DESCRIPTION"
else
FILE_PATTERN="${{ inputs.package-subdirectory }}/NEWS.md ${{ inputs.package-subdirectory }}/DESCRIPTION"
fi
if [[ '${{ steps.precommit-config-exists.outputs.files_exists }}' == 'true' ]]; then
FILE_PATTERN="$FILE_PATTERN .pre-commit-config.yaml"
fi
echo "file-pattern=$FILE_PATTERN" >> $GITHUB_OUTPUT
shell: bash
- name: Commit and push changes 📌
if: ${{ env.NEW_PKG_VERSION }}
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "[skip actions] Bump version to ${{ env.NEW_PKG_VERSION }}"
file_pattern: "${{ steps.file-pattern.outputs.file-pattern }}"
commit_user_name: github-actions
commit_user_email: >-
41898282+github-actions[bot]@users.noreply.github.com
continue-on-error: true