-
Notifications
You must be signed in to change notification settings - Fork 42
134 lines (129 loc) · 5.02 KB
/
deployment.yml
File metadata and controls
134 lines (129 loc) · 5.02 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
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
name: Deployment
on:
push:
pull_request:
workflow_dispatch:
inputs:
check-ci:
description: "Require the CI to have passed for this commit"
required: true
default: "yes"
version:
description: "Override the release version number (e.g. 5.0.0a5)"
jobs:
deploy-pypi:
name: PyPI deployment
runs-on: ubuntu-latest
if: github.event_name != 'push' || github.repository == 'DIRACGrid/WebAppDIRAC'
permissions:
id-token: write
attestations: write
contents: write
defaults:
run:
shell: bash -l {0}
steps:
# Checkout your main repository properly
- name: Checkout main repository
uses: actions/checkout@v5
with:
fetch-depth: 0 # get full history (so no need for "git fetch --unshallow")
# Configure git identity
- name: Configure git
run: |
git config --global user.email "ci@diracgrid.org"
git config --global user.name "DIRACGrid CI"
# Checkout the DIRAC dependency
- name: Checkout DIRAC dependency
uses: actions/checkout@v5
with:
repository: DIRACGrid/DIRAC
path: DIRAC
# Set up Python
- uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Installing dependencies
run: |
python -m pip install \
build \
python-dateutil \
pytz \
readme_renderer \
requests \
setuptools_scm \
- name: Validate README for PyPI
run: |
python -m readme_renderer README.rst -o /tmp/README.html
- name: Prepare release notes
run: |
set -xeuo pipefail
IFS=$'\n\t'
PREV_VERSION=$(git describe --tags --abbrev=0 --match '*[0-9].[0-9]*' --exclude 'v[0-9]r*' --exclude 'v[0-9][0-9]r*')
REFERENCE_BRANCH=${GITHUB_REF#refs/heads/}
echo "Making release notes for ${REFERENCE_BRANCH} since ${PREV_VERSION}"
./DIRAC/docs/diracdoctools/scripts/dirac-docs-get-release-notes.py \
--token "${{ secrets.GITHUB_TOKEN }}" \
--sinceTag "${PREV_VERSION}" \
--branches "${REFERENCE_BRANCH}" \
--repo "${{ github.repository }}" \
> release.notes.new
cat release.notes.new
- name: Create tag if required
id: check-tag
run: |
set -xeuo pipefail
IFS=$'\n\t'
if [[ "${{ github.repository }}" == "DIRACGrid/WebAppDIRAC" ]]; then
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
if [[ "${{ github.event.ref }}" =~ ^refs/heads/(integration|rel-v([5-9]|[1-9][0-9]+)r[0-9]+)$ ]]; then
echo "Will create a real release"
export NEW_VERSION="v${{ github.event.inputs.version }}"
if [[ "${NEW_VERSION}" == "v" ]]; then
NEW_VERSION=v$(python -m setuptools_scm | sed 's@Guessed Version @@g' | sed -E 's@(\.dev|\+g).+@@g')
export NEW_VERSION
fi
echo "Release will be named $NEW_VERSION"
# Validate the version
python -c $'from packaging.version import Version; v = Version('"'$NEW_VERSION'"$')\nif v.is_devrelease:\n raise ValueError(v)'
# Commit the release notes
mv release.notes release.notes.old
{
echo -e "[${NEW_VERSION}]" && \
tail -n +2 release.notes.new | perl -0777pe 's/\n+$/\n\n/' && \
cat release.notes.old;
} > release.notes
git add release.notes
git commit -m "docs: Add release notes for $NEW_VERSION"
git show
# Create the tag
git tag "$NEW_VERSION"
echo "create-release=true" >> $GITHUB_OUTPUT
echo "new-version=$NEW_VERSION" >> $GITHUB_OUTPUT
fi
fi
fi
- name: Build distributions
run: |
python -m build
- name: Make release on GitHub
if: steps.check-tag.outputs.create-release == 'true'
run: |
set -e
export NEW_VERSION=${{ steps.check-tag.outputs.new-version }}
echo "Pushing tagged release notes to ${GITHUB_REF#refs/heads/}"
git push "origin" "${GITHUB_REF#refs/heads/}"
echo "Making GitHub release for ${NEW_VERSION}"
./DIRAC/.github/workflows/make_release.py \
--repo="${{ github.repository }}" \
--token="${{ secrets.GITHUB_TOKEN }}" \
--version="${NEW_VERSION}" \
--rev="$(git rev-parse HEAD)" \
--release-notes-fn="release.notes.new"
- name: Publish package on PyPI
if: steps.check-tag.outputs.create-release == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
repository-url: https://upload.pypi.org/legacy/