Repository navigation
74 lines (66 loc) · 2.61 KB
/
Copy pathrelease.yml
File metadata and controls
74 lines (66 loc) · 2.61 KB
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
name: Release
# Manually started from the Actions tab (or `gh workflow run release.yml -f
# version=X.Y.Z`). Sets __version__, commits "Version number -> X.Y.Z" on
# main, tags it X.Y.Z, pushes both, then starts publish.yml on the new tag.
on:
workflow_dispatch:
inputs:
version:
description: "Version to release, e.g. 1.2.0 or 1.2.0rc1 (no 'v' prefix)"
required: true
type: string
permissions: {}
concurrency:
group: release
cancel-in-progress: false
jobs:
release:
name: Bump, tag and trigger publish
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
permissions:
contents: write # push the version commit and tag
actions: write # start publish.yml
env:
VERSION: ${{ inputs.version }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Validate version
env:
GH_TOKEN: ${{ github.token }}
run: |
if ! [[ "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?$ ]]; then
echo "::error::'${VERSION}' is not a version like 1.2.0 or 1.2.0rc1"
exit 1
fi
if gh api "repos/${GITHUB_REPOSITORY}/git/ref/tags/${VERSION}" --silent 2>/dev/null; then
echo "::error::Tag ${VERSION} already exists"
exit 1
fi
- name: Set __version__
run: |
sed -i -E "s/^__version__ = \".*\"$/__version__ = \"${VERSION}\"/" ipython_pygments_lexers/__init__.py
grep -qx "__version__ = \"${VERSION}\"" ipython_pygments_lexers/__init__.py
if git diff --quiet; then
echo "::error::__version__ is already ${VERSION}"
exit 1
fi
- name: Commit, tag and push
env:
GH_TOKEN: ${{ github.token }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -am "Version number -> ${VERSION}"
git tag -a "${VERSION}" -m "Release ${VERSION}"
git push --atomic "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" \
HEAD:refs/heads/main "refs/tags/${VERSION}"
- name: Start publish workflow
env:
GH_TOKEN: ${{ github.token }}
run: |
gh workflow run publish.yml --repo "${GITHUB_REPOSITORY}" --ref "${VERSION}"
echo "Publishing ${VERSION}: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/workflows/publish.yml" >> "${GITHUB_STEP_SUMMARY}"