Skip to content

Commit

Permalink
Make releases from workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
goerz committed Dec 28, 2020
1 parent 6b443de commit dcbab8e
Showing 1 changed file with 232 additions and 87 deletions.
319 changes: 232 additions & 87 deletions .github/workflows/docs.yml
Expand Up @@ -25,137 +25,282 @@ jobs:
- name: Generate HTML Documentation
run: tox -e docs

- name: Generate LaTeX Documentation
run: |
tox -e docs -- -b latex docs/_build/latex
tox -e run-cmd -- python docs/sources/build_pdf.py --patch-only docs/_build/latex/*.tex
- uses: xu-cheng/latex-action@v2
name: Compile LaTex (first pass)
with:
compiler: lualatex
args: --interaction=nonstopmode --halt-on-error
working_directory: docs/_build/latex
root_file: qalgebra.tex

- uses: xu-cheng/latex-action@v2
name: Compile LaTex (second pass)
with:
compiler: lualatex
args: --interaction=nonstopmode --halt-on-error
working_directory: docs/_build/latex
root_file: qalgebra.tex
# - name: Generate LaTeX Documentation
# run: |
# tox -e docs -- -b latex docs/_build/latex
# tox -e run-cmd -- python docs/sources/build_pdf.py --patch-only docs/_build/latex/*.tex
#
# - uses: xu-cheng/latex-action@v2
# name: Compile LaTex (first pass)
# with:
# compiler: lualatex
# args: --interaction=nonstopmode --halt-on-error
# working_directory: docs/_build/latex
# root_file: qalgebra.tex
#
# - uses: xu-cheng/latex-action@v2
# name: Compile LaTex (second pass)
# with:
# compiler: lualatex
# args: --interaction=nonstopmode --halt-on-error
# working_directory: docs/_build/latex
# root_file: qalgebra.tex

- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::$(python -c 'print([line.split("=")[-1].strip()[1:-1] for line in open("./src/qalgebra/__init__.py", encoding="utf8").readlines() if line.startswith("__version__")][0], end="")')

- name: Get branch name
shell: bash
run: |
echo ${{ github.ref }}
echo "BRANCH_NAME=$(echo ${GITHUB_REF##*/} | tr / -)" >> $GITHUB_ENV
cat $GITHUB_ENV
- name: Zip the HTML documentation
run: zip-folder --debug --auto-root --outfile "qalgebra-docs-${{ steps.get_version.outputs.VERSION }}.zip" docs/_build/html

- name: Rename the PDF documentation
run: mv docs/_build/latex/qalgebra.pdf "qalgebra-docs-${{ steps.get_version.outputs.VERSION }}.pdf"
# - name: Rename the PDF documentation
# run: mv docs/_build/latex/qalgebra.pdf "qalgebra-docs-${{ steps.get_version.outputs.VERSION }}.pdf"

- uses: actions/upload-artifact@v2
name: Upload documentation artifacts
with:
name: qalgebra-docs
# We need at least two files in the artifact to avoid a weird
# double-zip file. Hence README.md
path: |
./qalgebra-docs-${{ steps.get_version.outputs.VERSION }}.zip
./qalgebra-docs-${{ steps.get_version.outputs.VERSION }}.pdf
README.md
./qalgebra-docs-${{ steps.get_version.outputs.VERSION }}.*
deploy_gh_pages:
name: Deploy documentation to gh-pages
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
create_github_release:
name: Create a Github Release
runs-on: ubuntu-18.04
# if: startsWith(github.ref, 'refs/tags/v')
needs: build_docs
steps:

- name: Checkout code
uses: actions/checkout@v2

- uses: actions/setup-python@v2
name: Install Python 3.8
with:
python-version: 3.8

- name: Install deploy requirements
run: pip install git+https://github.com/goerz/doctr_versions_menu.git@master#egg=doctr_versions_menu
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::$(python -c 'print([line.split("=")[-1].strip()[1:-1] for line in open("./src/qalgebra/__init__.py", encoding="utf8").readlines() if line.startswith("__version__")][0], end="")')

- name: Check the version (DEBUG)
run: |
echo "${{ steps.get_version.outputs.VERSION }}"
- name: Get branch name
- name: Get tag name
shell: bash
run: |
echo ${{ github.ref }}
echo "BRANCH_NAME=$(echo ${GITHUB_REF##*/} | tr / -)" >> $GITHUB_ENV
echo "TAG_NAME=$(echo ${GITHUB_REF##*/} | tr / -)" >> $GITHUB_ENV
cat $GITHUB_ENV
- uses: actions/checkout@v2
name: Check out gh-pages branch (full history)
with:
ref: gh-pages
fetch-depth: 0
# - name: Check that tag is release
# run: test "v${{ steps.get_version.outputs.VERSION }}" == "${{ env.TAG_NAME }}"

- uses: actions/download-artifact@v2
name: Download qalgebra-docs artifact
with:
name: qalgebra-docs
path: _qalgebra_docs

- name: Unzip html documentation
working-directory: _qalgebra_docs
shell: bash
- name: Check for html (zip) artifact
id: zip_artifact_file
run: |
unzip *.zip -d _unzip
mv _unzip/* _unzip/${{ env.BRANCH_NAME }}
echo ::set-output name=hello::$(python -c 'print("HELLO WORLD")') # DEBUG
echo ::set-output name=full::$(bash -c 'ls -R .') # DEBUG
echo ::set-output name=allfiles::$(ls _qalgebra_docs/*) # DEBUG
echo ::set-output name=filename::$(ls _qalgebra_docs/*.zip | head -n1)
echo ::set-output name=basename::$(basename "`ls _qalgebra_docs/*.zip | head -n1`")
- name: Rsync html documentation into place
run: rsync -av --delete _qalgebra_docs/_unzip/${{ env.BRANCH_NAME }}/ ./${{ env.BRANCH_NAME }}/
- name: Check for pdf artifact
id: pdf_artifact_file
run: |
echo ::set-output name=filename::$(ls _qalgebra_docs/*.pdf | head -n1)
echo ::set-output name=basename::basename "$(ls _qalgebra_docs/*.pdf | head -n1)"
- name: Remove artifact files
shell: bash
run: rm -rf _qalgebra_docs
- name: Check for epub artifact
id: epub_artifact_file
run: |
echo ::set-output name=filename::$(ls _qalgebra_docs/*.epub | head -n1)
echo ::set-output name=basename::basename "$(ls _qalgebra_docs/*.epub | head -n1)"
- name: Run doctr-versions-menu
run: doctr-versions-menu
- name: Check zip file (DEBUG)
if: ${{ steps.zip_artifact_file.filename }} != ""
run: |
echo "${{ steps.zip_artifact_file.hello }}"
echo "${{ steps.zip_artifact_file.full }}"
echo "${{ steps.zip_artifact_file.allfiles }}"
echo "${{ steps.zip_artifact_file.filename }}"
echo "${{ steps.zip_artifact_file.basename }}"
- name: Get the previous commit message
id: get_previous_commit
- name: Check epub file (DEBUG)
if: ${{ steps.epub_artifact_file.filename }} != ""
run: |
git log --format=%B -n 1 | tee .git/_github_actions_commit_msg
echo ::set-output name=LOG::$(cat .git/_github_actions_commit_msg)
echo ::set-output name=AUTHOR::$(git log --format=%an -n 1)
echo "${{ steps.epub_artifact_file.filename }}"
echo "${{ steps.epub_artifact_file.basename }}"
test "v${{ steps.get_version.outputs.VERSION }}" == "${{ env.TAG_NAME }}"
- name: Set git configuration
shell: bash
- name: Get Release Notes
run: git tag -l --format='%(contents:body)' v${{ steps.get_version.outputs.VERSION }} | tee .RELEASE_NOTES.md

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.TAG_NAME}}
release_name: Release ${{ steps.get_version.outputs.VERSION }}
body_path: .RELEASE_NOTES.md
draft: false
prerelease: false

- name: Upload html (zip) asset
id: upload-release-asset-zip
if: ${{ steps.zip_artifact_file.filename }} != ""
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.zip_artifact_file.filename }}
asset_name: ${{ steps.zip_artifact_file.basename }}
asset_content_type: application/zip

- name: Add html asset to _downloads file
if: ${{ steps.zip_artifact_file.filename }} != ""
run: |
git config user.name github-actions
git config user.email github-actions@github.com
echo "[html]: ${{ steps.upload-release-asset-zip.outputs.browser_download_url }}" >> _downloads
- name: Commit changes
shell: bash
- name: Upload pdf asset
id: upload-release-asset-pdf
if: ${{ steps.pdf_artifact_file.filename }} != ""
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.pdf_artifact_file.filename }}
asset_name: ${{ steps.pdf_artifact_file.basename }}
asset_content_type: application/pdf

- name: Add pdf asset to _downloads file
if: ${{ steps.pdf_artifact_file.filename }} != ""
run: |
echo "Committing to gh-pages"
echo "[previous commit msg: ${{ steps.get_previous_commit.outputs.LOG }}]"
echo "[previous commit author: ${{ steps.get_previous_commit.outputs.AUTHOR }}]"
echo "# GIT ADD"
git add -A --verbose
echo "# GIT STATUS"
git status
echo "# GIT COMMIT"
if [[ "${{ steps.get_previous_commit.outputs.AUTHOR }}" == "github-actions"* ]];
then
echo "Amending previous commit"
echo "Deployed from commit ${GITHUB_SHA} (${GITHUB_REF})" >> .git/_github_actions_commit_msg
git commit --verbose --amend -F .git/_github_actions_commit_msg
else
echo "Making new commit"
git commit --verbose -m "Auto-update from Github Actions Workflow" -m "Deployed from commit ${GITHUB_SHA} (${GITHUB_REF})"
fi
git log -n 1
- name: Push changes
run: git push --verbose --force
echo "[pdf]: ${{ steps.upload-release-asset-pdf.outputs.browser_download_url }}" >> _downloads
- name: Upload epub asset
id: upload-release-asset-epub
if: ${{ steps.epub_artifact_file.filename }} != ""
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.epub_artifact_file.filename }}
asset_name: ${{ steps.epub_artifact_file.basename }}
asset_content_type: application/epub+zip

- name: Add epub asset to _downloads file
if: ${{ steps.epub_artifact_file.filename }} != ""
run: |
echo "[epub]: ${{ steps.upload-release-asset-epub.outputs.browser_download_url }}" >> _downloads
- uses: actions/upload-artifact@v2
name: Create _downloads artifact
with:
name: _downloads
path: |
_downloads
# deploy_gh_pages:
# name: Deploy documentation to gh-pages
# if: always() && needs.build_docs.result == 'success' && (github.ref == 'refs/heads/releases' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))
# runs-on: ubuntu-18.04
# needs: [build_docs, create_github_release]
# steps:
#
# - uses: actions/setup-python@v2
# name: Install Python 3.8
# with:
# python-version: 3.8
#
# - name: Install deploy requirements
# run: pip install git+https://github.com/goerz/doctr_versions_menu.git@master#egg=doctr_versions_menu
#
# - name: Get branch name
# shell: bash
# run: |
# echo ${{ github.ref }}
# echo "BRANCH_NAME=$(echo ${GITHUB_REF##*/} | tr / -)" >> $GITHUB_ENV
# cat $GITHUB_ENV
#
# - uses: actions/checkout@v2
# name: Check out gh-pages branch (full history)
# with:
# ref: gh-pages
# fetch-depth: 0
#
# - uses: actions/download-artifact@v2
# name: Download qalgebra-docs artifact
# with:
# name: qalgebra-docs
# path: _qalgebra_docs
#
# - name: Unzip html documentation
# working-directory: _qalgebra_docs
# shell: bash
# run: |
# unzip *.zip -d _unzip
# mv _unzip/* _unzip/${{ env.BRANCH_NAME }}
#
# - name: Rsync html documentation into place
# run: rsync -av --delete _qalgebra_docs/_unzip/${{ env.BRANCH_NAME }}/ ./${{ env.BRANCH_NAME }}/
#
# - name: Remove artifact files
# shell: bash
# run: rm -rf _qalgebra_docs
#
# - name: Run doctr-versions-menu
# run: doctr-versions-menu
#
# - name: Get the previous commit message
# id: get_previous_commit
# run: |
# git log --format=%B -n 1 | tee .git/_github_actions_commit_msg
# echo ::set-output name=LOG::$(cat .git/_github_actions_commit_msg)
# echo ::set-output name=AUTHOR::$(git log --format=%an -n 1)
#
# - name: Set git configuration
# shell: bash
# run: |
# git config user.name github-actions
# git config user.email github-actions@github.com
#
# - name: Commit changes
# shell: bash
# run: |
# echo "Committing to gh-pages"
# echo "[previous commit msg: ${{ steps.get_previous_commit.outputs.LOG }}]"
# echo "[previous commit author: ${{ steps.get_previous_commit.outputs.AUTHOR }}]"
# echo "# GIT ADD"
# git add -A --verbose
# echo "# GIT STATUS"
# git status
# echo "# GIT COMMIT"
# if [[ "${{ steps.get_previous_commit.outputs.AUTHOR }}" == "github-actions"* ]];
# then
# echo "Amending previous commit"
# echo "Deployed from commit ${GITHUB_SHA} (${GITHUB_REF})" >> .git/_github_actions_commit_msg
# git commit --verbose --amend -F .git/_github_actions_commit_msg
# else
# echo "Making new commit"
# git commit --verbose -m "Auto-update from Github Actions Workflow" -m "Deployed from commit ${GITHUB_SHA} (${GITHUB_REF})"
# fi
# git log -n 1
#
# - name: Push changes
# run: git push --verbose --force

0 comments on commit dcbab8e

Please sign in to comment.