Skip to content

Commit a38c5db

Browse files
authored
Merge pull request #1 from ZestCommunity/move/pros-build-to-zest-build
✨ Create Zest Build Action
2 parents 99e5ca2 + dfd605e commit a38c5db

File tree

6 files changed

+445
-1
lines changed

6 files changed

+445
-1
lines changed

.github/workflows/build-image.yml

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
name: Build Container Image & Test
2+
3+
# This workflow uses actions that are not certified by GitHub.
4+
# They are provided by a third-party and are governed by
5+
# separate terms of service, privacy policy, and support
6+
# documentation.
7+
8+
on:
9+
push:
10+
# Publish semver tags as releases.
11+
tags: ["v*.*.*"]
12+
paths-ignore:
13+
- "README.md"
14+
branches: [ "**" ]
15+
pull_request:
16+
17+
env:
18+
# Use docker.io for Docker Hub if empty
19+
REGISTRY: ghcr.io
20+
# github.repository as <account>/<repo>
21+
IMAGE_NAME: ${{ github.repository }}
22+
concurrency:
23+
group: ${{ github.workflow }}-${{ github.ref }}
24+
cancel-in-progress: true
25+
jobs:
26+
Build_Container:
27+
name: Build Docker Container
28+
runs-on: ubuntu-latest
29+
permissions:
30+
contents: read
31+
packages: write
32+
# This is used to complete the identity challenge
33+
# with sigstore/fulcio when running outside of PRs.
34+
id-token: write
35+
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v4
39+
40+
# Set up BuildKit Docker container builder to be able to build
41+
# multi-platform images and export cache
42+
# https://github.com/docker/setup-buildx-action
43+
- name: Set up Docker Buildx
44+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
45+
46+
# Login against a Docker registry except on PR
47+
# https://github.com/docker/login-action
48+
- name: Log into registry ${{ env.REGISTRY }}s
49+
if: github.event_name != 'pull_request'
50+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
51+
with:
52+
registry: ${{ env.REGISTRY }}
53+
username: ${{ github.actor }}
54+
password: ${{ secrets.GITHUB_TOKEN }}
55+
56+
# Extract metadata (tags, labels) for Docker
57+
# https://github.com/docker/metadata-action
58+
- name: Extract Docker metadata
59+
id: meta
60+
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
61+
with:
62+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
63+
64+
# Build and push Docker image with Buildx (don't push on PR)
65+
# https://github.com/docker/build-push-action
66+
- name: Build Docker image
67+
id: buildandpush
68+
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
69+
with:
70+
context: .
71+
push: false
72+
load: true
73+
tags: ${{ steps.meta.outputs.tags }}
74+
labels: ${{ steps.meta.outputs.labels }}
75+
cache-from: type=gha
76+
cache-to: type=gha,mode=max
77+
78+
- name: Add Environment Variables
79+
id: env
80+
run: |
81+
echo "GH_PULLREQ_NUM=${{ github.event.number }}" >> $GITHUB_ENV
82+
echo "GH_EEVENT_NAME=${{ github.event_name }}" >> $GITHUB_ENV
83+
echo "GH_RREPOSITORY=${{ github.repository }}" >> $GITHUB_ENV
84+
- name: Create Tar Image For Upload
85+
id: tar
86+
run: |
87+
docker images
88+
tag=$(echo "${{ steps.meta.outputs.tags }}" | tr '\n' ' ')
89+
echo $tag
90+
docker save -o image.tar $tag
91+
92+
- name: Upload Artifact
93+
id: upload
94+
uses: actions/upload-artifact@v4
95+
with:
96+
name: image.tar
97+
path: image.tar
98+
retention-days: 1 # One Day (The Minimum)
99+
outputs:
100+
prnum: ${{ github.event.number }}
101+
url: ${{ steps.upload.outputs.artifact-url }}
102+
tag: ${{ env.IMAGE_NAME }}
103+
artifact_id: ${{ steps.upload.outputs.artifact-id }}
104+
105+
Test_Action:
106+
name: Test Docker Container/GitHub Action
107+
needs: Build_Container
108+
uses: ./.github/workflows/test.yml
109+
strategy:
110+
fail-fast: true
111+
matrix:
112+
write_job_summary: [true, false]
113+
repository: ["ZestCommunity/ZestCode"]
114+
ref: ["main"]
115+
caller_token: ["${{ github.token }}"]
116+
with:
117+
write_job_summary: ${{ matrix.write_job_summary }}
118+
repository: ${{ matrix.repository }}
119+
ref: ${{ matrix.ref }}
120+
caller_token: ${{ matrix.caller_token }}
121+
122+
Upload_Image:
123+
name: Upload Docker Image to ghcr.io Registry
124+
permissions:
125+
contents: read
126+
packages: write
127+
needs:
128+
[
129+
Build_Container,
130+
Test_Action
131+
]
132+
runs-on: ubuntu-latest
133+
if: ${{ github.event_name != 'pull_request' }}
134+
steps:
135+
- name: Checkout repository
136+
uses: actions/checkout@v4
137+
- name: Set up Docker Buildx
138+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
139+
- name: Log into registry ${{ env.REGISTRY }}
140+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
141+
with:
142+
registry: ${{ env.REGISTRY }}
143+
username: ${{ github.actor }}
144+
password: ${{ secrets.GITHUB_TOKEN }}
145+
- name: Download Image
146+
uses: actions/download-artifact@v4
147+
with:
148+
name: image.tar
149+
github-token: ${{ secrets.GITHUB_TOKEN }}
150+
- name: Load Image
151+
id: load
152+
run: |
153+
echo "tag=$(docker load -i ./image.tar | grep -oP 'Loaded image: \K.*' | tr '\n' ' ')" > $GITHUB_OUTPUT
154+
- name: Push the image
155+
if: ${{ github.event_name != 'pull_request' }}
156+
run: |
157+
for tag in $(echo "${{ steps.load.outputs.tag }}" | tr ' ' '\n'); do
158+
echo "$tag"
159+
docker push "$tag"
160+
done

.github/workflows/test.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Tests
2+
on:
3+
workflow_call:
4+
inputs:
5+
repository:
6+
description: The github repository to checkout
7+
required: true
8+
type: string
9+
ref:
10+
description: The ref of the github repository to checkout
11+
required: true
12+
type: string
13+
caller_token:
14+
description: "The token of the caller"
15+
required: true
16+
type: string
17+
write_job_summary:
18+
description: Whether to write the artifact URL to the job summary
19+
default: true
20+
type: boolean
21+
22+
jobs:
23+
test:
24+
name: "Testing Container: Write Job Summary?${{ inputs.write_job_summary }}"
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
with:
30+
repository: ${{ inputs.repository }}
31+
ref: ${{ inputs.ref }}
32+
33+
- name: Checkout
34+
uses: actions/checkout@v4
35+
with:
36+
path: ./action/
37+
- name: Download Artifact
38+
uses: actions/download-artifact@v4
39+
with:
40+
name: image.tar
41+
github-token: ${{ inputs.caller_token }}
42+
43+
- name: Load Image
44+
id: load
45+
run: |
46+
echo "tag=$(docker load -i ./image.tar | grep -oP 'Loaded image: \K.*' | head -n 1)" > $GITHUB_OUTPUT
47+
48+
- name: Edit Action.yml With Local Image
49+
run: |
50+
cat action/action.yml
51+
sed -i "s|docker://ghcr.io/.*/build-action:[^\']*|docker://${{steps.load.outputs.tag}}|g" action/action.yml
52+
sed -i "s|Dockerfile|docker://${{steps.load.outputs.tag}}|g" action/action.yml
53+
cat action/action.yml
54+
55+
- name: Test Action
56+
id: test-action
57+
uses: ./action/
58+
continue-on-error: False
59+
with:
60+
write_job_summary: ${{ inputs.write_job_summary }}

Dockerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# ------------
2+
# Build Stage: Get Dependencies
3+
# ------------
4+
FROM alpine:latest AS get-dependencies
5+
LABEL stage=builder
6+
7+
LABEL org.opencontainers.image.description="A ZestCode Build Container"
8+
LABEL org.opencontainers.image.source=https://github.com/ZestCommunity/build-action
9+
LABEL org.opencontainers.image.licenses=MIT
10+
11+
# Install Required Packages and ARM Toolchain
12+
RUN apk add --no-cache bash
13+
RUN mkdir "/arm-none-eabi-toolchain" && wget -O- "https://developer.arm.com/-/media/Files/downloads/gnu/13.3.rel1/binrel/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi.tar.xz" \
14+
| tar Jxf - -C "/arm-none-eabi-toolchain" --strip-components=1
15+
RUN <<-"EOF" bash
16+
set -e
17+
18+
toolchain="/arm-none-eabi-toolchain"
19+
mkdir -p "$toolchain"
20+
21+
rm -rf "$toolchain"/{share,include}
22+
rm -rf "$toolchain"/lib/gcc/arm-none-eabi/13.3.1/arm
23+
rm -f "$toolchain"/bin/arm-none-eabi-{gdb,gdb-py,cpp,gcc-13.3.1}
24+
25+
find "$toolchain"/arm-none-eabi/lib/thumb -mindepth 1 -maxdepth 1 ! -name 'v7-a+simd' -exec rm -rf {} +
26+
find "$toolchain"/lib/gcc/arm-none-eabi/13.3.1/thumb -mindepth 1 -maxdepth 1 ! -name 'v7-a+simd' -exec rm -rf {} +
27+
find "$toolchain"/arm-none-eabi/include/c++/13.3.1/arm-none-eabi/thumb -mindepth 1 -maxdepth 1 ! -name 'v7-a+simd' -exec rm -rf {} +
28+
29+
apk cache clean # Cleanup image
30+
EOF
31+
# ------------
32+
# Runner Stage
33+
# ------------
34+
FROM alpine:latest AS runner
35+
LABEL stage=runner
36+
LABEL org.opencontainers.image.description="A ZestCode Build Container"
37+
LABEL org.opencontainers.image.source=https://github.com/ZestCommunity/build-action
38+
LABEL org.opencontainers.image.licenses=MIT
39+
# Copy dependencies from get-dependencies stage
40+
COPY --from=get-dependencies /arm-none-eabi-toolchain /arm-none-eabi-toolchain
41+
RUN apk add --no-cache gcompat libc6-compat libstdc++ git gawk python3 pipx unzip bash && pipx install meson ninja && apk cache clean
42+
43+
# Set Environment Variables
44+
ENV PATH="/arm-none-eabi-toolchain/bin:/root/.local/bin:${PATH}"
45+
46+
ENV PYTHONUNBUFFERED=1
47+
48+
COPY build-tools/build.sh /build.sh
49+
RUN chmod +x /build.sh
50+
COPY LICENSE /LICENSE
51+
52+
ENTRYPOINT ["/build.sh"]

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
1-
# build-action
1+
# ZestCode Build Action
2+
An automated build action for ZestCode projects.
3+
4+
## Usage:
5+
### Example:
6+
```yml
7+
name: ZestCode Build Action Example
8+
9+
on:
10+
push:
11+
branches: "**"
12+
pull_request:
13+
branches: "**"
14+
15+
workflow_dispatch:
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Run Build Action
25+
id: test
26+
uses: ZestCommunity/build-action@main
27+
```
28+
### Inputs:
29+
> `write_job_summary`
30+
> - **Whether to output to GitHub's Job Summary**
31+
> - Required: False
32+
> - Default: True
33+
34+
## Notes
35+
This container was based on LemLib/pros-build.

action.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: 'Zest Build Action'
2+
description: 'Automatically build ZestCode templates'
3+
branding:
4+
color: 'blue'
5+
icon: 'box'
6+
colorized: true
7+
8+
inputs:
9+
write_job_summary:
10+
required: false
11+
default: true
12+
description: Whether to create a GitHub job summary
13+
14+
outputs:
15+
name:
16+
description: 'The recommended name for the artifact.'
17+
18+
runs:
19+
using: 'Docker'
20+
image: 'Dockerfile'

0 commit comments

Comments
 (0)