diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad662f066..bc478cd07 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,12 +44,43 @@ jobs: with: go-version-file: src/go.mod + SetEnv: + environment: Testing + runs-on: ubuntu-latest + outputs: + environment: ${{ steps.environment.outputs.environment }} + version: ${{ steps.version.outputs.version }} + steps: + - uses: actions/checkout@v3 + + - name: Figure out environment + id: environment + run: | + if ${{ startsWith(github.ref, 'refs/tags/') }}; then + echo "set-output name=environment::Production" + echo "::set-output name=environment::Production" + else + echo "set-output name=environment::Testing" + echo "::set-output name=environment::Testing" + fi + + - name: Get version string + id: version + run: | + if ${{ startsWith(github.ref, 'refs/tags/') }}; then + echo "set-output name=version::$(git describe --exact-match --tags $(git rev-parse HEAD))" + echo "::set-output name=version::$(git describe --exact-match --tags $(git rev-parse HEAD))" + else + echo "set-output name=version::$(echo unreleased-$(git rev-parse --short HEAD))" + echo "::set-output name=version::$(echo unreleased-$(git rev-parse --short HEAD))" + fi + # ---------------------------------------------------------------------------------------------------- # --- Docs Linting ----------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------- Docs-Linting: - needs: [Precheck, Checkout] + needs: [Precheck, Checkout, SetEnv] environment: Testing runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || needs.precheck.outputs.docfileschanged == 'true' # docsfileschanged also includes srcfileschanged @@ -77,13 +108,6 @@ jobs: mv ./src/cmd/mdgen/cli_markdown/* ./docs/docs/cli/ rm -R ./src/cmd/mdgen/cli_markdown/ - - uses: actions/upload-artifact@master - if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || needs.precheck.outputs.srcfileschanged == 'true' - name: Upload cli docs as artifacts - with: - name: cli-docs - path: docs/docs/cli - - name: Install dependencies for docs lint run: | wget https://github.com/errata-ai/vale/releases/download/v2.20.2/vale_2.20.2_Linux_64-bit.tar.gz # NOTE: update in Dockerfile when updating @@ -97,6 +121,23 @@ jobs: run: | cd docs && make -o genclidocs localcheck + - name: Build docs + env: + CORSO_VERSION: ${{ needs.SetEnv.outputs.version }} + run: | + cd docs && + npm ci && + npm run build + + - uses: actions/upload-artifact@master + # uncomment next line to disable creating docs artifacts on PR runs + # if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' + name: Upload docs as artifacts + with: + name: docs + path: docs/build + + # ---------------------------------------------------------------------------------------------------- # --- Integration and Unit Testing ------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------- @@ -195,37 +236,6 @@ jobs: # --- Publish steps ---------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------- - SetEnv: - environment: Testing - runs-on: ubuntu-latest - outputs: - environment: ${{ steps.environment.outputs.environment }} - version: ${{ steps.version.outputs.version }} - steps: - - uses: actions/checkout@v3 - - - name: Figure out environment - id: environment - run: | - if ${{ startsWith(github.ref, 'refs/tags/') }}; then - echo "set-output name=environment::Production" - echo "::set-output name=environment::Production" - else - echo "set-output name=environment::Testing" - echo "::set-output name=environment::Testing" - fi - - - name: Get version string - id: version - run: | - if ${{ startsWith(github.ref, 'refs/tags/') }}; then - echo "set-output name=version::$(git describe --exact-match --tags $(git rev-parse HEAD))" - echo "::set-output name=version::$(git describe --exact-match --tags $(git rev-parse HEAD))" - else - echo "set-output name=version::$(echo unreleased-$(git rev-parse --short HEAD))" - echo "::set-output name=version::$(echo unreleased-$(git rev-parse --short HEAD))" - fi - Publish-Binary: needs: [Test-Suite, Linting, Docs-Linting, SetEnv] environment: ${{ needs.SetEnv.outputs.environment }} @@ -267,7 +277,7 @@ jobs: needs: [Test-Suite, Linting, Docs-Linting, SetEnv] environment: ${{ needs.SetEnv.outputs.environment }} runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || needs.precheck.outputs.docfileschanged == 'true' # docsfileschanged also includes srcfileschanged + if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' defaults: run: working-directory: docs @@ -276,38 +286,28 @@ jobs: - uses: actions/checkout@v3 - uses: actions/download-artifact@master - name: Download cli docs from build step + name: Download docs from build step with: - name: cli-docs - path: docs/docs/cli + name: docs + path: docs/build - name: Configure AWS credentials from Test account - if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' uses: aws-actions/configure-aws-credentials@v1 with: role-to-assume: ${{ secrets.AWS_IAM_ROLE }} role-session-name: integration-testing aws-region: us-east-1 - - name: Build docs - env: - CORSO_VERSION: ${{ needs.SetEnv.outputs.version }} - run: | - npm ci - npm run build - - name: Add rotbots.txt if: github.ref == 'refs/heads/main' run: | printf 'User-agent: *\nDisallow: /' > build/robots.txt - name: Push docs - if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' run: | aws s3 sync build "s3://${{ secrets.DOCS_S3_BUCKET }}" - name: Invalidate cloudfront - if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' run: | aws cloudfront create-invalidation --distribution-id ${{ secrets.DOCS_CF_DISTRIBUTION }} --paths "/*"