name: Build Master on: push: branches: - master paths-ignore: - 'scripts/**' - '.gitignore' - '.github/**' - 'book/**' workflow_dispatch: concurrency: build_master permissions: packages: write id-token: write contents: write jobs: run-translation: runs-on: ubuntu-latest container: image: ghcr.io/hacktricks-wiki/hacktricks-cloud/translator-image:latest environment: prod steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 1 # Only fetch the latest commit for faster cloning # Build the mdBook - name: Build mdBook run: MDBOOK_BOOK__LANGUAGE=en mdbook build || (echo "Error logs" && cat hacktricks-preprocessor-error.log && echo "" && echo "" && echo "Debug logs" && (cat hacktricks-preprocessor.log | tail -n 20) && exit 1) - name: Install GitHub CLI run: | curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ && sudo apt update \ && sudo apt install gh -y - name: Publish search index release asset shell: bash env: PAT_TOKEN: ${{ secrets.PAT_TOKEN }} run: | set -euo pipefail ASSET="book/searchindex.js" TAG="searchindex-en" TITLE="Search Index (en)" if [ ! -f "$ASSET" ]; then echo "Expected $ASSET to exist after build" >&2 exit 1 fi TOKEN="${PAT_TOKEN:-${GITHUB_TOKEN:-}}" if [ -z "$TOKEN" ]; then echo "No token available for GitHub CLI" >&2 exit 1 fi export GH_TOKEN="$TOKEN" # Delete the release if it exists echo "Checking if release $TAG exists..." if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then echo "Release $TAG already exists, deleting it..." gh release delete "$TAG" --yes --repo "$GITHUB_REPOSITORY" --cleanup-tag || { echo "Failed to delete release, trying without cleanup-tag..." gh release delete "$TAG" --yes --repo "$GITHUB_REPOSITORY" || { echo "Warning: Could not delete existing release, will try to recreate..." } } sleep 2 # Give GitHub API a moment to process the deletion else echo "Release $TAG does not exist, proceeding with creation..." fi # Create new release (with force flag to overwrite if deletion failed) gh release create "$TAG" "$ASSET" --title "$TITLE" --notes "Automated search index build for master" --repo "$GITHUB_REPOSITORY" || { echo "Failed to create release, trying with force flag..." gh release delete "$TAG" --yes --repo "$GITHUB_REPOSITORY" --cleanup-tag >/dev/null 2>&1 || true sleep 2 gh release create "$TAG" "$ASSET" --title "$TITLE" --notes "Automated search index build for master" --repo "$GITHUB_REPOSITORY" } # Login in AWs - name: Configure AWS credentials using OIDC uses: aws-actions/configure-aws-credentials@v3 with: role-to-assume: ${{ secrets.AWS_ROLE_ARN }} aws-region: us-east-1 # Sync the build to S3 - name: Sync to S3 run: aws s3 sync ./book s3://hacktricks-wiki/en --delete