-
-
Notifications
You must be signed in to change notification settings - Fork 1
149 lines (148 loc) · 5.38 KB
/
publish.yml
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Publish
#
# Publish container image to the GitHub Container Registry when a new tag is created or on workflow
# dispatch.
#
# References:
#
# - https://dbdocs.io/docs/ci-integration
# - https://docs.github.com/actions/learn-github-actions/contexts
# - https://docs.github.com/actions/learn-github-actions/expressions
# - https://docs.github.com/actions/using-workflows/events-that-trigger-workflows#release
# - https://docs.github.com/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
# - https://docs.github.com/actions/using-workflows/reusing-workflows#calling-a-reusable-workflow
# - https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions
# - https://docs.github.com/webhooks-and-events/webhooks/webhook-events-and-payloads#release
# - https://docs.github.com/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_dispatch
# - https://github.com/actions/checkout
# - https://github.com/actions/setup-node
# - https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#yarn2-configuration
# - https://github.com/actions/upload-artifact
# - https://github.com/docker/build-push-action
# - https://github.com/docker/login-action
# - https://github.com/docker/metadata-action
# - https://github.com/hmarr/debug-action
# - https://github.com/opencontainers/image-spec/blob/main/annotations.md
---
name: publish
on:
push:
tags:
- '*'
workflow_dispatch:
inputs:
tag:
description: release tag
required: true
env:
REF: ${{ format('refs/tags/{0}', inputs.tag || github.ref_name) }}
TAG: ${{ inputs.tag || github.ref_name }}
concurrency:
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.ref }}
jobs:
preflight:
runs-on: ubuntu-latest
outputs:
container-image-url: ${{ steps.container-image-url.outputs.result }}
steps:
- id: debug
name: Print environment variables and event payload
uses: hmarr/[email protected]
- id: container-image-url
name: Get container image URL
run: |
echo "result=${{ format('{0}/{1}/pkgs/container/{2}', github.server_url, github.repository, github.event.repository.name) }}" >>$GITHUB_OUTPUT
ghcr:
needs: preflight
permissions:
packages: write
runs-on: ubuntu-latest
environment:
name: container
url: ${{ needs.preflight.outputs.container-image-url }}
steps:
- id: checkout
name: Checkout ${{ env.TAG }}
uses: actions/[email protected]
with:
ref: ${{ env.REF }}
- id: login
name: Login to GitHub Container Registry
uses: docker/[email protected]
with:
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
username: ${{ github.repository_owner }}
- id: version
name: Get container image version
run: echo "result=$(jq .version package.json -r)" >>$GITHUB_OUTPUT
- id: licenses
name: Get container image licenses
run: echo "result=$(jq .license package.json -r)" >>$GITHUB_OUTPUT
- id: metadata
name: Extract container image metadata
uses: docker/[email protected]
env:
SOURCE: ${{ format('{0}/{1}', github.server_url, github.repository) }}
with:
flavor: latest=true
images: ghcr.io/${{ github.repository }}
labels: |
org.opencontainers.image.authors=@unicornware
org.opencontainers.image.licenses=${{ steps.licenses.outputs.result }}
org.opencontainers.image.title=${{ format('@{0}', github.repository) }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.source=${{ env.SOURCE }}
org.opencontainers.image.url=${{ needs.preflight.outputs.container-image-url }}
org.opencontainers.image.vendor=${{ github.repository_owner }}
org.opencontainers.image.version=${{ steps.version.outputs.result }}
tags: |
type=ref,event=tag
type=semver,pattern={{raw}},value=${{ steps.version.outputs.result }}
type=sha,prefix=
type=sha,prefix=,format=long
- id: build-push
name: Build and push container image
uses: docker/[email protected]
with:
context: .
file: ./Dockerfile
labels: ${{ steps.metadata.outputs.labels }}
push: true
secrets: |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
tags: ${{ steps.metadata.outputs.tags }}
target: production
dbdocs:
needs: ghcr
runs-on: ubuntu-latest
environment:
name: dbdocs
url: https://dbdocs.io/unicornware/${{ github.event.repository.name }}
steps:
- id: checkout
name: Checkout ${{ env.TAG }}
uses: actions/[email protected]
with:
ref: ${{ env.REF }}
- id: install
name: Install dbdocs
run: npm install --global dbdocs
- id: build
name: Update dbdocs project
run: dbdocs build $DB_ARCHITECTURE_FILE
env:
DBDOCS_TOKEN: ${{ secrets.DBDOCS_TOKEN }}
- id: archive
name: Archive database schema file
uses: actions/[email protected]
with:
name: DATABASE.dbml
path: ./DATABASE.dbml
vm:
needs:
- dbdocs
- ghcr
uses: ./.github/workflows/vm-restart.yml
secrets: inherit