-
Notifications
You must be signed in to change notification settings - Fork 4
130 lines (127 loc) · 4.52 KB
/
node.js.yml
File metadata and controls
130 lines (127 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Node.js test and docker build
on:
pull_request:
branches:
- "**"
push:
branches:
- "master"
env:
REGISTRY_ACCOUNT: prerendercloud
REGISTRY_IMAGE: webserver
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- uses: actions/cache@v3
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}
- run: npm install
- run: make build
- run: make test
env:
CI: true
cleanup:
if: ${{ github.ref == 'refs/heads/master' }}
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- name: Delete workflow runs
uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
retain_days: 0
keep_minimum_runs: 30
build:
# if: ${{ github.ref == 'refs/heads/master' }}
name: build Docker container
permissions:
contents: read
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- run: make cibuild
- name: Extract version from package.json
id: version
run: |
VERSION=$(cat package.json | jq -r '.version')
echo "Extracted version: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Docker Metadata
uses: docker/metadata-action@v4.4.0
id: meta
with:
images: "${{env.REGISTRY_ACCOUNT}}/${{ env.REGISTRY_IMAGE }}"
tags: |
type=schedule
type=ref,event=pr,suffix=_{{date 'YYYY-MM-DD'}}
type=ref,event=tag
type=raw,value=${{ env.VERSION }},enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
flavor: |
latest=auto
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2.5.0
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
push: ${{ github.ref == 'refs/heads/master' }}
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}
# outputs: type=image,name=${{ env.REGISTRY_IMAGE }},name-canonical=true
# - name: Debug tags output
# run: echo "${{ steps.meta.outputs.tags }}"
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: prerendercloud/webserver
short-description: "Pre-rendering, Node.js static webserver for single-page apps using Headless-Render-API.com"
- uses: actions/setup-node@v3
with:
node-version: 20.x
registry-url: "https://registry.npmjs.org"
- name: Npm Publish
if: ${{ github.ref == 'refs/heads/master' }}
run: npm publish ./publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Job Summary of Docker images created
id: job_summary
run: |
INSPECTION=$(docker buildx imagetools inspect --raw ${{env.REGISTRY_ACCOUNT}}/${{ env.REGISTRY_IMAGE }}:latest)
echo "## Multi-Arch Docker Image" >> $GITHUB_STEP_SUMMARY
echo "$(echo $INSPECTION | jq -r '.manifests[] | select(.mediaType == "application/vnd.oci.image.manifest.v1+json" and .platform.os != "unknown" and .platform.architecture != "unknown") | "- " + .platform.os + ", " + .platform.architecture')" >> $GITHUB_STEP_SUMMARY
echo " " >> $GITHUB_STEP_SUMMARY
echo "## Docker Image Tags" >> $GITHUB_STEP_SUMMARY
echo " " >> $GITHUB_STEP_SUMMARY
while IFS= read -r tag
do
echo "- $tag" >> $GITHUB_STEP_SUMMARY
done <<< "${{ steps.meta.outputs.tags }}"