From 6ff6ba11eb78b77e323aed1c59dae5562dcbd91a Mon Sep 17 00:00:00 2001 From: Mathieu Veber Date: Tue, 7 Nov 2023 16:10:02 +0100 Subject: [PATCH] ci: Add shared workflows --- .github/workflows/assign-to-project.yml | 43 +++++++++++ .github/workflows/continuous-integration.yml | 77 ++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 .github/workflows/assign-to-project.yml create mode 100644 .github/workflows/continuous-integration.yml diff --git a/.github/workflows/assign-to-project.yml b/.github/workflows/assign-to-project.yml new file mode 100644 index 0000000..4f6c879 --- /dev/null +++ b/.github/workflows/assign-to-project.yml @@ -0,0 +1,43 @@ +name: Assign issues and PRs to project + +on: + issues: + types: [opened, reopened] + + pull_request: + types: [opened, reopened] + + workflow_call: + inputs: + project-id: + default: 2 + description: Issues and PRs will be assigned to that project. Default to 2 (Hedia). + required: false + type: number + + secrets: + ASSIGN_TO_PROJECT_TOKEN: + description: Personal Access Token with "repo" and "project" permissions. + required: true + +jobs: + project: + runs-on: ubuntu-latest + steps: + + - id: addItem + name: Add to project + uses: actions/add-to-project@v0.5.0 + with: + project-url: https://github.com/orgs/hedia-team/projects/${{inputs.project-id}} + github-token: ${{ secrets.ASSIGN_TO_PROJECT_TOKEN }} + + - if: github.event_name == 'pull_request' + name: Set status + uses: hedia-team/titoportas_update-project-fields@v0.1.0 + with: + project-url: https://github.com/orgs/hedia-team/projects/${{inputs.project-id}} + github-token: ${{ secrets.ASSIGN_TO_PROJECT_TOKEN }} + item-id: ${{ steps.addItem.outputs.itemId }} + field-keys: Status + field-values: In Progress diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 0000000..080eab4 --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,77 @@ +name: Run Build, Tests & SonarCloud Scan + +on: + workflow_call: + inputs: + database: + description: Database used in this workflow. Default to none. + required: false + type: string + + secrets: + READONLY_NPM_TOKEN: + description: Needed to install private @hedia npm packages + required: true + SONAR_TOKEN: + description: Needed to run SonarCloud Scan + required: true + +jobs: + build-test: + runs-on: ubuntu-latest + + services: + postgres: + image: ${{ inputs.database && 'postgres' || '' }} + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + POSTGRES_DB: ${{ inputs.database }} + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of SonarCloud analysis + + - name: Setup Node.js Environment + uses: actions/setup-node@v3 + with: + node-version-file: "package.json" + always-auth: true + registry-url: https://registry.npmjs.org + scope: "@hedia" + + - name: "Install Dependencies" + run: npm ci + env: + NODE_AUTH_TOKEN: ${{ secrets.READONLY_NPM_TOKEN }} + + - name: "Build Repository" + run: "npm run build --if-present" + + - name: "Run Tests" + run: "npm run test" + + - name: SonarCloud Init + env: + GITHUB_PROJECT: ${{ github.repository }} + run: echo "GITHUB_PROJECT=${GITHUB_PROJECT/\//_}" >> $GITHUB_ENV + + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ github.token }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + args: > + -Dsonar.projectKey=${{ env.GITHUB_PROJECT }} + -Dsonar.organization=${{ github.repository_owner }} + -Dsonar.coverageReportPaths=coverage.xml