-
Notifications
You must be signed in to change notification settings - Fork 32
155 lines (129 loc) · 5.47 KB
/
artifacts.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
150
151
152
153
154
155
name: Artifacts
run-name: 📦 Generate artifacts for ${{ github.event_name == 'issue_comment' && 'PR' || (github.event_name == 'release' && '🏷' || '🌱') }} ${{github.event_name == 'issue_comment' && github.event.issue.number || github.ref_name}}
# This workflow runs whenever the "build affected docker images" checkbox is checked (for PR)
# and also whenever a commit is pushed on main or a tag is pushed
on:
push:
branches:
- main
release:
types: [published]
issue_comment:
types:
- edited
concurrency:
group: artifacts-${{ github.ref }}
cancel-in-progress: true
env:
NODE_VERSION: 18.16.1
# a list of apps to build and publish on releases
APP_NAMES: datafeeder,datahub,metadata-editor
jobs:
checks:
if: github.event_name != 'issue_comment' || github.event.issue.pull_request
name: Check whether a deploy was requested on a PR
runs-on: ubuntu-latest
outputs:
shouldRun: ${{ github.event_name != 'issue_comment' || (contains(github.event.changes.body.from, '- [ ] 📦 Build and push affected docker images') && contains(github.event.comment.body, '- [x] 📦 Build and push affected docker images')) || '' }}
ref: ${{ github.event_name == 'issue_comment' && steps.comment-branch.outputs.head_ref || '' }}
steps:
- uses: xt0rted/pull-request-comment-branch@v1
if: github.event_name == 'issue_comment'
id: comment-branch
build-archive-docker:
needs: checks
if: github.event_name != 'issue_comment' || needs.checks.outputs.shouldRun
name: Build and upload docker images and archives
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ needs.checks.outputs.ref }} # use the PR head ref if applicable; otherwise keep default behaviour
persist-credentials: false
fetch-depth: 0
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v2
with:
main-branch-name: 'main'
- name: Install dependencies
run: npm ci
- name: Build all applications and produce archives
if: github.event_name == 'release'
run: |
npx nx run-many --projects=${{ env.APP_NAMES }} --target=build
tools/make-archive.sh ${{env.APP_NAMES}}
- name: Upload archives to release
if: github.event_name == 'release'
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: dist/archives/*
file_glob: true
tag: ${{ github.ref }}
overwrite: true
- name: Build docker images for all apps
if: github.event_name == 'release'
run: npx nx run-many --projects=${{ env.APP_NAMES }} --target=docker-build
- name: Build docker images for affected apps
if: github.event_name != 'release'
# FIXME: excluding data-platform until it has a remote registry to be pushed
run: npx nx affected --target=docker-build --exclude=data-platform
- name: Build docker images for tools
working-directory: tools
run: npm run pipelines:docker-build
- name: Tag all docker images on main also as latest
if: github.event_name == 'push' # only happens when pushing on the main branch
run: docker image ls --format 'docker tag {{.Repository}}:{{.Tag}} {{.Repository}}:latest' --filter=reference='geonetwork/*' | bash -
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Push all docker images
# list all docker images, keep only the ones in the geonetwork org, and call docker push for each of them
run: |
docker image ls --format '{{.Repository}}:{{.Tag}}' --filter=reference='geonetwork/*' | \
xargs -r -L1 docker push $1
build-npm-package:
if: github.event_name != 'issue_comment'
name: Build and publish NPM package
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.checks.outputs.ref }} # use the PR head ref if applicable; otherwise keep default behaviour
persist-credentials: false
fetch-depth: 0
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
- name: Adjust package version according to branch & commit
working-directory: package
run: npm version $(../tools/print-dev-version.sh) --no-git-tag-version
- name: Build NPM package
working-directory: package
run: node generate-package.js
- name: Publish NPM package with @dev tag
if: github.event_name != 'release'
working-directory: package/dist
run: npm publish --tag dev
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish NPM package
if: github.event_name == 'release'
working-directory: package/dist
run: npm publish --tag latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}