From 63a0bf78972ac982b785d530ec8869077ee226d9 Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 20 Sep 2023 11:09:32 +1000 Subject: [PATCH 01/18] Adds deploy workflow --- .github/workflows/deploy.yml | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..ef52839 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,51 @@ +name: deploy + +on: + workflow_call: + inputs: + skpr_env: + default: dev + type: string + description: The environment to deploy to. + secrets: + skpr_username: + required: true + skpr_password: + required: true + +env: + SKPR_USERNAME: ${{ secrets.skpr_username }} + SKPR_PASSWORD: ${{ secrets.skpr_password }} + +jobs: + deploy: + runs-on: ubuntu-latest + environment: + name: ${{ inputs.skpr_env }} + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + show-progress: false + - name: Skpr Setup + uses: skpr/action-setup@v1 + - name: Skpr Info + id: skpr-info + uses: skpr/action-info@v1 + with: + env: ${{ inputs.skpr_env }} + - name: Skpr Package + uses: skpr/action-package@v1 + with: + version: ${{ steps.skpr-info.outputs.version }} + - name: Skpr Deploy + uses: skpr/action-deploy@v1 + with: + version: ${{ steps.skpr-info.outputs.version }} + env: ${{ inputs.skpr_env }} + - name: Run Skpr Post-deploy Command + uses: skpr/action-exec@v1 + with: + env: ${{ env.SKPR_ENV }} + command: make deploy From b73de0f5e7bd8dd4e548ac45ed6ed687322f9c3a Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 20 Sep 2023 12:22:49 +1000 Subject: [PATCH 02/18] Adds deploy workflow --- .github/workflows/deploy.yml | 47 +++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ef52839..92ea811 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,10 +3,17 @@ name: deploy on: workflow_call: inputs: - skpr_env: - default: dev + env: + type: environment + required: true + description: The Skpr environment to deploy to. + package: + default: true + type: boolean + description: Whether this deployment needs to be packaged. + version: type: string - description: The environment to deploy to. + description: The version to deploy secrets: skpr_username: required: true @@ -18,32 +25,50 @@ env: SKPR_PASSWORD: ${{ secrets.skpr_password }} jobs: - deploy: + info: runs-on: ubuntu-latest - environment: - name: ${{ inputs.skpr_env }} + concurrency: ${{ inputs.env }} steps: - name: Checkout Code uses: actions/checkout@v4 with: fetch-depth: 0 show-progress: false - - name: Skpr Setup - uses: skpr/action-setup@v1 - name: Skpr Info id: skpr-info uses: skpr/action-info@v1 with: - env: ${{ inputs.skpr_env }} + env: ${{ inputs.env }} + outputs: + url: ${{ steps.skpr-info.outputs.url }} + + deploy: + runs-on: ubuntu-latest + needs: [ info ] + environment: + name: ${{ inputs.env }} + url: ${{ needs.info.outputs.url }} + concurrency: ${{ inputs.env }} + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + show-progress: false + - name: Get version + if: + - name: Skpr Setup + uses: skpr/action-setup@v1 - name: Skpr Package + if: inputs.package uses: skpr/action-package@v1 with: - version: ${{ steps.skpr-info.outputs.version }} + version: - name: Skpr Deploy uses: skpr/action-deploy@v1 with: version: ${{ steps.skpr-info.outputs.version }} - env: ${{ inputs.skpr_env }} + env: ${{ inputs.env }} - name: Run Skpr Post-deploy Command uses: skpr/action-exec@v1 with: From a4935bec2eb4a1760b6fd604ff7cff6cb07cb090 Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 20 Sep 2023 13:40:08 +1000 Subject: [PATCH 03/18] Set environment url and lint --- .github/workflows/actionlint.yml | 22 +++++++++++++++++ .github/workflows/deploy.yml | 42 +++++++++++++------------------- 2 files changed, 39 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/actionlint.yml diff --git a/.github/workflows/actionlint.yml b/.github/workflows/actionlint.yml new file mode 100644 index 0000000..2defa91 --- /dev/null +++ b/.github/workflows/actionlint.yml @@ -0,0 +1,22 @@ +name: actionlint +on: + pull_request: + branches: [ main ] + push: + branches: [ main ] + +jobs: + run-actionlint: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + steps: + - uses: actions/checkout@v4 + with: + show-progress: false + - name: actionlint + uses: raven-actions/actionlint@v1 + with: + shellcheck: false + pyflakes: false diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 92ea811..0d1977b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -25,29 +25,11 @@ env: SKPR_PASSWORD: ${{ secrets.skpr_password }} jobs: - info: - runs-on: ubuntu-latest - concurrency: ${{ inputs.env }} - steps: - - name: Checkout Code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - show-progress: false - - name: Skpr Info - id: skpr-info - uses: skpr/action-info@v1 - with: - env: ${{ inputs.env }} - outputs: - url: ${{ steps.skpr-info.outputs.url }} - deploy: runs-on: ubuntu-latest - needs: [ info ] environment: name: ${{ inputs.env }} - url: ${{ needs.info.outputs.url }} + url: ${{ steps.skpr-info.outputs.url }} concurrency: ${{ inputs.env }} steps: - name: Checkout Code @@ -56,20 +38,30 @@ jobs: fetch-depth: 0 show-progress: false - name: Get version - if: + id: version + run: | + if ${{ inputs.version == '' }}; then + version=$(git describe --tags --always) + fi + echo "version=$version" >> $GITHUB_OUTPUT - name: Skpr Setup uses: skpr/action-setup@v1 - - name: Skpr Package + - name: Skpr Info + id: skpr-info + uses: skpr/action-info@v1 + with: + env: ${{ inputs.env }} + - name: Package if: inputs.package uses: skpr/action-package@v1 with: - version: - - name: Skpr Deploy + version: ${{ steps.version.outputs.version }} + - name: Deploy uses: skpr/action-deploy@v1 with: - version: ${{ steps.skpr-info.outputs.version }} + version: ${{ steps.version.outputs.version }} env: ${{ inputs.env }} - - name: Run Skpr Post-deploy Command + - name: Post-deploy Commands uses: skpr/action-exec@v1 with: env: ${{ env.SKPR_ENV }} From 545186b82a1a1759d7224983cc35967c54287ec6 Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 20 Sep 2023 13:43:01 +1000 Subject: [PATCH 04/18] Fix linting error --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0d1977b..f740358 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -4,7 +4,7 @@ on: workflow_call: inputs: env: - type: environment + type: string required: true description: The Skpr environment to deploy to. package: From 746f396f6f7abdf8a4e5df1275cec273f5980a9d Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 20 Sep 2023 13:50:36 +1000 Subject: [PATCH 05/18] Try case sensitive --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f740358..16cb44e 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -21,8 +21,8 @@ on: required: true env: - SKPR_USERNAME: ${{ secrets.skpr_username }} - SKPR_PASSWORD: ${{ secrets.skpr_password }} + SKPR_USERNAME: ${{ secrets.SKPR_USERNAME }} + SKPR_PASSWORD: ${{ secrets.SKPR_PASSWORD }} jobs: deploy: From a63631bd0141576dac41b9846aab46f0dddd1736 Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 20 Sep 2023 13:55:31 +1000 Subject: [PATCH 06/18] Add permissions: --- .github/workflows/deploy.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 16cb44e..f9ce6f6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -15,11 +15,16 @@ on: type: string description: The version to deploy secrets: - skpr_username: + SKPR_USERNAME: required: true - skpr_password: + SKPR_PASSWORD: required: true +permissions: + contents: read + checks: write + pull-requests: write + env: SKPR_USERNAME: ${{ secrets.SKPR_USERNAME }} SKPR_PASSWORD: ${{ secrets.SKPR_PASSWORD }} From 398c72ac9e3783d0c110473c864ea341d45743f9 Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 20 Sep 2023 14:06:34 +1000 Subject: [PATCH 07/18] Toggle case --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f9ce6f6..c9d031b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -15,9 +15,9 @@ on: type: string description: The version to deploy secrets: - SKPR_USERNAME: + skpr_username: required: true - SKPR_PASSWORD: + skpr_password: required: true permissions: From 82b24d2103821822e7fccc1a606420a5854ce241 Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 20 Sep 2023 14:12:15 +1000 Subject: [PATCH 08/18] Replace actions with skpr commands --- .github/workflows/deploy.yml | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c9d031b..6e1961e 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -14,6 +14,10 @@ on: version: type: string description: The version to deploy + post_deploy: + default: make deploy + type: string + description: The post deploy commands to run on the environment. secrets: skpr_username: required: true @@ -58,16 +62,8 @@ jobs: env: ${{ inputs.env }} - name: Package if: inputs.package - uses: skpr/action-package@v1 - with: - version: ${{ steps.version.outputs.version }} + run: skpr package ${{ steps.version.outputs.version }} - name: Deploy - uses: skpr/action-deploy@v1 - with: - version: ${{ steps.version.outputs.version }} - env: ${{ inputs.env }} + run: skpr deploy ${{ inputs.env }} ${{ steps.version.outputs.version }} - name: Post-deploy Commands - uses: skpr/action-exec@v1 - with: - env: ${{ env.SKPR_ENV }} - command: make deploy + run: skpr exec ${{ inputs.env }} ${{ inputs.post_deploy }} From 8afcb066addda655bbb9d2638974329aa203a8af Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 20 Sep 2023 14:17:44 +1000 Subject: [PATCH 09/18] Use correct action names --- .github/workflows/deploy.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6e1961e..678de1d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: deploy +name: Skpr Deploy on: workflow_call: @@ -53,11 +53,11 @@ jobs: version=$(git describe --tags --always) fi echo "version=$version" >> $GITHUB_OUTPUT - - name: Skpr Setup - uses: skpr/action-setup@v1 - - name: Skpr Info + - name: Setup + uses: skpr/setup-action@v1 + - name: Info id: skpr-info - uses: skpr/action-info@v1 + uses: skpr/info-action@v1 with: env: ${{ inputs.env }} - name: Package From 706063d57c13cce63d8faaf7a59866e68f15721c Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 20 Sep 2023 14:20:34 +1000 Subject: [PATCH 10/18] Use main --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 678de1d..4d83cc0 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -54,10 +54,10 @@ jobs: fi echo "version=$version" >> $GITHUB_OUTPUT - name: Setup - uses: skpr/setup-action@v1 + uses: skpr/setup-action@main - name: Info id: skpr-info - uses: skpr/info-action@v1 + uses: skpr/info-action@main with: env: ${{ inputs.env }} - name: Package From 4bb475f315a602f4d4492e459f29e5221a4cb595 Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 20 Sep 2023 14:25:47 +1000 Subject: [PATCH 11/18] Use skpr commands directly --- .github/workflows/deploy.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 4d83cc0..a23eb90 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -54,12 +54,18 @@ jobs: fi echo "version=$version" >> $GITHUB_OUTPUT - name: Setup - uses: skpr/setup-action@main + shell: bash + run: | + cli_version=$(curl -sSL "https://api.github.com/repos/skpr/cli/releases/latest" | jq -r .tag_name) + curl -sSL https://github.com/skpr/cli/releases/download/${cli_version}/skpr_${cli_version:1}_linux_amd64.deb -o skpr-cli.deb + sudo dpkg -i skpr-cli.deb - name: Info id: skpr-info - uses: skpr/info-action@main - with: - env: ${{ inputs.env }} + shell: bash + run: | + domain=$(skpr info ${{ inputs.env }} | jq -r ".Ingress.Domain") + url=https://$domain + echo "url=$url" >> $GITHUB_OUTPUT - name: Package if: inputs.package run: skpr package ${{ steps.version.outputs.version }} From 5d7440b43e97deb9222d7adba73abd2d6283354e Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 20 Sep 2023 15:43:02 +1000 Subject: [PATCH 12/18] Use gh release download --- .github/workflows/deploy.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a23eb90..25c1650 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -54,10 +54,8 @@ jobs: fi echo "version=$version" >> $GITHUB_OUTPUT - name: Setup - shell: bash run: | - cli_version=$(curl -sSL "https://api.github.com/repos/skpr/cli/releases/latest" | jq -r .tag_name) - curl -sSL https://github.com/skpr/cli/releases/download/${cli_version}/skpr_${cli_version:1}_linux_amd64.deb -o skpr-cli.deb + gh release download --repo skpr/cli --pattern skpr_*linux_amd64.deb -O skpr-cli.deb sudo dpkg -i skpr-cli.deb - name: Info id: skpr-info From 04f1df6dad96c5bf80e00de9dae51229c0c0c8a2 Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 20 Sep 2023 15:44:19 +1000 Subject: [PATCH 13/18] Set gh token --- .github/workflows/deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 25c1650..c7305aa 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -32,6 +32,7 @@ permissions: env: SKPR_USERNAME: ${{ secrets.SKPR_USERNAME }} SKPR_PASSWORD: ${{ secrets.SKPR_PASSWORD }} + GH_TOKEN: ${{ github.token }} jobs: deploy: From cbd8d95a96d4320103ed35b72c07df43353eae9b Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 20 Sep 2023 15:54:09 +1000 Subject: [PATCH 14/18] More detail --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c7305aa..d63bb5e 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -54,9 +54,9 @@ jobs: version=$(git describe --tags --always) fi echo "version=$version" >> $GITHUB_OUTPUT - - name: Setup + - name: Install Skpr CLI run: | - gh release download --repo skpr/cli --pattern skpr_*linux_amd64.deb -O skpr-cli.deb + gh release download --repo skpr/cli --pattern skpr_*_linux_amd64.deb -O skpr-cli.deb sudo dpkg -i skpr-cli.deb - name: Info id: skpr-info From 29f228d6b663bbbc0b24d6e0b840d988e384b886 Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 20 Sep 2023 16:07:58 +1000 Subject: [PATCH 15/18] Remove permissions --- .github/workflows/deploy.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d63bb5e..74c08b9 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -24,11 +24,6 @@ on: skpr_password: required: true -permissions: - contents: read - checks: write - pull-requests: write - env: SKPR_USERNAME: ${{ secrets.SKPR_USERNAME }} SKPR_PASSWORD: ${{ secrets.SKPR_PASSWORD }} From 191c5cfd8a54da0f1eac9fc784e0d7cdd0ce6c5b Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 20 Sep 2023 16:54:00 +1000 Subject: [PATCH 16/18] Adds support for version_from_env --- .github/workflows/deploy.yml | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 74c08b9..5c24a33 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -14,6 +14,9 @@ on: version: type: string description: The version to deploy + version_from_env: + type: string + description: Get the version to deploy from the environment. post_deploy: default: make deploy type: string @@ -42,17 +45,24 @@ jobs: with: fetch-depth: 0 show-progress: false + - name: Install Skpr CLI + run: | + gh release download --repo skpr/cli --pattern skpr_*_linux_amd64.deb -O skpr-cli.deb + sudo dpkg -i skpr-cli.deb - name: Get version id: version run: | - if ${{ inputs.version == '' }}; then + if [ -n "${{ inputs.version }}" ]; then + version=${{ inputs.version }} + echo "::notice:: Using explicit version $version" + elif [ -n "${{ inputs.version_from_env }}" ]; then + version=$(skpr info ${{ inputs.version_from_env }} | jq -r ".Version") + echo "::notice:: Using version $version from ${{ inputs.version_from_env }} env" + else version=$(git describe --tags --always) + echo "::notice:: Using version $version from git describe" fi echo "version=$version" >> $GITHUB_OUTPUT - - name: Install Skpr CLI - run: | - gh release download --repo skpr/cli --pattern skpr_*_linux_amd64.deb -O skpr-cli.deb - sudo dpkg -i skpr-cli.deb - name: Info id: skpr-info shell: bash @@ -65,5 +75,6 @@ jobs: run: skpr package ${{ steps.version.outputs.version }} - name: Deploy run: skpr deploy ${{ inputs.env }} ${{ steps.version.outputs.version }} - - name: Post-deploy Commands + - name: Post-deploy run: skpr exec ${{ inputs.env }} ${{ inputs.post_deploy }} + - run: echo "::notice:: Deployed ${{ steps.version.outputs.version }}" From 4870a62bff56e335441758f46310c92e02c0fdfd Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 20 Sep 2023 17:24:20 +1000 Subject: [PATCH 17/18] Yaml syntax --- .github/workflows/deploy.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5c24a33..e10cd68 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -77,4 +77,5 @@ jobs: run: skpr deploy ${{ inputs.env }} ${{ steps.version.outputs.version }} - name: Post-deploy run: skpr exec ${{ inputs.env }} ${{ inputs.post_deploy }} - - run: echo "::notice:: Deployed ${{ steps.version.outputs.version }}" + - name: Display version + run: echo "::notice:: Deployed ${{ steps.version.outputs.version }}" From ac1fba06b1352f7594f247daea059c50042b0d92 Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 20 Sep 2023 17:25:35 +1000 Subject: [PATCH 18/18] Remove version --- .github/workflows/deploy.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e10cd68..6b4b1ec 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -77,5 +77,4 @@ jobs: run: skpr deploy ${{ inputs.env }} ${{ steps.version.outputs.version }} - name: Post-deploy run: skpr exec ${{ inputs.env }} ${{ inputs.post_deploy }} - - name: Display version - run: echo "::notice:: Deployed ${{ steps.version.outputs.version }}" +