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 e325f80
Showing 1 changed file with 187 additions and 65 deletions.
252 changes: 187 additions & 65 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ jobs:
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

Expand All @@ -67,95 +60,224 @@ jobs:
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: 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=filepath::$(ls _qalgebra_docs/*.zip | head -n1)
echo ::set-output name=basename::$(ls _qalgebra_docs/*.zip | head -n1 | xargs basename)
- 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=filepath::$(ls _qalgebra_docs/*.pdf | head -n1)
echo ::set-output name=basename::$(ls _qalgebra_docs/*.pdf | head -n1 | xargs basename)
- 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=filepath::$(ls _qalgebra_docs/*.epub | head -n1)
echo ::set-output name=basename::$(ls _qalgebra_docs/*.pepub | head -n1 | xargs basename)
- name: Run doctr-versions-menu
run: doctr-versions-menu
- name: Get Release Notes
run: git tag -l --format='%(contents:body)' ${{ env.TAG_NAME}} | tee .RELEASE_NOTES.md

- name: Get the previous commit message
id: get_previous_commit
- 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.outputs.filepath != '' }}
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.outputs.filepath }}
asset_name: ${{ steps.zip_artifact_file.outputs.basename }}
asset_content_type: application/zip

- name: Add html asset to _downloads file
if: ${{ steps.zip_artifact_file.outputs.filepath != '' }}
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 "[html]: ${{ steps.upload-release-asset-zip.outputs.browser_download_url }}" >> _downloads
- name: Set git configuration
shell: bash
- name: Upload pdf asset
id: upload-release-asset-pdf
if: ${{ steps.pdf_artifact_file.outputs.filepath != '' }}
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.outputs.filepath }}
asset_name: ${{ steps.pdf_artifact_file.outputs.basename }}
asset_content_type: application/pdf

- name: Add pdf asset to _downloads file
if: ${{ steps.pdf_artifact_file.outputs.filepath != '' }}
run: |
git config user.name github-actions
git config user.email github-actions@github.com
echo "[pdf]: ${{ steps.upload-release-asset-pdf.outputs.browser_download_url }}" >> _downloads
- name: Commit changes
shell: bash
- name: Upload epub asset
id: upload-release-asset-epub
if: ${{ steps.epub_artifact_file.outputs.filepath != '' }}
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.outputs.filepath }}
asset_name: ${{ steps.epub_artifact_file.outputs.basename }}
asset_content_type: application/epub+zip

- name: Add epub asset to _downloads file
if: ${{ steps.epub_artifact_file.outputs.filepath != '' }}
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 "[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 e325f80

Please sign in to comment.