Skip to content

Commit b3f3fdb

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

File tree

8 files changed

+419
-614
lines changed

8 files changed

+419
-614
lines changed

.github/workflows/ci.yaml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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: Build and push
37+
uses: docker/build-push-action@v4
38+
with:
39+
push: true
40+
tags: ghcr.io/usa-reddragon/kiri:${{ steps.tag_name.outputs.tag }}
41+
cache-from: type=gha
42+
cache-to: type=gha,mode=max
43+
- name: Extract full version from tag, ie refs/tags/v1.2.3 -> v1.2.3
44+
id: full_version
45+
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'release'
46+
run: |
47+
echo "full_version=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
48+
- name: Extract minor version from tag, ie v1.2.3 -> v1.2
49+
id: minor_version
50+
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'release'
51+
run: |
52+
echo "minor_version=${GITHUB_REF#refs/*/}" | sed 's/\.[^.]*$//' >> $GITHUB_OUTPUT
53+
- name: Extract major version from tag, ie v1.2.3 -> v1
54+
id: major_version
55+
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'release'
56+
run: |
57+
echo "major_version=${GITHUB_REF#refs/*/}" | sed 's/\.[^.]*$//' | sed 's/\.[^.]*$//' >> $GITHUB_OUTPUT
58+
- name: Build and push minor version
59+
uses: docker/build-push-action@v4
60+
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'release'
61+
with:
62+
push: true
63+
tags: ghcr.io/usa-reddragon/kiri:${{ steps.minor_version.outputs.minor_version }}
64+
cache-from: type=gha
65+
cache-to: type=gha,mode=max
66+
- name: Build and push major version
67+
uses: docker/build-push-action@v4
68+
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'release'
69+
with:
70+
push: true
71+
tags: ghcr.io/usa-reddragon/kiri:${{ steps.major_version.outputs.major_version }}
72+
cache-from: type=gha
73+
cache-to: type=gha,mode=max
74+
# Make sure that the line in `action.yml` similar to docker://ghcr.io/usa-reddragon/kiri:v1.2.3 is updated
75+
- name: Update action.yml
76+
if: startsWith(github.ref, 'refs/tags/v')
77+
run: |
78+
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
79+
- name: Setup git config
80+
if: startsWith(github.ref, 'refs/tags/v')
81+
run: |
82+
git config --local user.email "${GITHUB_ACTOR}@users.noreply.github.com"
83+
git config --local user.name "${GITHUB_ACTOR}"
84+
- name: Fail if action.yml was not updated
85+
if: startsWith(github.ref, 'refs/tags/v')
86+
run: |
87+
if [ -n "$(git status --porcelain action.yml)" ]; then
88+
echo "Failing because action.yml was not updated with the new version"
89+
git add action.yml
90+
git diff --staged action.yml
91+
exit 1
92+
fi
93+
- name: Create Release
94+
id: create_release
95+
if: startsWith(github.ref, 'refs/tags/v')
96+
uses: actions/create-release@v1
97+
env:
98+
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
99+
with:
100+
tag_name: ${{ steps.full_version.outputs.full_version }}
101+
release_name: Release ${{ steps.full_version.outputs.full_version }}
102+
draft: false
103+
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)