Skip to content

Commit

Permalink
github: make deployment more generic
Browse files Browse the repository at this point in the history
Add a small tool to generate the matrix for building all versions of the
app.
  • Loading branch information
jnikula committed Mar 17, 2024
1 parent e59e969 commit 31c2a15
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 18 deletions.
34 changes: 34 additions & 0 deletions .github/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python3

import argparse
import json
import subprocess

def git_tags():
cmd = ['git', 'tag', '--list', '--sort=version:refname']

return subprocess.run(cmd, text=True, stdout=subprocess.PIPE).stdout.strip().splitlines()


def main():
parser = argparse.ArgumentParser()
parser.add_argument('--latest', action='store_true')
args = parser.parse_args()

tags = git_tags()

if args.latest:
print(tags[-1])
return

tags = [ { 'ref': tag, 'name': tag } for tag in tags ]
tags += [ { 'ref': 'main', 'name': 'testing' } ]

matrix = {
'include': tags,
}

print(json.dumps(matrix))

if __name__ == '__main__':
main()
42 changes: 24 additions & 18 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ on:
branches:
- main
jobs:
configure:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.version-matrix.outputs.matrix }}
latest: ${{ steps.latest.outputs.latest }}
steps:
- uses: actions/checkout@v3
- run: git fetch --tags origin
- id: version-matrix
run: echo "matrix=$(.github/config.py)" | tee $GITHUB_OUTPUT
- id: latest
run: echo "latest=$(.github/config.py --latest)" | tee $GITHUB_OUTPUT

build-docs:
runs-on: ubuntu-latest
steps:
Expand All @@ -18,13 +31,9 @@ jobs:

build-app:
runs-on: ubuntu-latest
needs: configure
strategy:
matrix:
include:
- ref: main
name: app-testing
- ref: v0.1.0
name: app-stable
matrix: ${{ fromJson(needs.configure.outputs.matrix) }}
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -42,7 +51,7 @@ jobs:

deploy:
runs-on: ubuntu-latest
needs: [build-docs, build-app]
needs: [configure, build-docs, build-app]
permissions:
pages: write
id-token: write
Expand All @@ -51,17 +60,14 @@ jobs:
url: ${{steps.deployment.outputs.page_url}}
steps:
- uses: actions/download-artifact@v4
with:
name: app-testing
path: testing
- uses: actions/download-artifact@v4
with:
name: app-stable
path: stable
- uses: actions/download-artifact@v4
with:
name: docs-artifact
path: .
- run: find
- run: mv docs-artifact/* .
- run: |
latest=${{ needs.configure.outputs.latest }}
echo "<meta http-equiv=\"refresh\" content=\"0; url=$latest\" />" > latest.html
- run: |
mkdir stable
echo "<meta http-equiv=\"refresh\" content=\"0; url=../v0.1.0\" />" > stable/index.html
- run: find
- uses: actions/configure-pages@v1
- uses: actions/upload-pages-artifact@v1
Expand Down

0 comments on commit 31c2a15

Please sign in to comment.