From 029d4417b3adc57d68803bd2e27cf2058f68c90f Mon Sep 17 00:00:00 2001 From: Rob Dalton <139376867+rdalton-va@users.noreply.github.com> Date: Tue, 4 Mar 2025 11:52:27 -0500 Subject: [PATCH] API-45148 Add github actions workflow (#214) * Add github actions workflow * yarn --> npm * Try using docker octopus node * Add user root option * See if node16 works * Try leaving user alone * Use root user * Make directory * Remove directory creation * Add unsecure node version fix https://github.com/vgc/vgc/issues/1804 * Change user directory to lhuser * remove directory option * use node18 rather than node18-di * Use lhuser * Try updating the libraries * Updating the libraries didn't work * Stop using docker octopus node * Validate that pipeline will know if tests fail * Use actions/setup-node * Remove fake error * Add names to steps * Create release workflow * Goodbye Jenkins * Add manual release --- .github/workflows/build-and-test.yml | 28 +++++++++++++++++ .github/workflows/release.yml | 42 +++++++++++++++++++++++++ Jenkinsfile | 47 ---------------------------- 3 files changed, 70 insertions(+), 47 deletions(-) create mode 100644 .github/workflows/build-and-test.yml create mode 100644 .github/workflows/release.yml delete mode 100644 Jenkinsfile diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000..733126d --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,28 @@ +# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs + +name: Build and Test + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: '18.x' + cache: 'npm' + - name: Install Dependencies + run: npm ci + - name: Build Package + run: npm run build + - name: Run Tests + run: npm run test:ci diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..da95ee3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,42 @@ +# taken from the semantic-release documentation +# https://semantic-release.gitbook.io/semantic-release/recipes/ci-configurations/github-actions + +name: Release +on: + push: + branches: + - master + workflow_dispatch: + +permissions: + contents: read # for checkout + +jobs: + release: + name: Release + runs-on: ubuntu-latest + permissions: + contents: write # to be able to publish a GitHub release + issues: write # to be able to comment on released issues + pull-requests: write # to be able to comment on released pull requests + id-token: write # to enable use of OIDC for npm provenance + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "18.x" + - name: Install dependencies + run: npm clean-install + - name: Verify the integrity of provenance attestations and registry signatures for installed dependencies + run: npm audit signatures + - name: Build Package + run: npm run build + - name: Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: npm run release diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index ed78963..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,47 +0,0 @@ -pipeline { - agent { - docker { - image 'ghcr.io/department-of-veterans-affairs/health-apis-docker-octopus/lighthouse-node-application-base:node16' - registryUrl 'https://ghcr.io' - registryCredentialsId 'GITHUB_USERNAME_TOKEN' - } - } - environment { - NPM_TOKEN = credentials('LIGHTHOUSE_NPM_REGISTRY_TOKEN') - } - - stages { - stage('Setup') { - steps { - sh 'npm install' - } - } - stage('Lint') { - steps{ - sh 'npm run lint' - } - } - stage('Test') { - steps { - sh 'npm run test:ci' - } - } - stage('Build') { - steps { - sh 'npm run build' - } - } - stage('Release') { - steps { - withCredentials([ - usernamePassword( - credentialsId: 'GITHUB_USERNAME_TOKEN', - usernameVariable: 'GITHUB_USERNAME', - passwordVariable: 'GITHUB_TOKEN') - ]) { - sh 'npm run release' - } - } - } - } -}