-
Notifications
You must be signed in to change notification settings - Fork 0
159 lines (135 loc) · 5.33 KB
/
build-and-test.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
156
157
158
159
name: Build and test
on:
schedule:
# Daily 5am australian/brisbane time (7pm UTC)
- cron: '0 19 * * *'
pull_request:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
name: Build and test
permissions:
contents: read
actions: write
checks: write
statuses: write
steps:
- uses: actions/checkout@v3
- name: Setup node 20
uses: actions/setup-node@v3
with:
node-version: 20.x
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Lint
run: npm run lint
- name: Test
run: npm run ci:test
- name: Create test report
uses: phoenix-actions/test-reporting@v12
if: success() || failure() # run this step even if previous step failed
with:
name: Tests # Name of the check run which will be created
path: test-results/jest-*.xml # Path to test results
reporter: jest-junit # Format of test results
output-to: step-summary
- name: Compare the expected and actual dist/ directories
run: |
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff
exit 1
fi
id: diff
# If index.js was different than expected, upload the expected version as an artifact
- name: Upload dist as artifact if differences detected
uses: actions/upload-artifact@v3
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with:
name: dist
path: dist/
test:
runs-on: ubuntu-latest
name: Integration test
needs: build
env:
SA_PASSWORD: ${{ secrets.INTEGRATION_TEST_SQL_SA_PASSWORD }}
ADMIN_API_KEY: ${{ secrets.INTEGRATION_TEST_OCTOPUS_ADMIN_API_KEY }}
SERVER_URL: "http://localhost:8080"
services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2019-CU27-ubuntu-20.04
env:
ACCEPT_EULA: Y
SA_PASSWORD: ${{ env.SA_PASSWORD }}
MSSQL_PID: Developer
options: >-
--health-cmd "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P \"$SA_PASSWORD\" -Q \"SELECT 1\" || exit 1"
--health-interval 10s
--health-timeout 3s
--health-retries 10
--health-start-period 10s
octopusserver:
image: octopusdeploy/octopusdeploy
env:
ACCEPT_EULA: Y
DB_CONNECTION_STRING: "Server=sqlserver;Database=OctopusDeploy;User Id=sa;Password=${{ env.SA_PASSWORD }};"
ADMIN_USERNAME: admin
ADMIN_API_KEY: ${{ env.ADMIN_API_KEY }}
ENABLE_USAGE: N
OCTOPUS_SERVER_BASE64_LICENSE: ${{ secrets.INTEGRATION_TEST_OCTOPUS_BASE64_LICENSE }}
ports:
- 8080:8080
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v3
- name: Install Octopus CLI
uses: OctopusDeploy/install-octopus-cli-action@v3
- name: Test login with API Key
id: api_key
uses: ./
with:
server: ${{ env.SERVER_URL }}
api_key: ${{ env.ADMIN_API_KEY }}
- name: Print Octopus credential environment variables from API Key login
run: |
echo "OCTOPUS_URL = $OCTOPUS_URL"
echo "OCTOPUS_API_KEY = $OCTOPUS_API_KEY"
echo "server = ${{ steps.api_key.outputs.server }}"
echo "api_key = ${{ steps.api_key.outputs.api_key }}"
- name: List environments using CLI (API Key)
run: octopus environment list --space Default
- name: Get OIDC identity subject (PR)
run: echo "SUBJECT_REF=pull_request" >> $GITHUB_ENV
if: ${{ github.event_name == 'pull_request' }}
- name: Get OIDC identity subject (branch)
run: echo "SUBJECT_REF=ref:${{ github.ref }}" >> $GITHUB_ENV
if: ${{ github.event_name != 'pull_request' }}
- name: Create OIDC identity
run: 'curl -X POST -H ''X-Octopus-ApiKey: ${{ env.ADMIN_API_KEY }}'' -H ''Content-Type: application/json'' -d ''{"serviceAccountId":"Users-1","name":"GitHub Actions","issuer":"https://token.actions.githubusercontent.com","subject":"repo:OctopusDeploy/login:${{ env.SUBJECT_REF }}"}'' ${{ env.SERVER_URL }}/api/serviceaccounts/Users-1/oidcidentities/create/v1'
- name: Get OIDC identity details
run: |
curl -s -H "X-Octopus-ApiKey: ${{ env.ADMIN_API_KEY }}" "${{ env.SERVER_URL }}/api/serviceaccounts/Users-1/oidcidentities/v1?skip=0&take=1000" > ./oidcidentities.json
service_account_id=$(jq -r '.ExternalId' ./oidcidentities.json)
echo "SERVICE_ACCOUNT_ID=$service_account_id" >> $GITHUB_ENV
- name: Test login with OIDC
id: oidc
uses: ./
with:
server: ${{ env.SERVER_URL }}
service_account_id: ${{ env.SERVICE_ACCOUNT_ID }}
- name: Print Octopus credential environment variables from OIDC login
run: |
echo "OCTOPUS_URL = $OCTOPUS_URL"
echo "OCTOPUS_ACCESS_TOKEN = $OCTOPUS_ACCESS_TOKEN"
echo "server = ${{ steps.oidc.outputs.server }}"
echo "access_token = ${{ steps.oidc.outputs.access_token }}"
- name: List environments using CLI (OIDC)
run: octopus environment list --space Default