Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .actrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-P ubuntu-latest=catthehacker/ubuntu:act-latest
25 changes: 14 additions & 11 deletions .github/actions/reload-dev-portal/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,48 @@ runs:
uses: tj-actions/changed-files@dcc7a0cba800f454d79fff4b993e8c3555bcc0a8 # v45.0.7
with:
files: |
content/**/*.mdx
content/**
base_sha: ${{ inputs.base_sha }}
sha: ${{ inputs.head_sha }}
json: true

- name: Print changed files
shell: bash
run: |
echo "Changed files:"
echo ${{ steps.changed-files.outputs.all_changed_files }} | xargs -n 1

- name:
if: steps.changed-files.outputs.all_changed_files == ''
- name: Check for added or deleted files
id: check-files
shell: bash
run: |
echo "No changed files found, redeploying dev-portal in case of api changes"
curl -X POST ${{ inputs.dev-portal-deploy-hook-prod }}
HAS_ADDED=$(echo ${{ steps.changed-files.outputs.added_files }} | grep . > /dev/null && echo 'true' || echo 'false')
HAS_DELETED=$(echo ${{ steps.changed-files.outputs.deleted_files }} | grep . > /dev/null && echo 'true' || echo 'false')
echo "has_added=$HAS_ADDED" >> $GITHUB_OUTPUT
echo "has_deleted=$HAS_DELETED" >> $GITHUB_OUTPUT

- name:
if: steps.changed-files.outputs.all_changed_files_count >= 128
- name: Redeploy if files added/deleted or >= 50
if: steps.check-files.outputs.has_added == 'true' || steps.check-files.outputs.has_deleted == 'true' || steps.changed-files.outputs.all_changed_files_count >= 50
shell: bash
run: |
echo "More than 124 paths changed, redeploying dev-portal"
echo "File added/deleted or >= 50, redeploying dev-portal"
curl -X POST ${{ inputs.dev-portal-deploy-hook-prod }}

- name: Map files to URLs
id: map-files
if: steps.changed-files.outputs.all_changed_files_count < 128
if: steps.changed-files.outputs.all_changed_files_count < 50
shell: bash
run: |
FILES_URLS=$(node ./scripts/map-files-to-urls.mjs ${{ steps.changed-files.outputs.all_changed_files }})
echo "FILES_URLS=$FILES_URLS" >> $GITHUB_OUTPUT

- name: Print urls
if: steps.changed-files.outputs.all_changed_files_count < 128
if: steps.changed-files.outputs.all_changed_files_count < 50
shell: bash
run: echo ${{ steps.map-files.outputs.FILES_URLS }} | xargs -n 1

- name: Revalidate paths
if: steps.changed-files.outputs.all_changed_files_count < 128
if: steps.changed-files.outputs.all_changed_files_count < 50
id: revalidate-paths
shell: bash
env:
Expand Down
41 changes: 41 additions & 0 deletions .github/actions/workflow-tests/reload-dev-portal.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { ActRunner, ActExecStatus } from '@pshevche/act-test-runner'
import { describe, test, expect } from 'vitest'

import mockttp from 'mockttp'

const runCICDTests = process.env.RUN_CI_CD_Tests === 'true'

let mockServer
if (runCICDTests) {
mockServer = mockttp.getLocal()
await mockServer.start(8080)
}

describe.skipIf(!runCICDTests)('prod only test suite', () => {
test('custom workflow', { timeout: 120_000 }, async () => {
const deployEndpointMock = await mockServer
.forPost('/deploy')
.thenReply(200, 'OK')

const result = await new ActRunner()
.withWorkflowFile('.github/workflows/reload-dev-portal.yml')
// .withAdditionalArgs(["-P", "ubuntu-latest=catthehacker/ubuntu:act-latest"])
.withVariablesValues(['base_sha', '^HEAD'], ['head_sha', 'HEAD'])
.withSecretsValues(
['dev-portal-deploy-hook-prod', `${mockServer.url}/deploy`],
['revalidate-token', 'dummy_value'],
['bot-bypass-token', 'dummy_value'],
)
.withEnvValues(['http_proxy', 'http://host.docker.internal:8080'])
.withEvent('workflow_call')
.forwardOutput()
.run()

console.log(result)

expect(result.status).toBe(ActExecStatus.SUCCESS)

const requests = await deployEndpointMock.getSeenRequests()
expect(requests.length).to.equal(1)
})
})
77 changes: 77 additions & 0 deletions .github/workflows/reload-dev-portal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Reload dev portal

on:
workflow_call:
inputs:
base_sha:
description: 'Base SHA for changed files comparison'
required: true
type: string
head_sha:
description: 'Head SHA for changed files comparison'
required: true
type: string
secrets:
dev-portal-deploy-hook-prod:
revalidate-token:
bot-bypass-token:

jobs:
reload-dev-portal:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Get changed files in the content/ subdirectories
id: changed-files
uses: tj-actions/changed-files@dcc7a0cba800f454d79fff4b993e8c3555bcc0a8 # v45.0.7
with:
files: |
content/**
base_sha: ${{ inputs.base_sha }}
sha: ${{ inputs.head_sha }}
json: true

- name: Print changed files
run: |
echo "Changed files:"
echo ${{ steps.changed-files.outputs.all_changed_files }} | xargs -n 1

- name: Check for added or deleted files
id: check-files
run: |
HAS_ADDED=$(echo ${{ steps.changed-files.outputs.added_files }} | grep . > /dev/null && echo 'true' || echo 'false')
HAS_DELETED=$(echo ${{ steps.changed-files.outputs.deleted_files }} | grep . > /dev/null && echo 'true' || echo 'false')
echo "has_added=$HAS_ADDED" >> $GITHUB_OUTPUT
echo "has_deleted=$HAS_DELETED" >> $GITHUB_OUTPUT

- name: Redeploy if files added/deleted or >= 50
if: steps.check-files.outputs.has_added == 'true' || steps.check-files.outputs.has_deleted == 'true' || steps.changed-files.outputs.all_changed_files_count >= 50
run: |
echo "File added/deleted or >= 50, redeploying dev-portal"
curl -X POST ${{ secrets.dev-portal-deploy-hook-prod }}

- name: Map files to URLs
id: map-files
if: steps.changed-files.outputs.all_changed_files_count < 50
run: |
FILES_URLS=$(node ./scripts/map-files-to-urls.mjs ${{ steps.changed-files.outputs.all_changed_files }})
echo "FILES_URLS=$FILES_URLS" >> $GITHUB_OUTPUT

- name: Print urls
if: steps.changed-files.outputs.all_changed_files_count < 50
run: echo ${{ steps.map-files.outputs.FILES_URLS }} | xargs -n 1

- name: Revalidate paths
if: steps.changed-files.outputs.all_changed_files_count < 50
id: revalidate-paths
env:
url: 'https://developer.hashicorp.com/api/revalidate/paths'
auth: 'Authorization: Bearer ${{ secrets.revalidate-token }}'
bot-bypass: '${{ secrets.bot-bypass-token }}'
run: |
curl -X POST "${{ env.url }}" \
-H "${{ env.auth }}" \
-H "Content-Type: application/json" \
-H "X-BOT-BYPASS: ${{ env.bot-bypass }}" \
-d '{"paths": ${{ steps.map-files.outputs.FILES_URLS }} }'
Loading
Loading