diff --git a/.github/actions/setup-postgres-on-mac/action.yml b/.github/actions/setup-postgres-on-mac/action.yml new file mode 100644 index 0000000..2a22d18 --- /dev/null +++ b/.github/actions/setup-postgres-on-mac/action.yml @@ -0,0 +1,47 @@ +name: 'Setup Postgres on Mac' +description: 'Setup Postgres on Mac' + +outputs: + database-url: + description: "Connection URL of database that was created" + value: ${{ steps.set-database-url.outputs.database-url }} + +runs: + using: "composite" + steps: + - shell: bash + run: | + brew install postgresql + brew services start postgresql + echo "Check PostgreSQL service is running" + i=10 + COMMAND='pg_isready' + while [ $i -gt 0 ]; do + echo "Check PostgreSQL service status" + eval $COMMAND && break + ((i--)) + if [ $i == 0 ]; then + echo "PostgreSQL service not ready, all attempts exhausted" + exit 1 + fi + echo "PostgreSQL service not ready, wait 10 more sec, attempts left: $i" + sleep 10 + done + + - shell: bash + run: | + psql --command="CREATE USER myuser PASSWORD 'mypassword'" --command="\du" postgres + + - shell: bash + run: | + createdb --owner=myuser mydatabase + PGPASSWORD=mypassword psql --username=myuser --host=localhost --list mydatabase + + - id: set-database-url + shell: bash + run: echo "database-url=postgresql://myuser:mypassword@localhost/mydatabase" >> $GITHUB_OUTPUT + + - shell: bash + run: psql $DATABASE_URL -c "select version()" + env: + DATABASE_URL: ${{ steps.set-database-url.outputs.database-url }} diff --git a/.github/actions/sincere-auth-build-action/action.yml b/.github/actions/sincere-auth-build-action/action.yml new file mode 100644 index 0000000..679dc76 --- /dev/null +++ b/.github/actions/sincere-auth-build-action/action.yml @@ -0,0 +1,31 @@ +name: 'Sincere Auth Build Action' +description: "Separate action to either build or test Sincere Auth" +inputs: + swift-version: + description: 'Version of Swift to build with' + required: true + action: + description: Build for release or run tests. Options are 'build' or 'test' + required: true + database-url: + description: Database URL to use during tests + required: true + +runs: + using: "composite" + steps: + - uses: SwiftyLab/setup-swift@latest + with: + swift-version: ${{ inputs.swift-version }} + - shell: bash + run: swift --version + + - if: ${{ inputs.action == 'test' }} + shell: bash + run: | + swift run SincereAuthServer migrate -y --env test && swift test + env: + DATABASE_URL: ${{ inputs.database-url }} + - if: ${{ inputs.action == 'build' }} + shell: bash + run: swift build -c release diff --git a/.github/actions/sincere-auth-docker-action/action.yml b/.github/actions/sincere-auth-docker-action/action.yml new file mode 100644 index 0000000..351581a --- /dev/null +++ b/.github/actions/sincere-auth-docker-action/action.yml @@ -0,0 +1,29 @@ +name: "Sincere Auth Docker Action" +description: "Build & push a docker image" +inputs: + target: + description: "The Dockerfile target to build and push" + required: true + +runs: + using: "composite" + steps: + - name: Docker metadata - ${{ inputs.target }} + id: docker-metadata + uses: docker/metadata-action@v4 + with: + images: | + ghcr.io/${{ github.repository }}-${{ inputs.target }} + tags: | + type=ref,event=tag + type=sha,format=long + type=semver,pattern={{version}} + + - name: Build and push Docker image - ${{ inputs.target }} + uses: docker/build-push-action@v6 + with: + context: . + push: true + target: ${{ inputs.target }} + tags: ${{ steps.docker-metadata.outputs.tags }} + labels: ${{ steps.docker-metadata.outputs.labels }} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..65d6c2c --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,81 @@ +name: Continuous Integration + +on: + push: + branches: "**" + pull_request: + tags: + - "**" + +jobs: + docker: + runs-on: ubuntu-latest + strategy: + matrix: + target: ["web", "release", "queues", "scheduled-queues"] + steps: + - uses: actions/checkout@v4 + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ghcr.io/${{ github.repository }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: ./.github/actions/sincere-auth-docker-action + with: + target: ${{ matrix.target }} + + mac: + name: Mac ${{ matrix.action }}, Swift ${{ matrix.swift-version }} + runs-on: macos-latest + strategy: + matrix: + swift-version: ["5.9", "5.10"] + action: ["build", "test"] + steps: + - uses: actions/checkout@v4 + - id: setup-postgres + uses: ./.github/actions/setup-postgres-on-mac + - uses: shogo82148/actions-setup-redis@v1 + - uses: ./.github/actions/sincere-auth-build-action + with: + swift-version: ${{ matrix.swift-version }} + action: ${{ matrix.action }} + database-url: ${{ steps.setup-postgres.outputs.database-url }} + + ubuntu: + name: Ubuntu ${{ matrix.action }}, Swift ${{ matrix.swift-version }} + runs-on: ubuntu-latest + strategy: + matrix: + swift-version: ["5.9", "5.10"] + action: ["build", "test"] + services: + redis: + image: redis:latest + ports: ["6379:6379"] + postgres: + image: postgres:latest + env: + POSTGRES_DB: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_USER: postgres + ports: ["5432:5432"] + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/sincere-auth-build-action + with: + swift-version: ${{ matrix.swift-version }} + action: ${{ matrix.action }} + database-url: "postgresql://postgres:postgres@localhost/postgres" + +env: + DB_SYMMETRIC_KEY: "9/Vk5Rlzctc5tyX0SCmIJaRzEg+QgwWjlTzD0LMPqNY=" + REDIS_URL: "redis://127.0.0.1:6379" + SELF_ISSUER_ID: "com.fullqueuedeveloper.FQAuth" + APPLE_APP_ID: "com.fullqueuedeveloper.FQAuth" + APPLE_TEAM_ID: "FQDV1234" + APPLE_SERVICES_KEY_ID: "com.fullqueuedeveloper.FQAuthServer.AppleServicesKeyID" + APPLE_SERVICES_KEY: "LS0tLS1CRUdJTiBFQyBQQVJBTUVURVJTLS0tLS0KQmdVcmdRUUFJdz09Ci0tLS0tRU5EIEVDIFBBUkFNRVRFUlMtLS0tLQotLS0tLUJFR0lOIEVDIFBSSVZBVEUgS0VZLS0tLS0KTUlIY0FnRUJCRUlCdXRBYnNFUjY1bVFnby9iKzJYcTVsaDZQTDhuRTJSRjZ0WjFDdWNmdW5UaWtyNDFwL3JhZwpYaXd6MTJVOWxoY211Y2wrWDh5MkVacUowQ0FXS0VhTHluYWdCd1lGSzRFRUFDT2hnWWtEZ1lZQUJBQm92SWc2CkNRREdkcjMxNlR6bEJXRG56SHIvWDVoSnVzbnpSY0E2WUpUS1RVMll2bXdCaHVGUFBiNit1MUttaUdkTnQ2N1EKTU16RjMxYjY0L0gwS3prQ1BnRVZicklMVkthNDlUbTdNQU1WT3dsUUxaVHBIck8xMVk2bVd5eERydEFCSXNDTApqNnBRMFhGNlZiNWNOT3RWL1BpMC9lcTIxY3UwV3h5aDNHODY2TlQ0T1E9PQotLS0tLUVORCBFQyBQUklWQVRFIEtFWS0tLS0tCg==" + AUTH_PRIVATE_KEY: "LS0tLS1CRUdJTiBFQyBQQVJBTUVURVJTLS0tLS0KQmdVcmdRUUFJdz09Ci0tLS0tRU5EIEVDIFBBUkFNRVRFUlMtLS0tLQotLS0tLUJFR0lOIEVDIFBSSVZBVEUgS0VZLS0tLS0KTUlIY0FnRUJCRUlCV1Q2RVFQZkRNelNwME1tNjFlbFRaaXljQSs5Sy9QRzN6TFFka0hsMnFlWnlCWEs4VlRrRQpTbGovemxXRkhUWG1RTTB0d3V5YnAyTEFMaHVwd2ZJR3l5eWdCd1lGSzRFRUFDT2hnWWtEZ1lZQUJBRXh5QS9wCitEM05CTmdjMm1XUjdBOVRUa0tkdWMrWVlaeFN2ZWdPMWpMeC9QbG1TUHdHcGF3c2NiYWxHYTgwbkRTNTU2SXUKR1l0S2ZnbkJGSXBFcU1FQkdBQ2MrUys2cTNBNU10emM4bHhzamRlYVlSWDdIbnJNejlVdzRROGNUUmkzUXVJNwpKdi93OEJnZFhRNnVMdGdSMTZLTzJQcVg2azRSSDdmY3BSL20vUEU1OEE9PQotLS0tLUVORCBFQyBQUklWQVRFIEtFWS0tLS0tCg==" diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index 9159d90..0000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,107 +0,0 @@ -name: Docker - -on: - push: - branches: "**" - pull_request: - tags: - - "**" - -jobs: - build-docker: - name: Build with Docker - runs-on: ubuntu-latest - - env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - - steps: - - name: Log in to the Container registry - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - uses: actions/checkout@v3 - - - name: Docker metadata - scheduled queues - id: meta-scheduled-queues - uses: docker/metadata-action@v4 - with: - images: | - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-scheduled-queues - tags: | - type=ref,event=tag - type=sha,format=long - type=semver,pattern={{version}} - - - name: Docker metadata - queues - id: meta-queues - uses: docker/metadata-action@v4 - with: - images: | - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-queues - tags: | - type=ref,event=tag - type=sha,format=long - type=semver,pattern={{version}} - - - name: Docker metadata - release - id: meta-release - uses: docker/metadata-action@v4 - with: - images: | - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-release - tags: | - type=ref,event=tag - type=sha,format=long - type=semver,pattern={{version}} - - - name: Docker metadata - web - id: meta-web - uses: docker/metadata-action@v4 - with: - images: | - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - tags: | - type=ref,event=tag - type=sha,format=long - type=semver,pattern={{version}} - - - name: Build and push Docker image - web - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc - with: - context: . - push: true - target: web - tags: ${{ steps.meta-web.outputs.tags }} - labels: ${{ steps.meta-web.outputs.labels }} - - - name: Build and push Docker image - release - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc - with: - context: . - push: true - target: release - tags: ${{ steps.meta-release.outputs.tags }} - labels: ${{ steps.meta-release.outputs.labels }} - - - name: Build and push Docker image - queues - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc - with: - context: . - push: true - target: queues - tags: ${{ steps.meta-queues.outputs.tags }} - labels: ${{ steps.meta-queues.outputs.labels }} - - - name: Build and push Docker image - scheduled queues - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc - with: - context: . - push: true - target: scheduled-queues - tags: ${{ steps.meta-scheduled-queues.outputs.tags }} - labels: ${{ steps.meta-scheduled-queues.outputs.labels }} diff --git a/.github/workflows/macos.yaml b/.github/workflows/macos.yaml deleted file mode 100644 index 439e21b..0000000 --- a/.github/workflows/macos.yaml +++ /dev/null @@ -1,79 +0,0 @@ -name: Mac - -on: - push: - branches: "**" - pull_request: - tags: - - "**" - -jobs: - build-mac: - name: Build on Mac, Swift ${{ matrix.swift-version }} - runs-on: macos-latest - strategy: - matrix: - include: - - swift-version: "5.9" - - swift-version: "5.10" - steps: - - uses: SwiftyLab/setup-swift@latest - with: - swift-version: ${{ matrix.swift-version }} - - run: swift --version - - uses: actions/checkout@v3 - - run: swift build -c release - - test-mac: - name: Test on Mac, Swift ${{ matrix.swift-version }} - runs-on: macos-latest - strategy: - matrix: - include: - - swift-version: "5.9" - - swift-version: "5.10" - - steps: - - run: | - brew install postgresql - brew services start postgresql - echo "Check PostgreSQL service is running" - i=10 - COMMAND='pg_isready' - while [ $i -gt 0 ]; do - echo "Check PostgreSQL service status" - eval $COMMAND && break - ((i--)) - if [ $i == 0 ]; then - echo "PostgreSQL service not ready, all attempts exhausted" - exit 1 - fi - echo "PostgreSQL service not ready, wait 10 more sec, attempts left: $i" - sleep 10 - done - - run: | - psql --command="CREATE USER myuser PASSWORD 'mypassword'" --command="\du" postgres - - run: | - createdb --owner=myuser mydatabase - PGPASSWORD=mypassword psql --username=myuser --host=localhost --list mydatabase - - - run: psql $DATABASE_URL -c "select version()" - - - uses: SwiftyLab/setup-swift@latest - with: - swift-version: ${{ matrix.swift-version }} - - run: swift --version - - uses: shogo82148/actions-setup-redis@v1 - - uses: actions/checkout@v3 - - run: swift run SincereAuthServer migrate -y --env test - - run: swift test - env: - DATABASE_URL: "postgresql://myuser:mypassword@localhost/mydatabase" - DB_SYMMETRIC_KEY: "9/Vk5Rlzctc5tyX0SCmIJaRzEg+QgwWjlTzD0LMPqNY=" - REDIS_URL: "redis://127.0.0.1:6379" - SELF_ISSUER_ID: "com.fullqueuedeveloper.FQAuth" - APPLE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RUa0tkdWMrWVlaeFN2ZWdPMWpMeC9QbG1TUHdHcGF3c2NiYWxHYTgwbkRTNTU2SXUKR1l0S2ZnbkJGSXBFcU1FQkdBQ2MrUys2cTNBNU10emM4bHhzamRlYVlSWDdIbnJNejlVdzRROGNUUmkzUXVJNwpKdi93OEJnZFhRNnVMdGdSMTZLTzJQcVg2azRSSDdmY3BSL20vUEU1OEE9PQotLS0tLUVORCBFQyBQUklWQVRFIEtFWS0tLS0tCg==" diff --git a/.github/workflows/ubuntu.yaml b/.github/workflows/ubuntu.yaml deleted file mode 100644 index 878826a..0000000 --- a/.github/workflows/ubuntu.yaml +++ /dev/null @@ -1,57 +0,0 @@ -name: Ubuntu - -on: - push: - branches: "**" - pull_request: - tags: - - "**" - -jobs: - test-ubuntu: - name: Test on Ubuntu, Swift ${{ matrix.swift-version }} - runs-on: ubuntu-latest - strategy: - matrix: - include: - - swift-version: "5.9" - - swift-version: "5.10" - services: - redis: - image: redis:latest - ports: - - 6379:6379 - postgres: - image: postgres:latest - env: - POSTGRES_DB: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_USER: postgres - ports: - - 5432:5432 - # Set health checks to wait until postgres has started - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - env: - DATABASE_URL: "postgresql://postgres:postgres@localhost/postgres" - DB_SYMMETRIC_KEY: "9/Vk5Rlzctc5tyX0SCmIJaRzEg+QgwWjlTzD0LMPqNY=" - REDIS_URL: "redis://localhost" - SELF_ISSUER_ID: "com.fullqueuedeveloper.FQAuth" - APPLE_SERVICES_KEY: "LS0tLS1CRUdJTiBFQyBQQVJBTUVURVJTLS0tLS0KQmdVcmdRUUFJdz09Ci0tLS0tRU5EIEVDIFBBUkFNRVRFUlMtLS0tLQotLS0tLUJFR0lOIEVDIFBSSVZBVEUgS0VZLS0tLS0KTUlIY0FnRUJCRUlCdXRBYnNFUjY1bVFnby9iKzJYcTVsaDZQTDhuRTJSRjZ0WjFDdWNmdW5UaWt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QUklWQVRFIEtFWS0tLS0tCg==" - WEBSITE_URL: localhost - WEBSITE_APPLE_APP_ID: com.fullqueuedeveloper.Web - steps: - - uses: SwiftyLab/setup-swift@latest - with: - swift-version: ${{ matrix.swift-version }} - - run: swift --version - - uses: actions/checkout@v3 - - run: swift run SincereAuthServer migrate -y --env test - - run: swift test