Skip to content

Commit 2e6d1be

Browse files
committed
refactor: optimize & smartly lock psr dependency version
1 parent 0f96c02 commit 2e6d1be

File tree

4 files changed

+45
-27
lines changed

4 files changed

+45
-27
lines changed

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Default, ignore everything
2+
*
3+
4+
# Except
5+
!requirements.txt
6+
!action.sh
7+
!LICENSE

Dockerfile

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
ARG PYTHON_VERSION=3.10
1+
FROM python:3.10-slim-bookworm
2+
ARG WORK_DIR="/opt/psr"
23

3-
FROM python:${PYTHON_VERSION}
4+
WORKDIR ${WORK_DIR}
45

5-
RUN set -ex; \
6-
apt-get update; \
7-
apt-get install -y --no-install-recommends \
8-
git-lfs
6+
ENV PSR_VENV_BIN="${WORK_DIR}/.venv/bin"
97

10-
#install backported stable vesion of git, which supports ssh signing
11-
RUN echo "deb http://deb.debian.org/debian bullseye-backports main" >> /etc/apt/sources.list; \
12-
apt-get update;\
13-
apt-get install -y git/bullseye-backports \
14-
&& apt-get clean \
15-
&& rm -rf /var/lib/apt/lists/*; \
16-
mkdir /semantic-release
8+
COPY . ./
179

18-
WORKDIR /semantic-release
10+
RUN \
11+
# Install required os packages
12+
apt update && apt install -y --no-install-recommends \
13+
git git-lfs python3-venv \
14+
# Create virtual environment
15+
&& python3 -m venv "$(dirname "${PSR_VENV_BIN}")" \
16+
# Update local pip and built tools
17+
&& "${PSR_VENV_BIN}/pip" install --upgrade --no-cache-dir pip setuptools wheel \
18+
# Install semantic-release (/root/.local/bin)
19+
&& "${PSR_VENV_BIN}/pip" install --pre --no-cache-dir -r requirements.txt \
20+
# Validate binary availability
21+
&& bash -c "${PSR_VENV_BIN}/semantic-release --help" \
22+
# make action script executable
23+
&& chmod +x "${WORK_DIR}/action.sh" \
24+
# Put action script in PATH
25+
&& ln -s "${WORK_DIR}/action.sh" /usr/local/bin/action-entrypoint \
26+
# Clean up
27+
&& apt clean && rm -rf /var/lib/apt/lists/* \
28+
&& find /tmp -mindepth 1 -delete
1929

20-
COPY action.sh /semantic-release/action.sh
21-
22-
RUN pip install --pre --no-cache-dir "python-semantic-release<9"; \
23-
semantic-release --help
24-
25-
ENTRYPOINT ["/semantic-release/action.sh"]
30+
ENTRYPOINT ["/usr/local/bin/action-entrypoint"]

action.sh

100755100644
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22

33
set -e
44

5-
# Copy inputs into correctly-named environment variables
6-
export GH_TOKEN="${INPUT_GITHUB_TOKEN}"
7-
export ROOT_OPTIONS="${INPUT_ROOT_OPTIONS:="-v"}"
8-
9-
# Change to configured directory
10-
cd "${INPUT_DIRECTORY}"
5+
explicit_run_cmd() {
6+
local cmd="$*"
7+
printf '%s\n' "$> $cmd"
8+
eval "$cmd"
9+
}
1110

1211
# See https://github.com/actions/runner-images/issues/6775#issuecomment-1409268124
1312
# and https://github.com/actions/runner-images/issues/6775#issuecomment-1410270956
1413
git config --system --add safe.directory "*"
1514

15+
# Change to configured directory
16+
cd "${INPUT_DIRECTORY}"
17+
18+
# Make Token available as a correctly-named environment variables
19+
export GH_TOKEN="${INPUT_GITHUB_TOKEN}"
20+
1621
# Run Semantic Release
17-
semantic-release ${ROOT_OPTIONS} publish --tag "${INPUT_TAG}"
22+
explicit_run_cmd "$PSR_VENV_BIN/semantic-release ${INPUT_ROOT_OPTIONS} publish --tag ${INPUT_TAG}"

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python-semantic-release == 8.7.0

0 commit comments

Comments
 (0)