|
| 1 | +name: Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [chore/github-actions] # FIXME: main |
| 6 | + # branches: [main] |
| 7 | + schedule: |
| 8 | + - cron: "0 00,12 * * *" # Twice a day |
| 9 | + |
| 10 | +jobs: |
| 11 | + generate-matrix: |
| 12 | + name: Generate Job Matrix |
| 13 | + runs-on: ubuntu-latest |
| 14 | + needs: [test] |
| 15 | + outputs: |
| 16 | + matrix: ${{ steps.set-matrix.outputs.matrix }} |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v3 |
| 19 | + with: |
| 20 | + fetch-depth: 2 |
| 21 | + - uses: actions/setup-python@v4 |
| 22 | + with: |
| 23 | + python-version: "3.11" |
| 24 | + cache: pipenv |
| 25 | + - run: | |
| 26 | + pip install pipenv |
| 27 | + pipenv install --deploy --dev |
| 28 | + - run: | |
| 29 | + FORCE=$(if git log --pretty=format:"%s" HEAD^..HEAD | grep -q '\[force\]'; then echo "--force"; else echo ""; fi) |
| 30 | + pipenv run python -m build_versions.main --ci-matrix $FORCE --ci-event ${{ github.event_name }} |
| 31 | + id: set-matrix |
| 32 | +
|
| 33 | + deploy: |
| 34 | + name: ${{ matrix.key }} |
| 35 | + runs-on: ubuntu-latest |
| 36 | + if: needs.generate-matrix.outputs.matrix != '' |
| 37 | + needs: [generate-matrix] |
| 38 | + strategy: |
| 39 | + matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }} |
| 40 | + steps: |
| 41 | + - uses: actions/checkout@v3 |
| 42 | + - uses: actions/setup-python@v4 |
| 43 | + with: |
| 44 | + python-version: "3.11" |
| 45 | + cache: pipenv |
| 46 | + - run: | |
| 47 | + pip install pipenv |
| 48 | + pipenv install --deploy --dev |
| 49 | + - run: echo ${{ matrix.key }} |
| 50 | + - name: Generate Dockerfile from config |
| 51 | + run: pipenv run python -m build_versions.main --dockerfile-with-context '${{ toJSON(matrix) }}' |
| 52 | + - name: Set up QEMU |
| 53 | + uses: docker/setup-qemu-action@v2 |
| 54 | + - name: Set up Docker Buildx |
| 55 | + uses: docker/setup-buildx-action@v2 |
| 56 | + - name: Login to Docker Hub |
| 57 | + uses: docker/login-action@v2 |
| 58 | + with: |
| 59 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 60 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 61 | + - name: Build and push |
| 62 | + uses: docker/build-push-action@v4 |
| 63 | + with: |
| 64 | + context: . |
| 65 | + file: dockerfiles/${{ matrix.key }}.Dockerfile |
| 66 | + platforms: ${{ join(matrix.platforms) }} |
| 67 | + push: true |
| 68 | + tags: nikolaik/python-nodejs:${{ matrix.key }}-canary # FIXME: remove debug canary |
| 69 | + |
| 70 | + release: |
| 71 | + name: Update versions.json and README.md |
| 72 | + runs-on: ubuntu-latest |
| 73 | + needs: [deploy] |
| 74 | + steps: |
| 75 | + - uses: actions/checkout@v3 |
| 76 | + - uses: actions/setup-python@v4 |
| 77 | + with: |
| 78 | + python-version: "3.11" |
| 79 | + cache: pipenv |
| 80 | + - run: | |
| 81 | + pip install pipenv |
| 82 | + pipenv install --deploy --dev |
| 83 | + - name: Update versions.json and README.md, then commit and push changes (if any) |
| 84 | + run: | |
| 85 | + # FIXME: remove --dry-run |
| 86 | + pipenv run python -m build_versions.main --verbose --release --dry-run |
| 87 | + clean_checkout=$(git status --porcelain) |
| 88 | + if [[ -n "${clean_checkout}" ]]; then |
| 89 | + git config --global user.name "Nikolai Kristiansen" > /dev/null 2>&1 |
| 90 | + git config --global user.email nikolaik@users.noreply.github.com > /dev/null 2>&1 |
| 91 | +
|
| 92 | + # Update README.md |
| 93 | + today=$(date +%Y-%m-%d) |
| 94 | + sed -i -E "s/Last updated by bot: .*/Last updated by bot: ${today}/" README.md |
| 95 | +
|
| 96 | + git add versions.json README.md |
| 97 | + git commit -m '🗃 Updated python/node versions [skip ci]' |
| 98 | + git push --quiet origin main |
| 99 | + else |
| 100 | + echo "Nothing changed, nothing to archive." |
| 101 | + fi |
| 102 | +
|
| 103 | + test: |
| 104 | + uses: ./.github/workflows/tests.yaml |
0 commit comments