Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 76f956a

Browse files
committed
ci: add action to release daily
1 parent ad40e37 commit 76f956a

File tree

7 files changed

+108
-8
lines changed

7 files changed

+108
-8
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Publish Docker image
2+
3+
on:
4+
schedule:
5+
# At the end of every day
6+
- cron: '0 0 * * *'
7+
workflow_dispatch:
8+
# inputs:
9+
# run:
10+
# description: 'Dummy button'
11+
# required: false
12+
# default: true
13+
# type: boolean
14+
15+
jobs:
16+
push_to_registry:
17+
name: Push Docker image to Docker Hub
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Check out the repo
21+
uses: actions/checkout@v2
22+
- name: Set up Python 3.10
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: '3.10'
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install -U pip
29+
sudo apt-get install wget grep
30+
- name: Compare version from pip and docker and set version
31+
id: getversion
32+
run: |
33+
./scripts/auto_publish/compare-versions
34+
- name: VERSION found
35+
if: "${{ steps.getversion.outputs.version != '' }}"
36+
run: echo ${{ steps.getversion.outputs.version }}
37+
- name: Log in to Docker Hub
38+
uses: docker/login-action@v2
39+
if: "${{ steps.getversion.outputs.version != '' }}"
40+
with:
41+
username: ${{ secrets.DOCKER_USERNAME }}
42+
password: ${{ secrets.DOCKER_PASSWORD }}
43+
- name: Build and push Docker image
44+
uses: docker/build-push-action@v2
45+
if: "${{ steps.getversion.outputs.version != '' }}"
46+
with:
47+
context: .
48+
push: true
49+
build-args: |
50+
CZ_VERSION=${{ steps.getversion.outputs.version }}
51+
tags: |
52+
commitizen/commitizen:2
53+
commitizen/commitizen:latest
54+
commitizen/commitizen:${{ steps.getversion.outputs.version }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,4 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
VERSION

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ WORKDIR /app
44

55
# Add dependencies
66
RUN apk add --update -t --no-cache git curl alpine-sdk
7+
RUN ["pip", "install", "-U", "--no-cache-dir", "pip"]
78

8-
RUN ["pip", "install", "--no-cache-dir", "commitizen>=2,<3"]
9+
ARG CZ_VERSION=2.28.0
10+
RUN pip install --no-cache-dir commitizen==$CZ_VERSION
911

1012
CMD [ "cz", "version" ]

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88

99
## Docker images
1010

11-
We publish only major versions starting with `v2`.
11+
We publish major versions starting with `v2` + latest exact v2.
12+
13+
| Tag | Description |
14+
| ------------------------------ | --------------------------------------------------------------- |
15+
| `commitizen/commitizen:latest` | Latest major version, at the moment v2 |
16+
| `commitizen/commitizen:2` | Points to latest v2 |
17+
| `commitizen/commitizen:2.x` | See [tags](https://hub.docker.com/r/commitizen/commitizen/tags) |
18+
19+
This repo checks daily for the latest version and tries to publish it.
1220

13-
| Tag | Description |
14-
| ------------------------------ | -------------------------------------- |
15-
| `commitizen/commitizen:latest` | Latest major version, at the moment v2 |
16-
| `commitizen/commitizen:2` | Points to latest v2 |
1721

1822
## Usage
1923

scripts/auto_publish/compare-versions

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh -e
2+
# This script retrieves latest version from pip
3+
# and all versions in docker hub for commitizen.
4+
# If the version EXISTS then exit with error and stop pipeline
5+
6+
# requires pip
7+
pip_latest_version() {
8+
python -m pip index versions commitizen | grep commitizen | grep -o -P '[0-9]+\.[0-9]+\.[0-9]+'
9+
}
10+
11+
# requires wget, sed, gnu awk
12+
list_cz_docker_versions() {
13+
image=commitizen/commitizen
14+
wget -q "https://registry.hub.docker.com/v1/repositories/${image}/tags" -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}'
15+
}
16+
17+
PIP_LATEST=$(pip_latest_version)
18+
echo "latest pip version found '$PIP_LATEST'"
19+
20+
tags=$(list_cz_docker_versions)
21+
22+
if echo "${tags}" | grep -q "$PIP_LATEST"; then
23+
echo "Version already present, skipping other steps..."
24+
else
25+
echo "Version not found... continue"
26+
echo 'Creating file: `VERSION`'
27+
echo "$PIP_LATEST" > VERSION
28+
echo "Setting variable 'version'"
29+
echo "::set-output name=version::$PIP_LATEST"
30+
fi
31+

scripts/build

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
#!/bin/sh -e
22
set -x
3-
docker build -t registry.hub.docker.com/commitizen/commitizen:2 -t registry.hub.docker.com/commitizen/commitizen:latest .
3+
EXACT_VERSION="${EXACT_VERSION:-2}"
4+
5+
# Also tag exact question, if not provided we repeat value '2' twice, but
6+
# it won't create any problem
7+
docker build \
8+
-t registry.hub.docker.com/commitizen/commitizen:2 \
9+
-t registry.hub.docker.com/commitizen/commitizen:latest \
10+
-t "registry.hub.docker.com/commitizen/commitizen:$EXACT_VERSION" \
11+
.

scripts/run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/sh -ex
2-
docker run --rm --name commitizen commitizen:2 /bin/sh -c "$@"
2+
docker run --rm --name commitizen registry.hub.docker.com/commitizen/commitizen:2 /bin/sh -c "$@"

0 commit comments

Comments
 (0)