You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-dev@db.apache.org by to...@apache.org on 2021/01/28 19:28:38 UTC

[db-jdo-site] 03/03: Add recovery workflow to recreate the site branch

This is an automated email from the ASF dual-hosted git repository.

tobous pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/db-jdo-site.git

commit 744aa969ace551e05fce9e6fc84c09572dfff2b0
Author: Tobias Bouschen <to...@googlemail.com>
AuthorDate: Sat Jan 23 01:06:16 2021 +0100

    Add recovery workflow to recreate the site branch
    
    Adds a workflow to recreate the site branch in case it ever gets deleted
    on accident or becomes corrupted.
    
    The new workflow to automatically deploy the site relies on there being
    a functioning site branch. This workflow offers an recovery option to
    recreate a stable version of the site branch with which the deploy
    workflow can function.
    
    The workflow does not listen for any events on the repository. It can
    only be triggered manually. To do so, go to the "Actions" section of the
    GitHub page for the repository and select the action from the menu. At
    the top of the list of past workflow runs is a blue bar offering the
    option to "Run workflow". Select the option and press the green button
    "Run workflow".
    
    When running the workflow, the default selection to run it on the master
    branch should not be changed. Even though the workflow is explicitly
    configured to check out the master branch, running the action on a
    different branch might still have other unintended side effects.
---
 .github/workflows/recreate-site-branch.yml | 89 ++++++++++++++++++++++++++++++
 1 file changed, 89 insertions(+)

diff --git a/.github/workflows/recreate-site-branch.yml b/.github/workflows/recreate-site-branch.yml
new file mode 100644
index 0000000..6b22b25
--- /dev/null
+++ b/.github/workflows/recreate-site-branch.yml
@@ -0,0 +1,89 @@
+# Recreates the orphan site branch
+#
+# This workflow is set up as a fallback in cases where the site branch has been deleted
+# The workflow to automatically publish the site after a push to the master relies on there already being a functioning site branch
+# This will not cause the website to be published; another push to the site branch (e.g. thought the deploy workflow) is necessary for this
+name: Recreate Site Branch - ONLY USE IF SITE BRANCH GOT DELETED
+
+# Conditions necessary to trigger a build
+#
+# Can only be triggered manually
+on:
+  workflow_dispatch:
+
+
+jobs:
+  build:
+    name: Build & Deploy Site
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+        with:
+          ref: master
+          fetch-depth: 1
+
+
+      - name: Build Site
+        run: mvn clean compile
+
+
+      # Determines the short sha of the commit that triggered the build
+      - name: Determine Short SHA
+        if: success()
+        id: short-sha
+        run: |
+          short_sha=$(git rev-parse --short=10 $GITHUB_SHA)
+          echo "::set-output name=short_sha::$short_sha"
+        shell: 'bash'
+
+
+      # Determines the author data of the HEAD commit
+      # Sets up the author data to be used for the site deploy commit
+      - name: Determine HEAD Commit Author Data
+        if: success()
+        id: author-data
+        run: |
+          echo "Reading author data"
+          author_name=$(git log -1 --format='%aN' HEAD)
+          author_email=$(git log -1 --format='%aE' HEAD)
+
+          echo "Setting up author data to use for deploy commit"
+          git config user.name $author_name
+          git config user.email $author_email
+        shell: 'bash'
+
+
+      # Publishes the site build results to a separate orphan branch
+      #
+      # Creates and checks out a new orphan branch
+      # Creates a single commit containing only the site build artifacts and site configuration files located in the root directory
+      # The commit is created with the author data set up in the previous step
+      # Force-pushes the created branch, overwriting the previously published site build
+      - name: Publish site branch
+        if: success()
+        run: |
+          branch_name="publish"
+
+          echo "Creating orphan branch"
+          git checkout --orphan $branch_name
+          echo
+
+          echo "Dropping content other than site data"
+          git reset
+          rm .gitignore
+          git add target/site
+          git add .asf.yaml.publish .htaccess
+          git clean -df
+          mkdir -v content
+          git mv target/site/* content/
+          git mv .asf.yaml.publish .asf.yaml
+          echo
+
+          echo "Committing changes"
+          git commit -m "Auto-deploy site for commit ${{ steps.short-sha.outputs.short_sha }}"
+          echo
+
+          echo "Pushing site branch"
+          git push -f origin $branch_name
+        shell: 'bash'