|
| 1 | +name: Deploy Workshop to GitHub Pages |
| 2 | + |
| 3 | +permissions: write-all |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + release_type: |
| 9 | + description: 'Type of version bump' |
| 10 | + required: true |
| 11 | + type: choice |
| 12 | + options: |
| 13 | + - minor |
| 14 | + - major |
| 15 | + default: minor |
| 16 | + |
| 17 | +jobs: |
| 18 | + deploy: |
| 19 | + name: Build and deploy workshop |
| 20 | + runs-on: ubuntu-24.04 |
| 21 | + steps: |
| 22 | + - name: Checkout sources |
| 23 | + uses: actions/checkout@v2 |
| 24 | + with: |
| 25 | + submodules: recursive |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: Setup Hugo |
| 29 | + uses: peaceiris/actions-hugo@v2 |
| 30 | + with: |
| 31 | + hugo-version: '0.145.0' |
| 32 | + extended: true |
| 33 | + |
| 34 | + - name: Setup yq |
| 35 | + uses: chrisdickinson/setup-yq@latest |
| 36 | + with: |
| 37 | + yq-version: '4.45.1' |
| 38 | + yq-url: 'https://github.com/mikefarah/yq/releases/download/v{version}/yq_{platform}_{arch}' |
| 39 | + |
| 40 | + - name: Set up Python 3.12 |
| 41 | + uses: actions/setup-python@v5 |
| 42 | + with: |
| 43 | + python-version: '3.12' |
| 44 | + cache: 'pip' |
| 45 | + |
| 46 | + - name: Install dependencies |
| 47 | + run: pip install -r requirements.txt |
| 48 | + |
| 49 | + - name: Cache go dependencies |
| 50 | + uses: actions/cache@v4 |
| 51 | + with: |
| 52 | + path: /tmp/hugo_cache |
| 53 | + key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }} |
| 54 | + restore-keys: | |
| 55 | + ${{ runner.os }}-hugomod- |
| 56 | +
|
| 57 | + - name: Bump version and create tag |
| 58 | + id: bumpversion |
| 59 | + run: | |
| 60 | + git config user.name "${GITHUB_ACTOR}" |
| 61 | + git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" |
| 62 | + git pull --rebase |
| 63 | +
|
| 64 | + TAG=$(bumpversion --list "${{ inputs.release_type }}" | awk -F= '/new_version=/ { print $2 }') |
| 65 | + echo "tag_name=${TAG}" >> $GITHUB_OUTPUT |
| 66 | +
|
| 67 | + BASE_URL="$(yq .baseURL hugo.yaml)" |
| 68 | + echo "base_url=${BASE_URL}" >> $GITHUB_OUTPUT |
| 69 | +
|
| 70 | + # Update README with new release link |
| 71 | + awk "/Latest versions of the workshop are:/ { print; print \"- [v${TAG}](https://splunk.github.io/observability-workshop/)\";next }1" README.md | |
| 72 | + awk "NR==1,/Latest versions of the workshop are:/{c=3} c&&c-- " > README.new.md |
| 73 | + mv README.new.md README.md |
| 74 | +
|
| 75 | + git fetch --tags origin |
| 76 | + git add README.md |
| 77 | + git commit --amend -m "Releasing v${TAG}" |
| 78 | + git tag -a "v${TAG}" -m "Version ${TAG}" |
| 79 | + git push --follow-tags origin main || { echo 'Push failed. git pull --rebase from upstream and attempt another release.'; exit 1; } |
| 80 | +
|
| 81 | + - name: Build Hugo site |
| 82 | + run: | |
| 83 | + hugo --minify --destination "public" --baseURL "${{ steps.bumpversion.outputs.base_url }}observability-workshop" --noChmod |
| 84 | +
|
| 85 | + - name: Deploy to GitHub Pages |
| 86 | + uses: peaceiris/actions-gh-pages@v3 |
| 87 | + with: |
| 88 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 89 | + publish_dir: ./public |
| 90 | + publish_branch: gh-pages |
| 91 | + force_orphan: false |
| 92 | + user_name: ${{ github.actor }} |
| 93 | + user_email: ${{ github.actor }}@users.noreply.github.com |
| 94 | + commit_message: "Deploy v${{ steps.bumpversion.outputs.tag_name }}" |
| 95 | + |
| 96 | + - name: Publish GitHub release |
| 97 | + uses: softprops/action-gh-release@v1 |
| 98 | + with: |
| 99 | + name: v${{ steps.bumpversion.outputs.tag_name }} |
| 100 | + tag_name: v${{ steps.bumpversion.outputs.tag_name }} |
0 commit comments