|
| 1 | +name: Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + environment: |
| 8 | + type: environment |
| 9 | + description: The environment to deploy. |
| 10 | + |
| 11 | +jobs: |
| 12 | +# lint: |
| 13 | +# runs-on: ubuntu-latest |
| 14 | +# steps: |
| 15 | +# - uses: actions/checkout@v4 |
| 16 | +# with: |
| 17 | +# fetch-depth: 0 |
| 18 | +# - uses: actions/setup-python@v4 |
| 19 | +# with: |
| 20 | +# python-version: 3.9 |
| 21 | +# - run: make init |
| 22 | +# - run: make lint |
| 23 | + |
| 24 | +# test: |
| 25 | +# runs-on: ubuntu-latest |
| 26 | +# services: |
| 27 | +# postgres: |
| 28 | +# image: postgis/postgis:14-master |
| 29 | +# env: |
| 30 | +# POSTGRES_PASSWORD: postgres |
| 31 | +# options: >- |
| 32 | +# --health-cmd pg_isready |
| 33 | +# --health-interval 10s |
| 34 | +# --health-timeout 5s |
| 35 | +# --health-retries 5 |
| 36 | +# ports: |
| 37 | +# - 5432:5432 |
| 38 | +# env: |
| 39 | +# DATASETTE_URL: https://datasette.digital-land.info |
| 40 | +# DATA_FILE_URL: https://data.digital-land.info |
| 41 | +# READ_DATABASE_URL: postgresql://postgres:postgres@localhost/digital_land_test |
| 42 | +# WRITE_DATABASE_URL: postgresql://postgres:postgres@localhost/digital_land_test |
| 43 | +# ENVIRONMENT: development |
| 44 | +# PGPASSWORD: postgres |
| 45 | +# steps: |
| 46 | +# - uses: actions/checkout@v4 |
| 47 | +# with: |
| 48 | +# fetch-depth: 0 |
| 49 | +# |
| 50 | +# - uses: actions/setup-python@v4 |
| 51 | +# with: |
| 52 | +# python-version: 3.9 |
| 53 | +# |
| 54 | +# - run: make init |
| 55 | +# |
| 56 | +# - name: Setup database |
| 57 | +# run: | |
| 58 | +# psql -h localhost -c "CREATE DATABASE digital_land_test WITH TEMPLATE postgres" -U postgres |
| 59 | +# |
| 60 | +# - name: Unit Tests |
| 61 | +# run: | |
| 62 | +# make test-unit |
| 63 | +# echo "## Unit Tests" >> $GITHUB_STEP_SUMMARY |
| 64 | +# cat unit-tests.md >> $GITHUB_STEP_SUMMARY |
| 65 | +# |
| 66 | +# - name: Integration Tests |
| 67 | +# run: | |
| 68 | +# make test-integration |
| 69 | +# echo "## Integration Tests" >> $GITHUB_STEP_SUMMARY |
| 70 | +# cat integration-tests.md >> $GITHUB_STEP_SUMMARY |
| 71 | +# |
| 72 | +# - name: Acceptance Tests |
| 73 | +# run: | |
| 74 | +# make test-acceptance |
| 75 | +# echo "## Acceptance Tests" >> $GITHUB_STEP_SUMMARY |
| 76 | +# cat acceptance-tests.md >> $GITHUB_STEP_SUMMARY |
| 77 | +# |
| 78 | +# - name: Accessibility Tests |
| 79 | +# run: | |
| 80 | +# make test-accessibility |
| 81 | +# echo "## Accessibility Tests" >> $GITHUB_STEP_SUMMARY |
| 82 | +# cat accessibility-tests.md >> $GITHUB_STEP_SUMMARY |
| 83 | +# |
| 84 | +# - uses: actions/upload-artifact@v3 |
| 85 | +# if: always() |
| 86 | +# with: |
| 87 | +# name: playwright-report |
| 88 | +# path: playwright-report/ |
| 89 | +# retention-days: 30 |
| 90 | + |
| 91 | + detect-environments: |
| 92 | + runs-on: ubuntu-latest |
| 93 | +# needs: [test, lint] |
| 94 | + outputs: |
| 95 | + environments: ${{ steps.environments.outputs.result }} |
| 96 | +# if: github.ref_name == 'main' |
| 97 | + steps: |
| 98 | + - uses: actions/github-script@v6 |
| 99 | + id: environments |
| 100 | + with: |
| 101 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 102 | + result-encoding: json |
| 103 | + script: | |
| 104 | + if (context.payload?.inputs?.environment) return [context.payload?.inputs?.environment]; |
| 105 | + const {data: {environments}} = |
| 106 | + await github.request(`GET /repos/${process.env.GITHUB_REPOSITORY}/environments`); |
| 107 | + return environments.map(e => e.name) |
| 108 | +
|
| 109 | + deploy: |
| 110 | + runs-on: ubuntu-latest |
| 111 | + needs: [detect-environments] |
| 112 | + strategy: |
| 113 | + matrix: |
| 114 | + environment: ${{ fromJSON(needs.detect-environments.outputs.environments) }} |
| 115 | + environment: ${{ matrix.environment }} |
| 116 | + env: |
| 117 | + DOCKER_REPO: ${{ secrets.DEPLOY_DOCKER_REPOSITORY }} |
| 118 | +# if: github.ref_name == 'main' |
| 119 | + steps: |
| 120 | + - uses: actions/checkout@v4 |
| 121 | + |
| 122 | + - id: vars |
| 123 | + run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT |
| 124 | + |
| 125 | + - run: | |
| 126 | + curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" |
| 127 | + unzip -q awscliv2.zip |
| 128 | + sudo ./aws/install --update |
| 129 | + sudo apt-get update |
| 130 | + sudo apt-get install -y rsync |
| 131 | +
|
| 132 | + - uses: aws-actions/configure-aws-credentials@v1-node16 |
| 133 | + with: |
| 134 | + aws-access-key-id: ${{ secrets.DEPLOY_AWS_ACCESS_KEY_ID }} |
| 135 | + aws-secret-access-key: ${{ secrets.DEPLOY_AWS_SECRET_ACCESS_KEY }} |
| 136 | + aws-region: eu-west-2 |
| 137 | + |
| 138 | + - run: | |
| 139 | + npm install |
| 140 | + make frontend-all |
| 141 | +
|
| 142 | + - uses: aws-actions/amazon-ecr-login@v1 |
| 143 | + |
| 144 | + - run: docker pull $DOCKER_REPO:${GITHUB_REF_NAME} || echo "no current latest image" |
| 145 | + |
| 146 | + - run: docker build -t $DOCKER_REPO:${{ steps.vars.outputs.sha_short }} . |
| 147 | + |
| 148 | + - run: docker tag $DOCKER_REPO:${{ steps.vars.outputs.sha_short }} $DOCKER_REPO:${GITHUB_REF_NAME} |
| 149 | + |
| 150 | + - run: docker push $DOCKER_REPO:${{ steps.vars.outputs.sha_short }} |
| 151 | + |
| 152 | + - run: docker push $DOCKER_REPO:${GITHUB_REF_NAME} |
0 commit comments