From ca7073ce873059d90e15170a61c4143f6c6db72a Mon Sep 17 00:00:00 2001 From: Soufiane Fariss Date: Wed, 9 Oct 2024 17:20:50 +0200 Subject: [PATCH 1/3] ci: add web releases workflow --- .github/workflows/web-release.yml | 67 +++++++++++++++++++++++++++++++ .github/workflows/web-tests.yml | 13 +++--- web/explorer/.gitignore | 3 ++ 3 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/web-release.yml diff --git a/.github/workflows/web-release.yml b/.github/workflows/web-release.yml new file mode 100644 index 000000000..a0156657f --- /dev/null +++ b/.github/workflows/web-release.yml @@ -0,0 +1,67 @@ +name: create capa Explorer Web release + +on: + workflow_dispatch: + inputs: + version: + description: 'Version number for the release (x.x.x)' + required: true + type: string + +jobs: + run-tests: + uses: ./.github/workflows/web-tests.yml + + build-and-release: + needs: run-tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set release name + run: echo "RELEASE_NAME=capa-explorer-web-${{ github.event.inputs.version }}-${GITHUB_SHA::7}" >> $GITHUB_ENV + + - name: Check if release already exists + run: | + if ls web/explorer/releases/capa-explorer-web-${{ github.event.inputs.version }}-* 1> /dev/null 2>&1; then + echo "A release with version ${{ github.event.inputs.version }} already exists" + exit 1 + fi + + - name: Set up Node.js + uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4 + with: + node-version: 20 + cache: 'npm' + cache-dependency-path: 'web/explorer/package-lock.json' + + - name: Install dependencies + run: npm ci + working-directory: web/explorer + + - name: Build offline bundle + run: npm run build:bundle + working-directory: web/explorer + + - name: Compress bundle + run: zip -r ${{ env.RELEASE_NAME }}.zip capa-explorer-web + working-directory: web/explorer + + - name: Create releases directory + run: mkdir -vp web/explorer/releases + + - name: Move archive release to releases folder + run: mv web/explorer/${{ env.RELEASE_NAME }}.zip web/explorer/releases + + - name: Commit and push release + run: | + git config --local user.email "capa-dev@mandiant.com" + git config --local user.name "Capa Bot" + git add -f web/explorer/releases/${{ env.RELEASE_NAME }}.zip + git commit -m "explorer web: add release ${{ env.RELEASE_NAME }}" + git push + + - name: Remove older releases + # keep only the latest 3 releases + run: ls -t capa-explorer-web-*.zip | tail -n +4 | xargs -r rm -- + working-directory: web/explorer/releases diff --git a/.github/workflows/web-tests.yml b/.github/workflows/web-tests.yml index 8a8a63312..22016a3a5 100644 --- a/.github/workflows/web-tests.yml +++ b/.github/workflows/web-tests.yml @@ -1,10 +1,11 @@ -name: Capa Explorer Web tests +name: capa Explorer Web tests on: pull_request: branches: [ master ] paths: - 'web/explorer/**' + workflow_call: # this allows the workflow to be called by other workflows jobs: test: @@ -23,20 +24,20 @@ jobs: with: node-version: 20 cache: 'npm' - cache-dependency-path: './web/explorer/package-lock.json' + cache-dependency-path: 'web/explorer/package-lock.json' - name: Install dependencies run: npm ci - working-directory: ./web/explorer + working-directory: web/explorer - name: Lint run: npm run lint - working-directory: ./web/explorer + working-directory: web/explorer - name: Format run: npm run format:check - working-directory: ./web/explorer + working-directory: web/explorer - name: Run unit tests run: npm run test - working-directory: ./web/explorer + working-directory: web/explorer diff --git a/web/explorer/.gitignore b/web/explorer/.gitignore index 064b5fed8..c734baff7 100644 --- a/web/explorer/.gitignore +++ b/web/explorer/.gitignore @@ -7,6 +7,9 @@ yarn-error.log* pnpm-debug.log* lerna-debug.log* +# capa Explorer Web Releases +releases/ + # Dependencies, build results, and other generated files node_modules .DS_Store From 7be6fe6ae1d71405730c5d12c47d14df4c6eb4af Mon Sep 17 00:00:00 2001 From: Soufiane Fariss Date: Wed, 9 Oct 2024 18:15:56 +0200 Subject: [PATCH 2/3] changelog: add web releases workflow --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97f0bfc20..b8e32a9a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -178,6 +178,7 @@ Special thanks to our repeat and new contributors: - CI: update Binary Ninja version to 4.1 and use Python 3.9 to test it #2211 @xusheng6 - CI: update tests.yml workflow to exclude web and documentation files #2263 @s-ff - CI: update build.yml workflow to exclude web and documentation files #2270 @s-ff +- CI: add web releases workflow #2455 @s-ff ### Raw diffs From 54badc323d49f6f8c0d05d01f25f51d79a539b89 Mon Sep 17 00:00:00 2001 From: Soufiane Fariss Date: Mon, 14 Oct 2024 11:59:17 +0200 Subject: [PATCH 3/3] ci: add CHANGELOG.md for web releases --- .github/workflows/web-release.yml | 38 ++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/.github/workflows/web-release.yml b/.github/workflows/web-release.yml index a0156657f..4dedff923 100644 --- a/.github/workflows/web-release.yml +++ b/.github/workflows/web-release.yml @@ -1,5 +1,4 @@ -name: create capa Explorer Web release - +name: create web release on: workflow_dispatch: inputs: @@ -19,12 +18,12 @@ jobs: - uses: actions/checkout@v4 - name: Set release name - run: echo "RELEASE_NAME=capa-explorer-web-${{ github.event.inputs.version }}-${GITHUB_SHA::7}" >> $GITHUB_ENV + run: echo "RELEASE_NAME=capa-explorer-web-v${{ github.event.inputs.version }}-${GITHUB_SHA::7}" >> $GITHUB_ENV - name: Check if release already exists run: | - if ls web/explorer/releases/capa-explorer-web-${{ github.event.inputs.version }}-* 1> /dev/null 2>&1; then - echo "A release with version ${{ github.event.inputs.version }} already exists" + if ls web/explorer/releases/capa-explorer-web-v${{ github.event.inputs.version }}-* 1> /dev/null 2>&1; then + echo "::error:: A release with version ${{ github.event.inputs.version }} already exists" exit 1 fi @@ -50,18 +49,31 @@ jobs: - name: Create releases directory run: mkdir -vp web/explorer/releases - - name: Move archive release to releases folder + - name: Move release to releases folder run: mv web/explorer/${{ env.RELEASE_NAME }}.zip web/explorer/releases - - name: Commit and push release + - name: Compute release SHA256 hash run: | - git config --local user.email "capa-dev@mandiant.com" - git config --local user.name "Capa Bot" - git add -f web/explorer/releases/${{ env.RELEASE_NAME }}.zip - git commit -m "explorer web: add release ${{ env.RELEASE_NAME }}" - git push + echo "RELEASE_SHA256=$(sha256sum web/explorer/releases/${{ env.RELEASE_NAME }}.zip | awk '{print $1}')" >> $GITHUB_ENV + + - name: Update CHANGELOG.md + run: | + echo "## ${{ env.RELEASE_NAME }}" >> web/explorer/releases/CHANGELOG.md + echo "- Release Date: $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> web/explorer/releases/CHANGELOG.md + echo "- SHA256: ${{ env.RELEASE_SHA256 }}" >> web/explorer/releases/CHANGELOG.md + echo "" >> web/explorer/releases/CHANGELOG.md + cat web/explorer/releases/CHANGELOG.md - name: Remove older releases # keep only the latest 3 releases - run: ls -t capa-explorer-web-*.zip | tail -n +4 | xargs -r rm -- + run: ls -t capa-explorer-web-v*.zip | tail -n +4 | xargs -r rm -- working-directory: web/explorer/releases + + - name: Commit and push release + run: | + git config --local user.email "capa-dev@mandiant.com" + git config --local user.name "Capa Bot" + git add -f web/explorer/releases/${{ env.RELEASE_NAME }}.zip web/explorer/releases/CHANGELOG.md + git add -u web/explorer/releases/ + git commit -m ":robot: explorer web: add release ${{ env.RELEASE_NAME }}" + git push