diff --git a/.github/workflows/publish-preview-manual.yml b/.github/workflows/publish-preview-manual.yml new file mode 100644 index 0000000000..20675e0a66 --- /dev/null +++ b/.github/workflows/publish-preview-manual.yml @@ -0,0 +1,104 @@ +name: GitHub Actions preview build manual + +on: + workflow_dispatch: + inputs: + pr_number: + description: 'PR number' + required: true + type: string + +env: + NODE_VER: '20.x' + JAVA_DISTRIBUTION: 'zulu' + JAVA_VER: 11 + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + ref: refs/pull/${{ github.event.inputs.pr_number }}/merge + fetch-depth: 0 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.2' + + - name: Install Jekyll + run: gem install jekyll + + - name: Initialize Jekyll site + run: | + jekyll new --skip-bundle ${{ github.workspace }}/reposense-report + env: + JEKYLL_ENV: production + + - name: Set up Vite environment + run: | + export VITE_BASE_DIR="/$(basename $GITHUB_REPOSITORY)" + echo "VITE_BASE_DIR: $VITE_BASE_DIR" + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + distribution: ${{ env.JAVA_DISTRIBUTION }} + java-version: ${{ env.JAVA_VER }} + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VER }} + + - name: Set up Gradle caching + uses: actions/cache@v3 + with: + path: | + $HOME/.gradle/caches + $HOME/.gradle/wrapper + key: ${{ matrix.os }}-gradle-${{ hashFiles('**/*.gradle*') }} + restore-keys: | + ${{ matrix.os }}-gradle- + + - name: Set up Node caching + uses: actions/cache@v3 + with: + path: $HOME/.npm + key: ${{ matrix.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ matrix.os }}-node- + + - name: Grant execute permission for gradlew + if: ${{ runner.os != 'Windows' }} + run: chmod +x gradlew + + - name: Build with Gradle + run: ./gradlew run + + - name: Run local website on action runner + run: | + gem install bundler + cd ${SITE} + bundle install + bundle exec jekyll serve --detach + env: + SITE: ${{github.workspace}}/reposense-report + + - name: Wait for the service to start + run: sleep 10 + + - name: Test connection to deployed website + run: curl -L http://0.0.0.0:4000/$VITE_BASE_DIR + + - name: Test deployed web page + uses: treosh/lighthouse-ci-action@v12 + with: + urls: http://0.0.0.0:4000/${{ env.VITE_BASE_DIR }} + uploadArtifacts: true + + - name: Display Lighthouse summary + run: cat .lighthouseci/manifest.json | jq '.' diff --git a/docs/dg/devOpsGuide.md b/docs/dg/devOpsGuide.md index 3699c85779..ad4599333d 100644 --- a/docs/dg/devOpsGuide.md +++ b/docs/dg/devOpsGuide.md @@ -84,3 +84,12 @@ For authentication, two secrets are stored and used in GitHub Actions: The `surge` command automatically detects the existence of these two environment variables and use them for authentication when deploying the RepoSense report and documentation build previews. Currently, deployments are kept forever, even after the pull request is merged or closed. There is currently no existing functionality to automatically clean up deployments after they are no longer useful. + + + +## Post-deployment test +Publish-RepoSense is our default tool for deploying RepoSense reports. We have automated the testing of deployments via this tool before each merge to strengthen our CI/CD processes. This is automatically performed by the job "GitHub Actions build preview" using the [`publish-preview.yml`](https://github.com/reposense/RepoSense/blob/master/config/gh-actions/publish-preview.yml). + +There is a manual action named `GitHub Actions preview build manual` using the [`publish-preview-manual.yml`](https://github.com/reposense/RepoSense/blob/master/config/gh-actions/publish-preview-manual.yml). It takes in an input of the PR number and run the test on the branch referring to the PR. + +The action will simulate a `jekyll build` environment using docker container on the GitHub action runner and audit the webpage using `lighthoucse-ci`, detecting potential issues in rendering the dashboard in actual github environments.