Skip to content

Commit

Permalink
test: add GitHub Action workflow to build and test container image
Browse files Browse the repository at this point in the history
  • Loading branch information
ahwayakchih committed Jan 20, 2025
1 parent 5b1a5ab commit e77c590
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 1 deletion.
103 changes: 103 additions & 0 deletions .github/workflows/puppeteer-container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: puppeteer-container

on:
push:
branches: [ master ]
tags: [ v* ]

env:
REGISTRY: ghcr.io
IMAGE_NAME: puppeteer
CONTAINERFILE: puppeteer.containerfile

jobs:
prepare:
runs-on: ubuntu-latest
outputs:
name: ${{ steps.step1.outputs.name }}
version: ${{ steps.step1.outputs.version }}
image_exists: ${{ steps.step1.outputs.image_exists }}
steps:
- id: step1
run: |
IMAGE_ID=${{ env.REGISTRY }}/${{ github.repository_owner }}/$IMAGE_NAME
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# we need to get files, so we can prepare version based on containerfile hash
git clone ${{ github.SERVER_URL }}/${{ github.REPOSITORY }}
cd $(basename ${{ github.REPOSITORY }})
git switch "${{ github.REF_NAME }}"
# use hash of the container file to version images
VERSION=$(sha256sum ${{ env.CONTAINERFILE }} | cut -d ' ' -f 1)
IMAGE_EXISTS=$(docker manifest inspect "$IMAGE_ID:$VERSION" &>/dev/null && echo yes || echo no)
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
echo IMAGE_EXISTS=$IMAGE_EXISTS
echo "name=$IMAGE_ID" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "image_exists=$IMAGE_EXISTS" >> "$GITHUB_OUTPUT"
build:
runs-on: ubuntu-latest
needs: prepare
if: ${{ needs.prepare.outputs.image_exists == 'no' }}

permissions:
contents: read
packages: write
attestations: write
id-token: write

steps:
- uses: actions/checkout@v4

- run: podman --version

- name: Build container image
run: |
podman build -t "$IMAGE_NAME" -f "$CONTAINERFILE"\
--label "org.opencontainers.image.source=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \
--label "org.opencontainers.image.description=Puppeteer container" \
--label "org.opencontainers.image.licenses=MIT" \
--build-arg=UID=$(id -u) \
--build-arg=GID=$(id -g)
- name: List images
run: podman images

- name: Test run
run: podman run --rm --init --userns=keep-id -v $(pwd):/app -w /app $IMAGE_NAME ls -la

- name: Login in to registry
if: success()
run: echo "${{ secrets.GITHUB_TOKEN }}" | podman login ${{ env.REGISTRY }} -u ${{ github.actor }} --password-stdin

- name: Push container image
if: success()
run: |
podman push $IMAGE_NAME ${{ needs.prepare.outputs.name }}:${{ needs.prepare.outputs.version }}
# Export as "latest" when on main branch
[ "${{ github.REF_NAME }}" != "master" ] || podman push $IMAGE_NAME ${{ needs.prepare.outputs.name }}:latest
# Export as version number when at tagged commit
[[ "${{ github.ref }}" != "refs/tags/"* ]] || podman push $IMAGE_NAME ${{ needs.prepare.outputs.name }}:$(basename "${{ github.ref }}" | sed -e 's/^v//')
test:
runs-on: ubuntu-latest
needs: [ prepare, build ]
if: always() && !failure() && !cancelled()

container:
image: ${{ needs.prepare.outputs.name }}:${{ needs.prepare.outputs.version }}
options: --user node2 -e CHROME_DISABLE_SANDBOX=1 -e DEBUG=true

steps:
- name: Checkout
run: git clone ${{ github.SERVER_URL }}/${{ github.REPOSITORY }}

- run: env

- name: Install and Run
run: |
cd $(basename ${{ github.REPOSITORY }})
git switch "${{ github.REF_NAME }}"
npm install && npm run puppeteer
xvfb-run npm test
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Changelog
- Improved error output when private key cannot be loaded
- Updated example ZIP and CRX binaries because tests failed on differences in compression ratio (of exactly the same sources!)
- Dropped use of runners on AppVeyor (Windows) and Cirrus CI (Linux & MacOS)
- Added puppeteer.containerfile and usage info
- Added puppeteer.containerfile and modified info about testing

**v1.1.3** - 2020-11-06

Expand Down
1 change: 1 addition & 0 deletions puppeteer.containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Or:
# podman run --rm --init -v $(pwd):/app -w /app --user node2 --userns=keep-id:uid=1001,gid=1001 -it puppeteer xvfb-run npm test
#
# Last change: 2025-01-20 Alpine 3.21.2 Node 23.6.0
FROM docker.io/node:alpine

# If set to values different than the ones used by Node.js (1000:1000 at the time of writing),
Expand Down

0 comments on commit e77c590

Please sign in to comment.