Skip to content

Commit f171572

Browse files
committed
Convert to a GitHub action
1 parent 02ad197 commit f171572

File tree

8 files changed

+479
-611
lines changed

8 files changed

+479
-611
lines changed

.github/workflows/ci.yaml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
paths:
8+
- 'Dockerfile'
9+
- 'entrypoint.sh'
10+
- 'config/**'
11+
- '.github/workflows/ci.yaml'
12+
tags:
13+
- 'v[0-9]+.[0-9]+.[0-9]+'
14+
15+
jobs:
16+
docker:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v2
22+
- name: Log in to GHCR
23+
uses: docker/login-action@v2
24+
with:
25+
registry: ghcr.io
26+
username: ${{ github.actor }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
- name: Set tag name
29+
id: tag_name
30+
run: |
31+
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
32+
echo "tag=latest" >> $GITHUB_OUTPUT
33+
else
34+
echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
35+
fi
36+
- name: Extract full version from tag, ie refs/tags/v1.2.3 -> v1.2.3
37+
id: full_version
38+
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'release'
39+
run: |
40+
echo "full_version=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
41+
# Make sure that the line in `action.yml` similar to docker://ghcr.io/usa-reddragon/kiri:v1.2.3 is updated
42+
- name: Update action.yml
43+
if: startsWith(github.ref, 'refs/tags/v')
44+
run: |
45+
sed -i "s/docker:\/\/ghcr.io\/usa-reddragon\/kiri:v[0-9]\+\.[0-9]\+\.[0-9]\+/docker:\/\/ghcr.io\/usa-reddragon\/kiri:${{ steps.full_version.outputs.full_version }}/g" action.yml
46+
- name: Setup git config
47+
if: startsWith(github.ref, 'refs/tags/v')
48+
run: |
49+
git config --local user.email "${GITHUB_ACTOR}@users.noreply.github.com"
50+
git config --local user.name "${GITHUB_ACTOR}"
51+
- name: Fail if action.yml was not updated
52+
if: startsWith(github.ref, 'refs/tags/v')
53+
run: |
54+
if [ -n "$(git status --porcelain action.yml)" ]; then
55+
echo "Failing because action.yml was not updated with the new version"
56+
git add action.yml
57+
git diff --staged action.yml
58+
exit 1
59+
fi
60+
- name: Build and push
61+
uses: docker/build-push-action@v4
62+
with:
63+
push: true
64+
tags: ghcr.io/usa-reddragon/kiri:${{ steps.tag_name.outputs.tag }}
65+
cache-from: type=gha
66+
cache-to: type=gha,mode=max
67+
- name: Extract minor version from tag, ie v1.2.3 -> v1.2
68+
id: minor_version
69+
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'release'
70+
run: |
71+
echo "minor_version=${GITHUB_REF#refs/*/}" | sed 's/\.[^.]*$//' >> $GITHUB_OUTPUT
72+
- name: Extract major version from tag, ie v1.2.3 -> v1
73+
id: major_version
74+
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'release'
75+
run: |
76+
echo "major_version=${GITHUB_REF#refs/*/}" | sed 's/\.[^.]*$//' | sed 's/\.[^.]*$//' >> $GITHUB_OUTPUT
77+
- name: Build and push minor version
78+
uses: docker/build-push-action@v4
79+
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'release'
80+
with:
81+
push: true
82+
tags: ghcr.io/usa-reddragon/kiri:${{ steps.minor_version.outputs.minor_version }}
83+
cache-from: type=gha
84+
cache-to: type=gha,mode=max
85+
- name: Build and push major version
86+
uses: docker/build-push-action@v4
87+
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'release'
88+
with:
89+
push: true
90+
tags: ghcr.io/usa-reddragon/kiri:${{ steps.major_version.outputs.major_version }}
91+
cache-from: type=gha
92+
cache-to: type=gha,mode=max
93+
- name: Re-tag minor and major version
94+
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'release'
95+
run: |
96+
git tag -d ${{ steps.minor_version.outputs.minor_version }} || true
97+
git tag -d ${{ steps.major_version.outputs.major_version }} || true
98+
git push origin :refs/tags/${{ steps.minor_version.outputs.minor_version }} || true
99+
git push origin :refs/tags/${{ steps.major_version.outputs.major_version }} || true
100+
git tag ${{ steps.minor_version.outputs.minor_version }} ${{ steps.full_version.outputs.full_version }}
101+
git tag ${{ steps.major_version.outputs.major_version }} ${{ steps.full_version.outputs.full_version }}
102+
git push origin ${{ steps.minor_version.outputs.minor_version }}
103+
git push origin ${{ steps.major_version.outputs.major_version }}
104+
- name: Create Release
105+
id: create_release
106+
if: startsWith(github.ref, 'refs/tags/v')
107+
uses: actions/create-release@v1
108+
env:
109+
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
110+
with:
111+
tag_name: ${{ steps.full_version.outputs.full_version }}
112+
release_name: Release ${{ steps.full_version.outputs.full_version }}
113+
draft: false
114+
prerelease: false

Dockerfile

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
# Latest stable version of Ubuntu, of course
33
FROM ubuntu:22.04
44

5-
LABEL org.opencontainers.image.authors "Leandro Heck <leoheck@gmail.com>"
5+
LABEL org.opencontainers.image.authors "Leandro Heck <leoheck@gmail.com>, Jacob McSwain <kiri-github-action@mcswain.dev>"
66
LABEL org.opencontainers.image.description "Kicad 7 and KiRI"
7-
LABEL org.opencontainers.image.url "https://hub.docker.com/r/leoheck/kiri/main"
8-
LABEL org.opencontainers.image.documentation "https://github.com/leoheck/kiri-docker"
7+
LABEL org.opencontainers.image.url "https://github.com/USA-RedDragon/kiri-github-action/pkgs/container/kiri"
8+
LABEL org.opencontainers.image.documentation "https://github.com/USA-RedDragon/kiri-github-action"
9+
LABEL org.opencontainers.image.source "https://github.com/USA-RedDragon/kiri-github-action"
910

1011
ARG DEBIAN_FRONTEND noninteractive
1112
ARG DEBCONF_NOWARNINGS="yes"
12-
ARG TERM 'dumb'
13+
ENV TERM 'dumb'
1314

1415
RUN apt-get update
1516
RUN apt-get install -y \
1617
sudo \
1718
git \
18-
zsh \
1919
curl \
2020
coreutils \
2121
software-properties-common \
@@ -49,18 +49,19 @@ RUN apt-get install --no-install-recommends -y kicad && \
4949
rm -rf /var/tmp/*
5050

5151
# Create user
52-
RUN useradd -rm -d "/home/kiri" -s "/usr/bin/zsh" -g root -G sudo -u 1000 kiri -p kiri
52+
RUN useradd -rm -d "/home/github" -s "$(which bash)" -G sudo -u 1001 -U github
5353

5454
# Run sudo without password
55-
RUN echo "kiri ALL=(ALL) NOPASSWD:ALL" | tee sudo -a "/etc/sudoers"
55+
RUN echo "github ALL=(ALL) NOPASSWD:ALL" | tee sudo -a "/etc/sudoers"
5656

5757
# Change current user
58-
USER kiri
59-
WORKDIR "/home/kiri"
60-
ENV USER kiri
58+
USER github
59+
WORKDIR "/home/github"
60+
ENV USER github
61+
ENV HOME /home/github
6162
ENV DISPLAY :0
6263

63-
ENV PATH "${PATH}:/home/kiri/.local/bin"
64+
ENV PATH "${PATH}:/home/github/.local/bin"
6465

6566
# Python dependencies
6667
RUN yes | pip3 install \
@@ -89,38 +90,19 @@ RUN yes | opam init --disable-sandboxing && \
8990
rm -rf ~/.opam/download-cache ;\
9091
rm -rf ~/.opam/repo/*
9192

92-
# Oh-my-zsh, please
93-
RUN zsh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" || true
94-
9593
# Install kiri, kidiff and plotgitsch
96-
ADD https://api.github.com/repos/leoheck/kiri/git/refs/heads/main kiri_version.json
97-
ENV KIRI_HOME "/home/kiri/.local/share/"
98-
RUN git clone --recurse-submodules -j8 https://github.com/leoheck/kiri.git "${KIRI_HOME}/kiri"
99-
RUN cd "${KIRI_HOME}/kiri/submodules/plotkicadsch" && \
94+
ADD https://api.github.com/repos/USA-RedDragon/kiri/git/refs/heads/main kiri_version.json
95+
ENV KIRI_HOME "/home/github/.local/share/kiri"
96+
RUN git clone --recurse-submodules -j8 https://github.com/USA-RedDragon/kiri.git "${KIRI_HOME}"
97+
RUN cd "${KIRI_HOME}/submodules/plotkicadsch" && \
10098
opam pin add -y kicadsch . && \
10199
opam pin add -y plotkicadsch . && \
102100
opam install -y plotkicadsch; \
103101
opam clean -a -c -s --logs -r ;\
104102
rm -rf ~/.opam/download-cache ;\
105103
rm -rf ~/.opam/repo/*
106104

107-
# Opam configuration
108-
RUN echo | tee -a "${HOME}/.zshrc"
109-
RUN echo '# OPAM configuration' | tee -a "${HOME}/.zshrc"
110-
RUN echo "test -r /home/kiri/.opam/opam-init/init.sh && . /home/kiri/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true" | tee -a "${HOME}/.zshrc"
111-
112-
# KiRI environment
113-
RUN echo | tee -a "${HOME}/.zshrc"
114-
RUN echo '# KIRI Environment' | tee -a "${HOME}/.zshrc"
115-
RUN echo 'export KIRI_HOME=${HOME}/.local/share/kiri' | tee -a "${HOME}/.zshrc"
116-
RUN echo 'export PATH=${KIRI_HOME}/submodules/KiCad-Diff/bin:${PATH}' | tee -a "${HOME}/.zshrc"
117-
RUN echo 'export PATH=${KIRI_HOME}/bin:${PATH}' | tee -a "${HOME}/.zshrc"
118-
119-
# Custom commands
120-
RUN echo | tee -a "${HOME}/.zshrc"
121-
RUN echo '# Custom Commands' | tee -a "${HOME}/.zshrc"
122-
RUN echo 'function ip() { awk "/32 host/ { print f } {f=\$2}" /proc/net/fib_trie | sort | uniq | grep -v 127.0.0.1 | head -n1 }' | tee -a "${HOME}/.zshrc"
123-
RUN echo 'alias kiri="kiri -i \$(ip)"' | tee -a "${HOME}/.zshrc"
105+
ENV PATH "${KIRI_HOME}/bin:${KIRI_HOME}/submodules/KiCad-Diff/bin:${PATH}"
124106

125107
# Clean unnecessary stuff
126108
RUN sudo apt-get purge -y \
@@ -138,5 +120,24 @@ RUN sudo rm -rf \
138120
/usr/share/man/*
139121

140122
# Initialize Kicad config files to skip default popups of setup
141-
COPY config "/home/kiri/.config"
142-
RUN sudo chown -R kiri "/home/kiri/.config"
123+
COPY config "/home/github/.config"
124+
RUN sudo chown -R github:github "/home/github/.config"
125+
126+
COPY entrypoint.sh /entrypoint.sh
127+
RUN sudo chmod a+rx /entrypoint.sh
128+
129+
# GitHub Actions environment variables
130+
ENV KIRI_PROJECT_FILE ""
131+
ENV KIRI_OUTPUT_DIR ""
132+
ENV KIRI_REMOVE ""
133+
ENV KIRI_ARCHIVE ""
134+
ENV KIRI_PCB_PAGE_FRAME ""
135+
ENV KIRI_FORCE_LAYOUT_VIEW ""
136+
ENV KIRI_SKIP_KICAD6_SCHEMATICS ""
137+
ENV KIRI_SKIP_CACHE ""
138+
ENV KIRI_OLDER ""
139+
ENV KIRI_NEWER ""
140+
ENV KIRI_LAST ""
141+
ENV KIRI_ALL ""
142+
143+
ENTRYPOINT ["/entrypoint.sh"]

0 commit comments

Comments
 (0)