From 85f0054d0c50c53bc35ecab7b318b82da8343e6f Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Thu, 15 Aug 2024 11:37:36 +0530 Subject: [PATCH] Fix GitHub CI build issue Signed-off-by: Anup Patel --- .github/workflows/build-doc.yml | 64 ------------------------- .github/workflows/build-pdf.yml | 73 ++++++++++++++++++++++++++++ Makefile | 84 +++++++++++++++++++++------------ dependencies/Gemfile | 14 ++++++ dependencies/README.md | 2 + dependencies/apt_packages.txt | 32 +++++++++++++ dependencies/package.json | 8 ++++ docs-resources | 2 +- 8 files changed, 185 insertions(+), 94 deletions(-) delete mode 100644 .github/workflows/build-doc.yml create mode 100644 .github/workflows/build-pdf.yml create mode 100644 dependencies/Gemfile create mode 100644 dependencies/README.md create mode 100644 dependencies/apt_packages.txt create mode 100644 dependencies/package.json diff --git a/.github/workflows/build-doc.yml b/.github/workflows/build-doc.yml deleted file mode 100644 index 1d50ea9..0000000 --- a/.github/workflows/build-doc.yml +++ /dev/null @@ -1,64 +0,0 @@ -name: Create Specification Document - -on: - workflow_dispatch: - inputs: - prerelease: - description: 'Tag as a pre-release?' - required: false - type: boolean - default: true - draft: - description: 'Create release as a draft?' - required: false - type: boolean - default: false - pull_request: - push: - branches: - - main - - master - -jobs: - build: - runs-on: ubuntu-latest - - steps: - # Step 1: Checkout the repository - - name: Checkout repository - uses: actions/checkout@v3 - with: - submodules: 'recursive' - fetch-depth: 0 - - # Step 2: Install Dependencies - - name: Install Dependencies - run: | - sudo apt-get update - sudo apt-get install -y pandoc asciidoctor ditaa ruby-asciidoctor-pdf - - # Step 3: Build Files - - name: Build Files - run: make - - # Step 4: Upload the built PDF and HTML files as artifacts - - name: Upload Build Artifacts - uses: actions/upload-artifact@v3 - with: - name: Build Artifacts - path: | - riscv-sbi.pdf - retention-days: 30 - - # Create Release - - name: Create Release - uses: softprops/action-gh-release@v1 - with: - files: ./riscv-sbi.pdf - tag_name: commit-${{ github.sha }} - name: Release commit-${{ github.sha }} - draft: ${{ github.event.inputs.draft }} - prerelease: ${{ github.event.inputs.prerelease }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUBTOKEN }} - if: github.event_name == 'workflow_dispatch' diff --git a/.github/workflows/build-pdf.yml b/.github/workflows/build-pdf.yml new file mode 100644 index 0000000..b7be4dd --- /dev/null +++ b/.github/workflows/build-pdf.yml @@ -0,0 +1,73 @@ +name: Create Specification Document + +# The workflow is triggered by pull request, push to main, and manual dispatch. +on: + workflow_dispatch: + inputs: + version: + description: 'Release version, e.g. X.Y.Z:' + required: true + type: string + revision_mark: + description: 'Set revision mark as Draft, Release or Stable:' + required: true + type: string + default: 'Draft' + prerelease: + description: 'Tag as a pre-release?' + required: false + type: boolean + default: true + draft: + description: 'Create release as a draft?' + required: false + type: boolean + default: false + pull_request: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + # Step 1: Checkout the repository + - name: Checkout repository + uses: actions/checkout@v3 + with: + submodules: 'recursive' + + # Step 2: Pull the latest RISC-V Docs container image + - name: Pull Container + run: docker pull riscvintl/riscv-docs-base-container-image:latest + + # Step 3: Build Files + - name: Build Files + run: make + env: + VERSION: v${{ github.event.inputs.version }} + REVMARK: ${{ github.event.inputs.revision_mark }} + + # Step 4: Upload the built PDF files as a single artifact + - name: Upload Build Artifacts + uses: actions/upload-artifact@v3 + with: + name: Build Artifacts + path: ${{ github.workspace }}/*.pdf + retention-days: 30 + + # Create Release + - name: Create Release + uses: softprops/action-gh-release@v1 + with: + files: ${{ github.workspace }}/*.pdf + tag_name: v${{ github.event.inputs.version }} + name: Release ${{ github.event.inputs.version }} + draft: ${{ github.event.inputs.draft }} + prerelease: ${{ github.event.inputs.prerelease }} + env: + GITHUB_TOKEN: ${{ secrets.GHTOKEN }} + if: github.event_name == 'workflow_dispatch' + # This condition ensures this step only runs for workflow_dispatch events. diff --git a/Makefile b/Makefile index ffd676e..522b16e 100644 --- a/Makefile +++ b/Makefile @@ -2,19 +2,9 @@ # Build usable documents # -ASCIIDOCTOR = asciidoctor -ASCIIDOCTOR_PDF = $(ASCIIDOCTOR)-pdf -OPTIONS := --trace \ - -a toc \ - -a compress \ - -a mathematical-format=svg \ - -a pdf-fontsdir=docs-resources/fonts \ - -a pdf-theme=docs-resources/themes/riscv-pdf.yml \ - --failure-level=ERROR -REQUIRES := --require=asciidoctor-bibtex \ - --require=asciidoctor-diagram \ - --require=asciidoctor-mathematical -DITAA = ditaa +DOCKER_RUN := docker run --rm -v ${PWD}:/build -w /build \ +riscvintl/riscv-docs-base-container-image:latest + DEPS = src/contributors.adoc DEPS += src/changelog.adoc DEPS += src/intro.adoc @@ -41,43 +31,79 @@ DEPS += src/ext-vendor.adoc DEPS += src/ext-firmware.adoc DEPS += src/references.adoc DEPS += src/references.bib + +DEPS += $(SPEC)/autogenerated/revision.adoc-snippet + IMAGES = images/riscv-sbi-intro1.png IMAGES += images/riscv-sbi-intro2.png IMAGES += images/riscv-sbi-hsm.png IMAGES += images/riscv-sbi-sse-sm.png -REVSNIP = $(SPEC)/autogenerated/revision.adoc-snippet + TARGETS = riscv-sbi.pdf -TARGETS += riscv-sbi.html -TARGETS += $(REVSNIP) + COMMITDATE=$(shell git show -s --format=%ci | cut -d ' ' -f 1) GITVERSION=$(shell git describe --tag) SPEC=$(shell pwd) -.PHONY: all -all: $(IMAGES) $(TARGETS) +ASCIIDOCTOR_PDF := asciidoctor-pdf +OPTIONS := --trace \ + -a compress \ + -a mathematical-format=svg \ + -a pdf-fontsdir=docs-resources/fonts \ + -a pdf-theme=docs-resources/themes/riscv-pdf.yml \ + --failure-level=ERROR +REQUIRES := --require=asciidoctor-bibtex \ + --require=asciidoctor-diagram \ + --require=asciidoctor-mathematical -images/%.png: src/%.ditaa - rm -f $@ - $(DITAA) $< $@ +.PHONY: all images clean -%.html: %.adoc $(IMAGES) $(REVSNIP) $(DEPS) - $(ASCIIDOCTOR) -d book -b html $< +all: $(TARGETS) +images: $(IMAGES) -%.pdf: %.adoc $(IMAGES) docs-resources/themes/riscv-pdf.yml $(REVSNIP) $(DEPS) - $(ASCIIDOCTOR_PDF) $(OPTIONS) $(REQUIRES) --out-file=$@ $< +# Preserve all intermediate files +.SECONDARY: -$(SPEC)/autogenerated: - -mkdir $@ +images/%.png: src/%.ditaa + mkdir -p `dirname $@` + ditaa $< $@ -$(SPEC)/autogenerated/revision.adoc-snippet: Makefile $(SPEC)/autogenerated +$(SPEC)/autogenerated/revision.adoc-snippet: Makefile + mkdir -p $(SPEC)/autogenerated echo ":revdate: ${COMMITDATE}" > $@-tmp echo ":revnumber: ${GITVERSION}" >> $@-tmp (test -f $@ && diff $@ $@-tmp) || mv $@-tmp $@ +%.pdf: %.adoc $(DEPS) + @echo "Checking if Docker is available..." + @if command -v docker >/dev/null 2>&1 ; then \ + echo "Docker is available, building inside Docker container..."; \ + $(MAKE) build-container/$@; \ + cp -f build-container/$@ $@; \ + else \ + echo "Docker is not available, building without Docker..."; \ + $(MAKE) build-no-container/$@; \ + cp -f build-no-container/$@ $@; \ + fi + +build-container/%.pdf: %.adoc $(DEPS) + @echo "Starting build inside Docker container..." + @mkdir -p `dirname $@` + $(DOCKER_RUN) /bin/sh -c "$(ASCIIDOCTOR_PDF) $(OPTIONS) $(REQUIRES) --out-file=$@ $<" + @echo "Build completed successfully inside Docker container." + +build-no-container/%.pdf: %.adoc $(DEPS) + @echo "Starting build..." + @mkdir -p `dirname $@` + $(ASCIIDOCTOR_PDF) $(OPTIONS) $(REQUIRES) --out-file=$@ $< + @echo "Build completed successfully." + .PHONY: clean clean: - rm -f $(TARGETS) + @echo "Cleaning up generated files..." + rm -rf build-container build-no-container $(TARGETS) rm -rf $(SPEC)/autogenerated + @echo "Cleanup completed." .PHONY: install-debs install-debs: diff --git a/dependencies/Gemfile b/dependencies/Gemfile new file mode 100644 index 0000000..8cf7a50 --- /dev/null +++ b/dependencies/Gemfile @@ -0,0 +1,14 @@ +source 'https://rubygems.org' +gem 'asciidoctor' +gem 'asciidoctor-bibtex' +gem 'asciidoctor-diagram' +gem 'asciidoctor-mathematical' +gem 'asciidoctor-pdf' +gem 'citeproc-ruby' +gem 'coderay' +gem 'csl-styles' +gem 'json' +gem 'pygments.rb' +gem 'rghost' +gem 'rouge' +gem 'ruby_dev' diff --git a/dependencies/README.md b/dependencies/README.md new file mode 100644 index 0000000..f64a366 --- /dev/null +++ b/dependencies/README.md @@ -0,0 +1,2 @@ +Dependencies for the build environment for various package managers. Used in +`.github/workflows/`. diff --git a/dependencies/apt_packages.txt b/dependencies/apt_packages.txt new file mode 100644 index 0000000..905045d --- /dev/null +++ b/dependencies/apt_packages.txt @@ -0,0 +1,32 @@ +bison +build-essential +python3-pip +cmake +curl +flex +fonts-lyx +git +graphviz +default-jre +libcairo2-dev +libffi-dev +libgdk-pixbuf2.0-dev +libpango1.0-dev +libxml2-dev +libglib2.0-dev +make +pkg-config +ruby +ruby-dev +libgif-dev +libwebp-dev +libzstd-dev +ruby-full +gem +npm +texlive-latex-base +texlive-fonts-recommended +texlive-fonts-extra +texlive-latex-extra +texlive-science +ditaa diff --git a/dependencies/package.json b/dependencies/package.json new file mode 100644 index 0000000..7347d43 --- /dev/null +++ b/dependencies/package.json @@ -0,0 +1,8 @@ +{ + "dependencies": { + "bytefield-svg": "^1.8.0", + "wavedrom-cli": "^2.6.8" + }, + "name": "local", + "version": "0.0.1" +} diff --git a/docs-resources b/docs-resources index 35203a4..d7a4606 160000 --- a/docs-resources +++ b/docs-resources @@ -1 +1 @@ -Subproject commit 35203a4f123d0be162b6b5ea213a657b594f8c36 +Subproject commit d7a4606ae3302a94d679ecd21c311b11c3433446