From 7653f03ace3f5bbf0259a3033267dfb9fe73d665 Mon Sep 17 00:00:00 2001 From: Jeremy McCormick Date: Fri, 17 May 2024 16:56:40 -0500 Subject: [PATCH 1/4] Upload the branch version of the website for pull requests Also change the main upload action to only execute when the action is not triggered by a PR. --- .github/workflows/deploy_version.yaml | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/deploy_version.yaml diff --git a/.github/workflows/deploy_version.yaml b/.github/workflows/deploy_version.yaml new file mode 100644 index 0000000..1619c38 --- /dev/null +++ b/.github/workflows/deploy_version.yaml @@ -0,0 +1,39 @@ +name: "Deploy a branch version of the website" + +on: + pull_request: + +env: + HUGO_VERSION: 0.123.4 + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Extract branch name + shell: bash + run: echo "BRANCH_NAME=$(echo ${{ github.head_ref }} | sed 's/\//-/g')" >> $GITHUB_ENV + + - name: Debug print branch name + shell: bash + run: echo "BRANCH_NAME=${{ env.BRANCH_NAME }}" + + - name: Download hugo + run: | + wget https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_Linux-64bit.tar.gz + tar -zxvf hugo_${HUGO_VERSION}_Linux-64bit.tar.gz hugo + + - name: Build the website + run: ./hugo -b https://webtest.ivoa.info/v/${{ env.BRANCH_NAME }} + + - name: Upload the branch version of the website + uses: Dylan700/sftp-upload-action@latest + with: + username: webstage + server: web.ivoa.net + key: ${{ secrets.STAGE_ID }} + uploads: | + ./public/ => ./ivoa-web-stage/v/${{ env.BRANCH_NAME }} From a80a7718b17d79c399dcda6ee9332493ae9670ab Mon Sep 17 00:00:00 2001 From: Jeremy McCormick Date: Sun, 19 May 2024 12:08:22 +1000 Subject: [PATCH 2/4] Rename main workflow and remove unnecessary dry-run config --- .../workflows/{build_and_deploy.yaml => deploy_main.yaml} | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) rename .github/workflows/{build_and_deploy.yaml => deploy_main.yaml} (77%) diff --git a/.github/workflows/build_and_deploy.yaml b/.github/workflows/deploy_main.yaml similarity index 77% rename from .github/workflows/build_and_deploy.yaml rename to .github/workflows/deploy_main.yaml index 4903bf0..f9adec1 100644 --- a/.github/workflows/build_and_deploy.yaml +++ b/.github/workflows/deploy_main.yaml @@ -1,8 +1,7 @@ -name: "Build and deploy the website" +name: "Deploy the main version of the website" on: workflow_dispatch: - pull_request: push: branches: - main @@ -25,15 +24,11 @@ jobs: - name: Build the website run: ./hugo - - name: Set dry run - run: echo "DRY_RUN=${{ github.event_name == 'pull_request' && 'true' || 'false' }}" >> $GITHUB_ENV - - name: Deploy the website uses: Dylan700/sftp-upload-action@latest with: username: webstage server: web.ivoa.net - dry-run: ${{ env.DRY_RUN }} key: ${{ secrets.STAGE_ID }} uploads: | ./public/ => ./ivoa-web-stage/ From 468120b308eb064196de7285c3b45789cd98b120 Mon Sep 17 00:00:00 2001 From: Jeremy McCormick Date: Sun, 19 May 2024 12:15:31 +1000 Subject: [PATCH 3/4] Rename 'build' jobs to 'deploy' --- .github/workflows/deploy_main.yaml | 2 +- .github/workflows/deploy_version.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy_main.yaml b/.github/workflows/deploy_main.yaml index f9adec1..a088a4a 100644 --- a/.github/workflows/deploy_main.yaml +++ b/.github/workflows/deploy_main.yaml @@ -10,7 +10,7 @@ env: HUGO_VERSION: 0.123.4 jobs: - build: + deploy: runs-on: ubuntu-latest steps: - name: Checkout repository diff --git a/.github/workflows/deploy_version.yaml b/.github/workflows/deploy_version.yaml index 1619c38..9fd69df 100644 --- a/.github/workflows/deploy_version.yaml +++ b/.github/workflows/deploy_version.yaml @@ -7,7 +7,7 @@ env: HUGO_VERSION: 0.123.4 jobs: - build: + deploy: runs-on: ubuntu-latest steps: - name: Checkout repository From ebe44274248941379a4e60a0d968d935764784e0 Mon Sep 17 00:00:00 2001 From: Jeremy McCormick Date: Sun, 19 May 2024 12:27:17 +1000 Subject: [PATCH 4/4] Use an action to download and cache hugo --- .github/actions/setup-hugo/action.yaml | 23 +++++++++++++++++++++++ .github/workflows/deploy_main.yaml | 11 +++-------- .github/workflows/deploy_version.yaml | 11 +++-------- 3 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 .github/actions/setup-hugo/action.yaml diff --git a/.github/actions/setup-hugo/action.yaml b/.github/actions/setup-hugo/action.yaml new file mode 100644 index 0000000..a98e3ae --- /dev/null +++ b/.github/actions/setup-hugo/action.yaml @@ -0,0 +1,23 @@ +name: 'Download and extract Hugo' +description: 'Downloads and extracts a specified version of Hugo' +inputs: + hugo_version: + description: 'Version of Hugo to download' + required: false + default: '0.123.4' +runs: + using: 'composite' + steps: + - name: Cache Hugo + uses: actions/cache@v2 + with: + path: ~/hugo + key: ${{ runner.os }}-hugo-${{ inputs.hugo_version }} + - name: Download and extract Hugo + run: | + if [ ! -f ~/hugo ]; then + wget https://github.com/gohugoio/hugo/releases/download/v${{ inputs.hugo_version }}/hugo_${{ inputs.hugo_version }}_Linux-64bit.tar.gz + tar -zxvf hugo_${{ inputs.hugo_version }}_Linux-64bit.tar.gz + mv hugo ~/hugo + fi + shell: bash \ No newline at end of file diff --git a/.github/workflows/deploy_main.yaml b/.github/workflows/deploy_main.yaml index a088a4a..577a52e 100644 --- a/.github/workflows/deploy_main.yaml +++ b/.github/workflows/deploy_main.yaml @@ -6,9 +6,6 @@ on: branches: - main -env: - HUGO_VERSION: 0.123.4 - jobs: deploy: runs-on: ubuntu-latest @@ -16,13 +13,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - - name: Download hugo - run: | - wget https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_Linux-64bit.tar.gz - tar -zxvf hugo_${HUGO_VERSION}_Linux-64bit.tar.gz hugo + - name: Setup Hugo + uses: ./.github/actions/setup-hugo - name: Build the website - run: ./hugo + run: ~/hugo - name: Deploy the website uses: Dylan700/sftp-upload-action@latest diff --git a/.github/workflows/deploy_version.yaml b/.github/workflows/deploy_version.yaml index 9fd69df..9940346 100644 --- a/.github/workflows/deploy_version.yaml +++ b/.github/workflows/deploy_version.yaml @@ -3,9 +3,6 @@ name: "Deploy a branch version of the website" on: pull_request: -env: - HUGO_VERSION: 0.123.4 - jobs: deploy: runs-on: ubuntu-latest @@ -21,13 +18,11 @@ jobs: shell: bash run: echo "BRANCH_NAME=${{ env.BRANCH_NAME }}" - - name: Download hugo - run: | - wget https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_Linux-64bit.tar.gz - tar -zxvf hugo_${HUGO_VERSION}_Linux-64bit.tar.gz hugo + - name: Setup Hugo + uses: ./.github/actions/setup-hugo - name: Build the website - run: ./hugo -b https://webtest.ivoa.info/v/${{ env.BRANCH_NAME }} + run: ~/hugo -b https://webtest.ivoa.info/v/${{ env.BRANCH_NAME }} - name: Upload the branch version of the website uses: Dylan700/sftp-upload-action@latest