Skip to content

Build and test

Build and test #1267

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