mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-30 03:03:09 +00:00
task: split jobs into reusable actions
This commit is contained in:
parent
d1a935c299
commit
9969a2f3aa
8 changed files with 234 additions and 134 deletions
14
.github/actions/build_site/action.yaml
vendored
Normal file
14
.github/actions/build_site/action.yaml
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
name: Build site
|
||||
description: Builds the Hugo exampleSite for later deploy on GitHub-Pages
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Setup Hugo
|
||||
uses: peaceiris/actions-hugo@v2
|
||||
with:
|
||||
hugo-version: 'latest'
|
||||
|
||||
- name: Build site
|
||||
shell: bash
|
||||
run: |
|
||||
hugo --minify --source ${GITHUB_WORKSPACE}/exampleSite --destination ${GITHUB_WORKSPACE}/../public --cleanDestinationDir --gc --baseURL https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/ --theme ${GITHUB_WORKSPACE}
|
73
.github/actions/check_milestone/action.yaml
vendored
Normal file
73
.github/actions/check_milestone/action.yaml
vendored
Normal file
|
@ -0,0 +1,73 @@
|
|||
name: Check milestone
|
||||
description: Checks if the given milestone and its according tag are valid to be released
|
||||
inputs:
|
||||
milestone:
|
||||
description: Milestone for this release
|
||||
required: true
|
||||
github_token:
|
||||
description: Secret GitHub token
|
||||
required: true
|
||||
outputs:
|
||||
outcome:
|
||||
description: Result of the check, success or failure
|
||||
value: ${{ steps.outcome.outputs.outcome }}
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Get tag uniqueness
|
||||
id: unique_tag
|
||||
uses: mukunku/tag-exists-action@v1.0.0
|
||||
with:
|
||||
tag: ${{ env.MILESTONE }}
|
||||
env:
|
||||
MILESTONE: ${{ inputs.milestone }}
|
||||
GITHUB_TOKEN: ${{ inputs.github_token }}
|
||||
|
||||
- name: Get closed issues for milestone
|
||||
id: closed_issues
|
||||
uses: octokit/graphql-action@v2.x
|
||||
with:
|
||||
query: |
|
||||
query {
|
||||
search(first: 1, type: ISSUE, query: "user:${{ github.repository_owner }} repo:${{ github.event.repository.name }} milestone:${{ env.MILESTONE }} state:closed") {
|
||||
issueCount
|
||||
}
|
||||
}
|
||||
env:
|
||||
MILESTONE: ${{ inputs.milestone }}
|
||||
GITHUB_TOKEN: ${{ inputs.github_token }}
|
||||
|
||||
- name: Get open issues for milestone
|
||||
id: open_issues
|
||||
uses: octokit/graphql-action@v2.x
|
||||
with:
|
||||
query: |
|
||||
query {
|
||||
search(first: 1, type: ISSUE, query: "user:${{ github.repository_owner }} repo:${{ github.event.repository.name }} milestone:${{ env.MILESTONE }} state:open") {
|
||||
issueCount
|
||||
}
|
||||
}
|
||||
env:
|
||||
MILESTONE: ${{ inputs.milestone }}
|
||||
GITHUB_TOKEN: ${{ inputs.github_token }}
|
||||
|
||||
- name: Set outcome
|
||||
id: outcome
|
||||
shell: bash
|
||||
run: |
|
||||
if [ "${{ fromJSON(steps.closed_issues.outputs.data).search.issueCount > 0 && fromJSON(steps.open_issues.outputs.data).search.issueCount == 0 && steps.unique_tag.outputs.exists == 'false' }}" = "true" ]; then
|
||||
echo "::set-output name=outcome::success"
|
||||
else
|
||||
echo "::set-output name=outcome::failure"
|
||||
fi
|
||||
|
||||
- name: Log results and exit
|
||||
shell: bash
|
||||
run: |
|
||||
echo outcome : ${{ steps.outcome.outputs.outcome }}
|
||||
echo has unique tag : ${{ steps.unique_tag.outputs.exists == 'false' }}
|
||||
echo has closed issues: ${{ fromJSON(steps.closed_issues.outputs.data).search.issueCount > 0 }}
|
||||
echo has open issues : ${{ fromJSON(steps.open_issues.outputs.data).search.issueCount > 0 }}
|
||||
if [ "${{ steps.outcome.outputs.outcome }}" = "failure" ]; then
|
||||
exit 1
|
||||
fi
|
17
.github/actions/deploy_site/action.yaml
vendored
Normal file
17
.github/actions/deploy_site/action.yaml
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
name: Deploy site
|
||||
description: Deploys a built site on GitHub-Pages
|
||||
inputs:
|
||||
github_token:
|
||||
description: Secret GitHub token
|
||||
required: true
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Deploy site
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
github_token: ${{ env.GITHUB_TOKEN }}
|
||||
publish_dir: ${{ env.GITHUB_WORKSPACE }}/../public
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ inputs.github_token }}
|
||||
GITHUB_WORKSPACE: ${{ github.workspace }}
|
64
.github/actions/release_milestone/action.yaml
vendored
Normal file
64
.github/actions/release_milestone/action.yaml
vendored
Normal file
|
@ -0,0 +1,64 @@
|
|||
name: Release milestone
|
||||
description: Creates a release with changelog and tag out of a given milestone
|
||||
inputs:
|
||||
milestone:
|
||||
description: Milestone for this release
|
||||
required: true
|
||||
github_token:
|
||||
description: Secret GitHub token
|
||||
required: true
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Setup node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16'
|
||||
|
||||
- name: Close milestone
|
||||
uses: Akkjon/close-milestone@v2
|
||||
with:
|
||||
milestone_name: ${{ env.MILESTONE }}
|
||||
env:
|
||||
MILESTONE: ${{ inputs.milestone }}
|
||||
GITHUB_TOKEN: ${{ inputs.github_token }}
|
||||
|
||||
- name: Create provisionary tag
|
||||
shell: bash
|
||||
env:
|
||||
MILESTONE: ${{ inputs.milestone }}
|
||||
GITHUB_TOKEN: ${{ inputs.github_token }}
|
||||
run: |
|
||||
git config user.name "GitHub Actions Bot"
|
||||
git config user.email "<>"
|
||||
git tag --message "" "$MILESTONE"
|
||||
git push origin "$MILESTONE"
|
||||
|
||||
- name: Update changelog
|
||||
shell: bash
|
||||
env:
|
||||
MILESTONE: ${{ inputs.milestone }}
|
||||
GITHUB_TOKEN: ${{ inputs.github_token }}
|
||||
GREN_GITHUB_TOKEN: ${{ inputs.github_token }}
|
||||
run: |
|
||||
npx github-release-notes@0.17.1 changelog --generate --override --tags=all
|
||||
git add *
|
||||
git commit --message "Ship tag $MILESTONE"
|
||||
git push origin main
|
||||
|
||||
- name: Create final tag
|
||||
shell: bash
|
||||
env:
|
||||
MILESTONE: ${{ inputs.milestone }}
|
||||
GITHUB_TOKEN: ${{ inputs.github_token }}
|
||||
run: |
|
||||
git tag --force --message "" "$MILESTONE"
|
||||
git push --force origin "$MILESTONE"
|
||||
|
||||
- name: Publish release
|
||||
shell: bash
|
||||
env:
|
||||
MILESTONE: ${{ inputs.milestone }}
|
||||
GREN_GITHUB_TOKEN: ${{ inputs.github_token }}
|
||||
run: |
|
||||
npx github-release-notes@0.17.1 release --tags "$MILESTONE"
|
20
.github/workflows/build.yaml
vendored
Normal file
20
.github/workflows/build.yaml
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
name: Build
|
||||
|
||||
on:
|
||||
push: # Build on all pushes but only deploy for main branch
|
||||
pull_request: # Build on all PRs regardless what branch
|
||||
workflow_dispatch: # Allow this task to be manually started (you'll never know)
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
name: Run build
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name != 'push' || (github.event_name == 'push' && github.ref != 'refs/heads/main')
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: true # Fetch Hugo themes (true OR recursive)
|
||||
|
||||
- name: Build site
|
||||
uses: ./.github/actions/build_site
|
33
.github/workflows/cicd.yaml
vendored
33
.github/workflows/cicd.yaml
vendored
|
@ -1,33 +0,0 @@
|
|||
name: CI/CD
|
||||
|
||||
on:
|
||||
push: # Build on all pushes but only deploy for main branch
|
||||
pull_request: # Build on all PRs regardless what branch
|
||||
workflow_dispatch: # Allow this task to be manually started (you'll never know)
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
name: Run CI/CD
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: true # Fetch Hugo themes (true OR recursive)
|
||||
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
|
||||
|
||||
- name: Setup Hugo
|
||||
uses: peaceiris/actions-hugo@v2
|
||||
with:
|
||||
hugo-version: 'latest'
|
||||
# extended: true
|
||||
|
||||
- name: Build site
|
||||
run: hugo --minify --source exampleSite --destination ../public --cleanDestinationDir --gc --baseURL https://mcshelby.github.io/hugo-theme-relearn/
|
||||
|
||||
- name: Deploy site
|
||||
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./public
|
25
.github/workflows/deploy.yaml
vendored
Normal file
25
.github/workflows/deploy.yaml
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
name: Deploy
|
||||
|
||||
on:
|
||||
push: # Build on all pushes but only deploy for main branch
|
||||
workflow_dispatch: # Allow this task to be manually started (you'll never know)
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
name: Run deploy
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name != 'push' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: true # Fetch Hugo themes (true OR recursive)
|
||||
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
|
||||
|
||||
- name: Build site
|
||||
uses: ./.github/actions/build_site
|
||||
|
||||
- name: Deploy site
|
||||
uses: ./.github/actions/deploy_site
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
122
.github/workflows/release.yaml
vendored
122
.github/workflows/release.yaml
vendored
|
@ -8,115 +8,35 @@ on:
|
|||
required: true
|
||||
|
||||
jobs:
|
||||
release_state:
|
||||
name: Get tag and milestone state
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
MILESTONE: ${{ github.event.inputs.milestone }} # To avoid code injection
|
||||
outputs:
|
||||
has_closed_issues: ${{ fromJSON(steps.closed_issues.outputs.data).search.issueCount > 0 }}
|
||||
has_open_issues: ${{ fromJSON(steps.open_issues.outputs.data).search.issueCount > 0 }}
|
||||
has_unique_tag: ${{ steps.unique_tag.outcome == 'failure' }}
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Get closed issues for milestone
|
||||
id: closed_issues
|
||||
uses: octokit/graphql-action@v2.x
|
||||
with:
|
||||
query: |
|
||||
query {
|
||||
search(first: 1, type: ISSUE, query: "user:${{ github.repository_owner }} repo:${{ github.event.repository.name }} milestone:${{ env.MILESTONE }} state:closed") {
|
||||
issueCount
|
||||
}
|
||||
}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Get open issues for milestone
|
||||
id: open_issues
|
||||
uses: octokit/graphql-action@v2.x
|
||||
with:
|
||||
query: |
|
||||
query {
|
||||
search(first: 1, type: ISSUE, query: "user:${{ github.repository_owner }} repo:${{ github.event.repository.name }} milestone:${{ env.MILESTONE }} state:open") {
|
||||
issueCount
|
||||
}
|
||||
}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Get tag uniqueness
|
||||
id: unique_tag
|
||||
continue-on-error: true
|
||||
run: git rev-parse "$MILESTONE" --
|
||||
|
||||
release_log:
|
||||
name: Log tag and milestone state
|
||||
needs: release_state
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
MILESTONE: ${{ github.event.inputs.milestone }} # To avoid code injection
|
||||
steps:
|
||||
- run: "echo has unique tag : ${{ needs.release_state.outputs.has_unique_tag }}"
|
||||
- run: "echo has closed issues: ${{ needs.release_state.outputs.has_closed_issues }}"
|
||||
- run: "echo has open issues : ${{ needs.release_state.outputs.has_open_issues }}"
|
||||
|
||||
release:
|
||||
name: Create release
|
||||
needs: release_state
|
||||
if: needs.release_state.outputs.has_closed_issues == 'true' && needs.release_state.outputs.has_open_issues == 'false' && needs.release_state.outputs.has_unique_tag == 'true'
|
||||
name: Run release
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
MILESTONE: ${{ github.event.inputs.milestone }} # To avoid code injection
|
||||
GREN_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16'
|
||||
submodules: true # Fetch Hugo themes (true OR recursive)
|
||||
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
|
||||
|
||||
- name: Setup git env
|
||||
run: |
|
||||
git config user.name "GitHub Actions Bot"
|
||||
git config user.email "<>"
|
||||
|
||||
- name: Close milestone
|
||||
uses: Akkjon/close-milestone@v2
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Check milestone
|
||||
id: check
|
||||
uses: ./.github/actions/check_milestone
|
||||
with:
|
||||
milestone_name: ${{ env.MILESTONE }}
|
||||
milestone: ${{ github.event.inputs.milestone }}
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Create provisionary tag
|
||||
run: git tag --message "" "$MILESTONE"
|
||||
- name: Create release
|
||||
if: ${{ steps.check.outputs.outcome == 'success' }}
|
||||
uses: ./.github/actions/release_milestone
|
||||
with:
|
||||
milestone: ${{ github.event.inputs.milestone }}
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Push provisionary tag
|
||||
run: git push origin "$MILESTONE"
|
||||
# We need to deploy the site again to show the updated changelog
|
||||
- name: Build site
|
||||
uses: ./.github/actions/build_site
|
||||
|
||||
- name: Update changelog
|
||||
run: npx github-release-notes@0.17.1 changelog --generate --override --tags=all
|
||||
|
||||
- name: Stage changelog
|
||||
run: git add *
|
||||
|
||||
- name: Commit changelog
|
||||
run: git commit --message "Ship tag $MILESTONE"
|
||||
|
||||
- name: Push changelog
|
||||
run: git push origin main
|
||||
|
||||
- name: Create final tag
|
||||
run: git tag --force --message "" "$MILESTONE"
|
||||
|
||||
- name: Push final tag
|
||||
run: git push --force origin "$MILESTONE"
|
||||
|
||||
- name: Publish release
|
||||
run: npx github-release-notes@0.17.1 release --tags "$MILESTONE"
|
||||
- name: Deploy site
|
||||
uses: ./.github/actions/deploy_site
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
|
Loading…
Reference in a new issue