Skip to content

Commit ecb80b5

Browse files
committed
refactor: restructure for better testing, and improved image size
1 parent 3b757c8 commit ecb80b5

File tree

18 files changed

+635
-211
lines changed

18 files changed

+635
-211
lines changed

.env

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
GITHUB_EVENT_NAME=push
2+
GITHUB_EVENT_PATH=test/fixtures/payload.json
3+
GITHUB_REPOSITORY=ahmadnassri/action-workflow-queue
4+
GITHUB_WORKSPACE=/github/workspace
5+
6+
INPUT_GITHUB-TOKEN=$GITHUB_TOKEN
7+
INPUT_DELAY=1000
8+
INPUT_TIMEOUT=1000
9+
INPUT_TOKEN=$GITHUB_TOKEN

.github/linters/.checkov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
quiet: true
66
skip-check:
77
- CKV_DOCKER_2
8+
- CKV_DOCKER_8
89
- CKV_GHA_3
910
- BC_DKR_3
1011
- CKV_GIT_1

.github/linters/.grype.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
check-for-app-update: false
2+
exclude:
3+
- '**/package-lock.json'

.github/linters/.lychee.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exclude_path = [".github"]

.github/linters/.mega-linter.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ DISABLE_LINTERS:
1111
- JSON_PRETTIER
1212
- YAML_PRETTIER
1313
- JAVASCRIPT_PRETTIER
14+
- REPOSITORY_DEVSKIM # temporarily disabled
1415

1516
LOG_LEVEL: INFO
1617
PRINT_ALPACA: false
@@ -19,7 +20,7 @@ SHOW_ELAPSED_TIME: true
1920
FLAVOR_SUGGESTIONS: false
2021
VALIDATE_ALL_CODEBASE: false
2122
IGNORE_GENERATED_FILES: true
22-
FILTER_REGEX_EXCLUDE: (dist/*|README.md|test/fixtures/*|vendor/*|/schemas/*)
23+
FILTER_REGEX_EXCLUDE: (dist/*|README.md|test/fixtures/*|vendor/*|/schemas/*|coverage/*|.nyc_output/*)
2324

2425
MARKDOWN_MARKDOWNLINT_CONFIG_FILE: .markdown-lint.yml
2526
REPOSITORY_CHECKOV_ARGUMENTS: [--skip-path, schemas]

.github/workflows/pull_request_target.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ permissions: read-all
1010

1111
jobs:
1212
main:
13-
uses: ahmadnassri/actions/.github/workflows/pull-request-target-template.yml@master
14-
secrets:
15-
github-token: ${{ secrets.GH_TOKEN }}
13+
uses: ahmadnassri/actions/.github/workflows/pull-request-target.yml@master
14+
secrets: inherit
1615
permissions:
1716
contents: write
1817
pull-requests: write

.github/workflows/push.yml

Lines changed: 7 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -2,198 +2,20 @@
22
# Note: this file originates in template-action-docker #
33
# ---------------------------------------------------- #
44

5+
name: push
6+
57
on:
68
- push
79
- workflow_dispatch
810

9-
name: push
10-
11-
concurrency:
12-
group: ${{ github.ref }}-${{ github.workflow }}
13-
1411
permissions: read-all
1512

1613
jobs:
17-
metadata:
18-
runs-on: ubuntu-latest
19-
20-
outputs:
21-
image-name: ${{ steps.image.outputs.name }}
22-
repository_is_template: ${{ steps.metadata.outputs.repository_is_template }}
23-
repository_default_branch: ${{ steps.metadata.outputs.repository_default_branch }}
24-
25-
steps:
26-
- uses: actions/[email protected]
27-
28-
- id: metadata
29-
uses: ahmadnassri/[email protected]
30-
31-
- id: image
32-
run: echo "name=$(basename "${GITHUB_REPOSITORY/docker-//}")" >> "$GITHUB_OUTPUT"
33-
34-
commit-lint:
35-
timeout-minutes: 5
36-
37-
runs-on: ubuntu-latest
38-
39-
steps:
40-
- uses: actions/[email protected]
41-
42-
- uses: ahmadnassri/[email protected]
43-
with:
44-
config: .github/linters/.commit-lint.yml
45-
46-
mega-linter:
47-
timeout-minutes: 5
48-
49-
runs-on: ubuntu-latest
50-
51-
steps:
52-
- uses: actions/[email protected]
53-
54-
- uses: oxsecurity/megalinter/flavors/[email protected]
55-
env:
56-
GITHUB_TOKEN: ${{ github.token }}
57-
MEGALINTER_CONFIG: .github/linters/.mega-linter.yml
58-
GITHUB_COMMENT_REPORTER: true
59-
GITHUB_STATUS_REPORTER: true
60-
61-
- uses: actions/upload-artifact@v3
62-
if: ${{ success() }} || ${{ failure() }}
63-
with:
64-
name: mega-linter-reports
65-
path: |
66-
megalinter-reports
67-
mega-linter.log
68-
69-
release:
70-
needs:
71-
- metadata
72-
- commit-lint
73-
- mega-linter
74-
75-
# only runs on main branch for non template repos
76-
if: |
77-
needs.metadata.outputs.repository_is_template == 'false' &&
78-
needs.metadata.outputs.repository_default_branch == github.ref_name
79-
80-
timeout-minutes: 5
81-
82-
runs-on: ubuntu-latest
83-
84-
permissions:
85-
contents: write
86-
packages: write
87-
88-
outputs:
89-
published: ${{ steps.release.outputs.published }}
90-
version: ${{ steps.release.outputs.release-version }}
91-
version-major: ${{ steps.release.outputs.release-version-major }}
92-
version-minor: ${{ steps.release.outputs.release-version-minor }}
93-
94-
steps:
95-
- uses: actions/[email protected]
96-
with:
97-
submodules: true
98-
99-
- id: release
100-
uses: ahmadnassri/[email protected]
101-
with:
102-
config: ${{ github.workspace }}/.semantic.json
103-
env:
104-
GITHUB_TOKEN: ${{ github.token }}
105-
106-
publish-docker:
107-
needs:
108-
- release
109-
- metadata
110-
111-
timeout-minutes: 5
112-
113-
if: ${{ needs.release.outputs.published == 'true' }}
114-
115-
name: publish to ghcr.io
116-
117-
runs-on: ubuntu-latest
118-
119-
permissions:
120-
contents: read
121-
packages: write
122-
123-
steps:
124-
- uses: actions/[email protected]
125-
- uses: docker/setup-qemu-action@v2
126-
- uses: docker/setup-buildx-action@v2
127-
128-
# login to registry
129-
- uses: docker/login-action@v2
130-
with:
131-
registry: ghcr.io
132-
username: ${{ github.repository_owner }}
133-
password: ${{ github.token }}
134-
135-
# publish
136-
- uses: docker/build-push-action@v4
137-
with:
138-
push: true
139-
cache-from: type=gha
140-
cache-to: type=gha,mode=max
141-
platforms: linux/amd64,linux/arm64
142-
tags: |
143-
ghcr.io/${{ github.repository_owner }}/${{ needs.metadata.outputs.image-name }}:latest
144-
ghcr.io/${{ github.repository_owner }}/${{ needs.metadata.outputs.image-name }}:${{ needs.release.outputs.version-major }}
145-
ghcr.io/${{ github.repository_owner }}/${{ needs.metadata.outputs.image-name }}:${{ needs.release.outputs.version }}
146-
labels: |
147-
org.opencontainers.image.title=${{ needs.metadata.outputs.image-name }}
148-
org.opencontainers.image.url=${{ github.event.repository.html_url }}
149-
org.opencontainers.image.version=${{ needs.release.outputs.version }}
150-
org.opencontainers.image.source=${{ github.event.repository.html_url }}
151-
org.opencontainers.image.revision=${{ github.sha }}
152-
153-
alias:
154-
needs: release
155-
156-
if: ${{ needs.release.outputs.published == 'true' }}
157-
158-
runs-on: ubuntu-latest
159-
14+
main:
15+
uses: ahmadnassri/actions/.github/workflows/push-action-docker.yml@master
16+
secrets: inherit
16017
permissions:
16118
contents: write
19+
statuses: write
16220
packages: write
163-
164-
strategy:
165-
matrix:
166-
release: [ "v${{ needs.release.outputs.version }}" ]
167-
alias:
168-
- "v${{ needs.release.outputs.version-major }}"
169-
- "v${{ needs.release.outputs.version-major }}.${{ needs.release.outputs.version-minor }}"
170-
171-
steps:
172-
- uses: actions/github-script@v6
173-
with:
174-
script: |
175-
const { data: { object: { sha } } } = await github.rest.git.getRef({ ...context.repo, ref: 'tags/${{ matrix.release }}' })
176-
await github.rest.git.deleteRef({ ...context.repo, ref: 'tags/${{ matrix.alias }}' }).catch(() => {})
177-
await github.rest.git.createRef({ ...context.repo, ref: 'refs/tags/${{ matrix.alias }}', sha })
178-
179-
template-sync:
180-
timeout-minutes: 5
181-
182-
needs:
183-
- metadata
184-
- commit-lint
185-
- mega-linter
186-
187-
# only runs on main branch for template repos
188-
if: |
189-
needs.metadata.outputs.repository_is_template == 'true' &&
190-
needs.metadata.outputs.repository_default_branch == github.ref_name
191-
192-
runs-on: ubuntu-latest
193-
194-
steps:
195-
- uses: actions/[email protected]
196-
197-
- uses: ahmadnassri/[email protected]
198-
with:
199-
github-token: ${{ secrets.GH_TOKEN }}
21+
pull-requests: write

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
# ---------------------------------------------------- #
22
# Note: this file originates in template-action-docker #
33
# ---------------------------------------------------- #
4+
5+
*.log
6+
.nyc_output
7+
coverage
8+
node_modules

Dockerfile

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,48 @@
1-
FROM node:slim
1+
# --- base stage --- #
22

3-
LABEL com.github.actions.name="GitHub Action: Workflow Run Wait" \
4-
com.github.actions.description="wait for all `workflow_run` required workflows to be successful" \
5-
com.github.actions.icon="clock" \
6-
com.github.actions.color="blue" \
7-
maintainer="Ahmad Nassri <[email protected]>"
3+
FROM alpine:3.18 AS base
4+
5+
# hadolint ignore=DL3018
6+
RUN apk add --no-cache --update \
7+
nodejs=18.17.0-r0 \
8+
git=2.40.1-r0 \
9+
openssh=9.3_p2-r0 \
10+
ca-certificates=20230506-r0 \
11+
ruby-bundler=2.4.15-r0 \
12+
bash=5.2.15-r5
813

9-
RUN mkdir /action
1014
WORKDIR /action
1115

12-
COPY action ./
16+
# --- build stage --- #
17+
18+
FROM base AS build
19+
20+
# hadolint ignore=DL3018
21+
RUN apk add --no-cache npm=9.6.6-r0
22+
23+
# slience npm
24+
# hadolint ignore=DL3059
25+
RUN npm config set update-notifier=false audit=false fund=false
26+
27+
# install packages
28+
COPY package* ./
29+
RUN npm ci --omit=dev --no-fund --no-audit
30+
31+
# --- app stage --- #
32+
33+
FROM base AS app
34+
35+
# copy from build image
36+
COPY --from=build /action/node_modules ./node_modules
37+
38+
# copy files
39+
COPY package.json src ./
40+
41+
WORKDIR /github/workspace/
42+
43+
# hadolint ignore=DL3002
44+
USER root
1345

14-
RUN npm ci --only=prod
46+
HEALTHCHECK NONE
1547

1648
ENTRYPOINT ["node", "/action/index.js"]

Makefile

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# Note: this file originates in template-action-docker #
55
# ---------------------------------------------------- #
66

7-
SHELL := /bin/bash
8-
97
pull: ## pull latest containers
108
@docker compose pull
119

@@ -15,15 +13,33 @@ lint: clean ## run mega-linter
1513
readme: clean ## run readme action
1614
@docker compose run --rm readme
1715

18-
start: ## start the project in foreground
19-
@docker compose run $(shell env | grep DOCKER | sed -E 's/DOCKER_(.*?)=(.*)/-e \1="\2"/gm;t;d') app
20-
2116
build: clean ## start the project in background
2217
@docker compose build --no-cache app
2318

2419
shell: ## start the container shell
2520
@docker compose run --rm --entrypoint /bin/sh app
2621

22+
install: ## install all dependencies
23+
@docker compose run --rm app install
24+
25+
start: ## start the project in foreground
26+
@docker compose run --rm app
27+
28+
test: ## run all npm tests
29+
@docker compose run --rm app-test
30+
31+
build-action: clean ## start the project in background
32+
@docker compose build --no-cache action
33+
34+
shell-action: ## start the container shell
35+
@docker compose run --rm --entrypoint /bin/sh action
36+
37+
start-action: ## start the project in foreground
38+
@docker compose run --rm action
39+
40+
test-action: ## start the project in foreground
41+
@docker compose run --rm action-test
42+
2743
stop: ## stop all running containers
2844
@docker compose down --remove-orphans --rmi local
2945

0 commit comments

Comments
 (0)