Merge pull request #290 from owaspsamm/sud-fixes-2 #188
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: github pages | |
on: | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- .github/workflows/*.yml | |
- .github/workflows/*.yaml | |
repository_dispatch: | |
types: [samm-core-released] | |
workflow_dispatch: | |
env: | |
hugo_version: '0.81.0' | |
jobs: | |
updateHugoMod: | |
runs-on: ubuntu-latest | |
outputs: | |
goMod: ${{ steps.modFiles.outputs.goMod }} | |
goSum: ${{ steps.modFiles.outputs.goSum }} | |
steps: | |
- name: Parse semver string | |
if: github.event_name == 'repository_dispatch' | |
id: semver_parser | |
uses: booxmedialtd/ws-action-parse-semver@v1 | |
with: | |
input_string: ${{ github.event.client_payload.release }} | |
version_extractor_regex: 'v(.*)$' | |
- name: Check release semver sanity | |
if: github.event_name == 'repository_dispatch' | |
env: | |
RELEASE: "v${{ steps.semver_parser.outputs.fullversion }}" | |
run: | | |
if [ "${RELEASE}" = "v" ]; then | |
echo "::error title={Bad Semver}::{Release version is not semver compatible}" | |
exit 1 | |
fi | |
- uses: actions/checkout@v3 | |
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: ${{ env.hugo_version }} | |
extended: true | |
- name: Get new release and commit to main | |
if: github.event_name == 'repository_dispatch' | |
env: | |
RELEASE: "v${{ steps.semver_parser.outputs.fullversion }}" | |
run: | | |
echo "We got a new SAMM release: v${{ steps.semver_parser.outputs.fullversion }}${RELEASE}" | |
hugo mod get "github.com/owaspsamm/core@markdown/${RELEASE}" | |
cat go.mod | |
- name: Get translations | |
run: | | |
hugo mod get "github.com/owaspsamm/i18n-FR@markdown" | |
- name: Passing hugo mod files | |
id: modFiles | |
run: | | |
{ | |
echo 'goMod<<EOF' | |
cat go.mod | |
echo EOF | |
} >> "$GITHUB_OUTPUT" | |
{ | |
echo 'goSum<<EOF' | |
cat go.sum | |
echo EOF | |
} >> "$GITHUB_OUTPUT" | |
- name: Set commit message | |
run: | | |
if [ -z "${{ github.event.client_payload.release }}" ]; then | |
echo "COMMIT_MESSAGE='Updated translations'" >> $GITHUB_ENV | |
else | |
echo "COMMIT_MESSAGE='New SAMM release: ${{ github.event.client_payload.release }}'" >> $GITHUB_ENV | |
fi | |
- name: Commit updated files to git | |
uses: EndBug/add-and-commit@v9 | |
with: | |
add: '["go.mod", "go.sum"]' | |
default_author: github_actions | |
message: "${{ env.COMMIT_MESSAGE }}" | |
deploy: | |
runs-on: ubuntu-latest | |
needs: updateHugoMod | |
if: ${{ always() && (needs.updateHugoMod.result == 'success' || needs.updateHugoMod.result == 'skipped') }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
submodules: true # Fetch Hugo themes (true OR recursive) | |
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmodd | |
- name: Get hugo mod files | |
if: ${{ needs.updateHugoMod.result == 'success' }} | |
run: | | |
echo "${{needs.updateHugoMod.outputs.goMod}}" > go.mod | |
echo "${{needs.updateHugoMod.outputs.goSum}}" > go.sum | |
- uses: actions/cache@v3 | |
with: | |
path: /tmp/hugo_cache | |
key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
${{ runner.os }}-hugomod- | |
- name: Setup Hugo | |
uses: peaceiris/actions-hugo@v2 | |
with: | |
hugo-version: ${{ env.hugo_version }} | |
extended: true | |
- name: Build | |
run: hugo --gc --minify -v --cleanDestinationDir --environment production | |
- name: Deploy | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./public |