-
Notifications
You must be signed in to change notification settings - Fork 29
139 lines (124 loc) · 4.79 KB
/
web-workflow.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
name: Web
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
IS_BUILD_SERVER: true # Needed by spa testing
# SENTRY_LOG_LEVEL: "debug"
on:
push:
tags:
- 'v*.*.*'
branches:
- main
paths:
- 'src/NuGetTrends.Web/**'
- 'src/NuGetTrends.Data/**'
- 'src/Directory.Build.props'
- '**/web-workflow.yml'
pull_request:
paths:
- 'src/NuGetTrends.Web/**'
- 'src/NuGetTrends.Data/**'
- 'src/Directory.Build.props'
- '**/web-workflow.yml'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_NOLOGO: 1
DOTNET_MULTILEVEL_LOOKUP: 1
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Prepare Docker
id: docker-prep
run: |
DOCKER_IMAGE=nugettrends/nugettrends.web
VERSION=noop
ENVIRONMENT=test
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
ENVIRONMENT=prod
elif [[ $GITHUB_REF == refs/heads/main ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
MINOR=${VERSION%.*}
MAJOR=${MINOR%.*}
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest"
elif [ "${{ github.event_name }}" = "push" ]; then
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
fi
echo ::set-output name=environment::${ENVIRONMENT}
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Docker values debug
run: |
echo ${{ steps.docker-prep.outputs.environment }}
echo ${{ steps.docker-prep.outputs.version }}
echo ${{ steps.docker-prep.outputs.tags }}
echo ${{ steps.docker-prep.outputs.created }}
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
cache-dependency-path: src/NuGetTrends.Web/Portal/package-lock.json
- name: Install Angular CLI
run: npm install -g @angular/[email protected]
- name: Test/print Angular CLI version
run: ng version
- name: 'Install SPA packages'
run: npm install
working-directory: src/NuGetTrends.Web/Portal
# TODO: Enable again when we migrate to ESLint
# - name: 'SPA lint'
# run: yarn run lint
# working-directory: src/NuGetTrends.Web/Portal
- name: 'SPA test'
run: npm run test-cc
working-directory: src/NuGetTrends.Web/Portal
- name: 'SPA prod build'
# Angular runs a prod build by default
run: npm run build
working-directory: src/NuGetTrends.Web/Portal
- name: Replace SPA path on coverage file (Hack codecov) # https://community.codecov.io/t/looking-for-assistance-with-path-fixing/1669/9
run: sed -i 's/SF:/SF:src\/NuGetTrends.Web\/Portal\//g' src/NuGetTrends.Web/Portal/coverage/lcov.info
- name: Upload SPA coverage report to Codecov
uses: codecov/codecov-action@v3
- name: Web Build
run: dotnet build -c Release
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
working-directory: src/NuGetTrends.Web/
- name: Web Publish
run: dotnet publish -c Release -o publish --no-build
working-directory: src/NuGetTrends.Web/
- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
id: docker_build
with:
context: ./src/NuGetTrends.Web
file: ./src/NuGetTrends.Web/Dockerfile
build-args: |
ENVIRONMENT=${{ steps.docker-prep.outputs.environment }}
VERSION=${{ steps.docker-prep.outputs.version }}
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker-prep.outputs.tags }}
labels: |
org.opencontainers.image.created=${{ steps.docker-prep.outputs.created }}
org.opencontainers.image.source=${{ github.repositoryUrl }}
org.opencontainers.image.version=${{ steps.docker-prep.outputs.version }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.name }}