Skip to content

Commit 4436f84

Browse files
committed
Release CI
1 parent 949352d commit 4436f84

File tree

5 files changed

+142
-0
lines changed

5 files changed

+142
-0
lines changed

.github/scripts/pack.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# install deps
2+
pip install --upgrade build
3+
4+
# tag the version
5+
sed -i "s/^VERSION = .*$/VERSION = \"${VERSION}\"/" setup.py
6+
sed -i "s/^version = .*$/version = \"${VERSION}\"/" pyproject.toml
7+
8+
# make a package
9+
mkdir -p "${GITHUB_WORKSPACE}/temp"
10+
python -m build --outdir "${GITHUB_WORKSPACE}/temp"
11+
12+
# save the output filename to env
13+
PACKAGE_FILENAME=$(cd "${GITHUB_WORKSPACE}/temp" && ls -1 -- *.tar.gz)
14+
echo "PACKAGE_FILENAME=${PACKAGE_FILENAME}" >> "${GITHUB_ENV}"
15+
16+
mkdir -p "${GITHUB_WORKSPACE}/dist"
17+
mv "${GITHUB_WORKSPACE}/temp/${PACKAGE_FILENAME}" "${GITHUB_WORKSPACE}/dist/${PACKAGE_FILENAME}"

.github/scripts/prepare.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
echo "Publishing ${PROJECT_NAME} to NPM"
2+
echo " Publishing version: ${VERSION}"
3+
echo " Publish tag is ${PUBLISH_TAG}"
4+
5+
# perform publish
6+
if [ "${DRY_RUN}" == "1" ]; then
7+
echo "(dry run)"
8+
else
9+
python3 -m pip install --upgrade build && python3 -m build
10+
fi

.github/scripts/publish_env.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Parse the release tag
2+
3+
# strip leading 'release/'
4+
TAG="${RELEASE_TAG#release/}"
5+
6+
# strip leading v
7+
TAG_VALUE="${TAG#v}"
8+
9+
# strip trailing -dry
10+
VERSION="${TAG_VALUE%-dry}"
11+
12+
# detect valid semver
13+
VALID_VERSION=$(npx -y [email protected] "${VERSION}" --field matches)
14+
if [ "${VALID_VERSION}" != "true" ]; then
15+
exit 1
16+
fi
17+
18+
# Detect dry run mode
19+
DRY_RUN=0
20+
if [ "${TAG_VALUE}" != "${VERSION}" ]; then
21+
DRY_RUN=1
22+
fi
23+
24+
# publish tag ('alpha', 'beta', etc.) is used to tag the release
25+
PUBLISH_TAG="$(npx -y [email protected] "${VERSION}" --field preid)"
26+
if [ "${PUBLISH_TAG}" == "undefined" ]; then
27+
PUBLISH_TAG=latest
28+
fi
29+
30+
echo "API_CLIENT_NAME=Python"
31+
echo "PROJECT_NAME=fastly-py"
32+
echo "VERSION=${VERSION}"
33+
echo "DRY_RUN=${DRY_RUN}"
34+
echo "PUBLISH_TAG=${PUBLISH_TAG}"

.github/scripts/release_body.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
printf '%s' "## ${API_CLIENT_NAME} API client v${VERSION}"
2+
3+
if [ "${DRY_RUN}" == "1" ]; then
4+
printf '%s' " (dry run)"
5+
fi
6+
7+
echo ""
8+
9+
# add a newline
10+
echo ""
11+
12+
CODE_PATH=${CODE_PATH:-./}
13+
G_CODE=$(jq -r .G "${CODE_PATH}/sig.json")
14+
D_CODE=$(jq -r .D "${CODE_PATH}/sig.json")
15+
16+
PACKAGE_FILESIZE=$(ls -lh "${GITHUB_WORKSPACE}/dist/${PACKAGE_FILENAME}" | awk '{print $5}')B
17+
18+
echo "Artifact"
19+
echo " ${PACKAGE_FILENAME} (${PACKAGE_FILESIZE})"
20+
echo ""
21+
echo "Generated on: $(date)"
22+
echo "G-code: ${G_CODE}, D-code: ${D_CODE}"
23+
if [ "${PUBLISH_TAG}" != "latest" ]; then
24+
echo "Pre-release Tag: ${PUBLISH_TAG}"
25+
fi

.github/workflows/ci-release.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Release CI
2+
on:
3+
push:
4+
tags:
5+
- 'release/v?[0-9]*'
6+
7+
env:
8+
RELEASE_TAG: ${{ github.ref_name }}
9+
10+
jobs:
11+
publish:
12+
name: Publish to PyPI
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v3
17+
with:
18+
path: main
19+
- name: Set up environment variables
20+
run: ./.github/scripts/publish_env.sh >> $GITHUB_ENV
21+
working-directory: ./main
22+
shell: bash
23+
- name: Setup Python
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: '3.10'
27+
- name: Pack API client
28+
run: ./.github/scripts/pack.sh
29+
working-directory: ./main
30+
shell: bash
31+
- name: Prepare API client for publish
32+
run: ./.github/scripts/prepare.sh
33+
working-directory: ./main
34+
shell: bash
35+
- name: Publish API client
36+
if: ${{ env.DRY_RUN != '1' }}
37+
uses: pypa/gh-action-pypi-publish@release/v1
38+
with:
39+
password: ${{ secrets.PYPI_PUBLISH_TOKEN }}
40+
packages-dir: ./main/dist/
41+
- name: Write release body file
42+
run: CODE_PATH=./main ./main/.github/scripts/release_body.sh > ./dist/release_body.txt
43+
shell: bash
44+
- name: Create release (dry run)
45+
if: ${{ env.DRY_RUN == '1' }}
46+
run: cat ./dist/release_body.txt
47+
- name: Create GitHub release
48+
if: ${{ env.DRY_RUN != '1' }}
49+
uses: softprops/action-gh-release@v1
50+
with:
51+
name: v${{ env.VERSION }}
52+
body_path: ./dist/release_body.txt
53+
files: |
54+
./dist/${{ env.PACKAGE_FILENAME }}
55+
draft: false
56+
prerelease: ${{ env.PUBLISH_TAG != 'latest' }}

0 commit comments

Comments
 (0)