From 8284c325e131134b9c5bc0888331d85243e5531a Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Tue, 5 Dec 2023 10:59:24 +0000 Subject: [PATCH 01/12] fix: parse snap name from yaml in promotion workflow --- promote-to-stable/README.md | 11 ++++++----- promote-to-stable/action.yaml | 37 ++++++++++++++++++++++++++++++----- sync-version/action.yaml | 6 +++--- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/promote-to-stable/README.md b/promote-to-stable/README.md index 96f529e..a1da8fc 100644 --- a/promote-to-stable/README.md +++ b/promote-to-stable/README.md @@ -27,11 +27,12 @@ jobs: ### Inputs -| Key | Description | Required | Default | -| -------------- | ---------------------------------------------------------------------------------------- | :------: | :------ | -| `github-token` | A token with permissions to write issues on the repository | Y | | -| `store-token` | A token with permissions to upload and release to the `stable` channel in the Snap Store | Y | | -| `snap-name` | The name of the snap to promote | N | | +| Key | Description | Required | Default | +| --------------------- | ---------------------------------------------------------------------------------------- | :------: | :------ | +| `github-token` | A token with permissions to write issues on the repository | Y | | +| `store-token` | A token with permissions to upload and release to the `stable` channel in the Snap Store | Y | | +| `snap-name` | The name of the snap to promote | N | | +| `snapcraft-yaml-path` | The path to the `snapcraft.yaml` file. | N | ### Outputs diff --git a/promote-to-stable/action.yaml b/promote-to-stable/action.yaml index 5e7fbad..c34d319 100644 --- a/promote-to-stable/action.yaml +++ b/promote-to-stable/action.yaml @@ -9,12 +9,12 @@ inputs: github-token: description: "A token with permissions to write issues on the repository" required: true + snapcraft-yaml-path: + description: "Custom path to snapcraft.yaml for when it is not in the default location." + required: false store-token: description: "A token with permissions to upload to the specified channel" required: true - snap-name: - description: "The name of the snap to promote" - required: false runs: using: composite @@ -34,12 +34,39 @@ runs: shell: bash run: | sudo snap install --classic snapcraft + + - name: Find the snapcraft.yaml path + id: yaml-path + shell: bash + run: | + if [[ -n "${{ inputs.snapcraft-yaml-path }} " ]]; then + yaml_path="${{ inputs.snapcraft-yaml-path }}" + else + snapcraft_yaml_paths=( + "snap/snapcraft.yaml" + "snapcraft.yaml" + "build-aux/snap/snapcraft.yaml" + ".snapcraft.yaml" + ) + + for file in "${snapcraft_yaml_paths[@]}"; do + if [[ -f "$file" ]]; then + yaml_path="$file" + fi + done + fi + if [[ ! -n "${yaml-path}" ]]; then + echo "No snapcraft.yaml found" >2 + exit 1 + fi + echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT" + echo "snap-name=$(yq -r '.name' "$yaml_path")" >> "$GITHUB_OUTPUT" - name: Promote snap to latest/stable id: promote env: SNAPCRAFT_STORE_CREDENTIALS: ${{ inputs.store-token }} - SNAP_NAME: ${{ inputs.snap-name || github.event.repository.name }} + snap_name: ${{ steps.yaml-path.outputs.snap-name }} shell: bash run: | echo "The command was '${{ steps.command.outputs.command-name }}' with arguments '${{ steps.command.outputs.command-arguments }}'" @@ -70,7 +97,7 @@ runs: released_revs=() for r in $revs; do - snapcraft release $SNAP_NAME "$r" "$channel" + snapcraft release $snap_name "$r" "$channel" released_revs+=("$r") done diff --git a/sync-version/action.yaml b/sync-version/action.yaml index 907c92d..d3da1b1 100644 --- a/sync-version/action.yaml +++ b/sync-version/action.yaml @@ -70,7 +70,7 @@ runs: env: yaml_path: ${{ steps.yaml-path.outputs.yaml-path }} prev_version: ${{ steps.yaml-path.outputs.prev-version }} - SNAP_NAME: ${{ steps.yaml-path.outputs.snap-name }} + snap_name: ${{ steps.yaml-path.outputs.snap-name }} run: | new_version="$(yq -r '.version' "$yaml-path")" if [[ ! "$prev_version" == "$new_version" ]]; then @@ -79,8 +79,8 @@ runs: git config --global user.name 'Snapcrafters Bot' git config --global user.email 'merlijn.sebrechts+snapcrafters-bot@gmail.com' if [[ -n "${version:-}" ]]; then - git commit -am "chore: bump ${SNAP_NAME} to version $version" + git commit -am "chore: bump ${snap_name} to version $version" else - git commit -am "chore: bump ${SNAP_NAME} dependencies" + git commit -am "chore: bump ${snap_name} dependencies" fi git push From 833b497db0cb7fc87bb3270157032e61c2b46bab Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Tue, 5 Dec 2023 11:00:28 +0000 Subject: [PATCH 02/12] docs: alphabet-ise the inputs and format tables --- release-to-candidate/README.md | 15 +++++++-------- release-to-candidate/action.yaml | 6 +++--- sync-version/README.md | 11 +++++------ sync-version/action.yaml | 12 ++++++------ test-snap-build/README.md | 9 ++++----- 5 files changed, 25 insertions(+), 28 deletions(-) diff --git a/release-to-candidate/README.md b/release-to-candidate/README.md index f27d2b1..8e15b04 100644 --- a/release-to-candidate/README.md +++ b/release-to-candidate/README.md @@ -24,14 +24,13 @@ jobs: ### Inputs -| Key | Description | Required | Default | -| ----------------- | ----------------------------------------------------------------------------------------- | :------: | :--------------| -| `architecture` | The architecture for which to build the snap. | N | `amd64` | -| `channel` | The channel to release the snap to. | N | `candidate` | -| `launchpad-token` | A token with permissions to create Launchpad remote builds. | Y | | -| `store-token` | A token with permissions to upload and release to the specified channel in the Snap Store | Y | | -| `snapcraft-yaml-path` | The path to the Snapcraft YAML file. | N | | - +| Key | Description | Required | Default | +| --------------------- | ----------------------------------------------------------------------------------------- | :------: | :---------- | +| `architecture` | The architecture for which to build the snap. | N | `amd64` | +| `channel` | The channel to release the snap to. | N | `candidate` | +| `launchpad-token` | A token with permissions to create Launchpad remote builds. | Y | | +| `snapcraft-yaml-path` | The path to the Snapcraft YAML file. | N | | +| `store-token` | A token with permissions to upload and release to the specified channel in the Snap Store | Y | | ### Outputs diff --git a/release-to-candidate/action.yaml b/release-to-candidate/action.yaml index 6007c68..570e1ad 100644 --- a/release-to-candidate/action.yaml +++ b/release-to-candidate/action.yaml @@ -17,12 +17,12 @@ inputs: launchpad-token: description: "A token with permissions to create remote builds on Launchpad" required: true - store-token: - description: "A token with permissions to upload to the specified channel" - required: true snapcraft-yaml-path: description: "Custom path to snapcraft.yaml for when it is not in the default location." required: false + store-token: + description: "A token with permissions to upload to the specified channel" + required: true outputs: diff --git a/sync-version/README.md b/sync-version/README.md index d6f6096..18bf8ae 100644 --- a/sync-version/README.md +++ b/sync-version/README.md @@ -28,12 +28,11 @@ jobs: ### Inputs -| Key | Description | Required | -| --------------- | -------------------------------------------------------------------------------------------------- | :------: | -| `token` | A token with permissions to commit to the repository. | Y | -| `update-script` | A script that checks for version updates and updates `snapcraft.yaml` and other files if required. | Y | -| `snapcraft-yaml-path` | The path to the `snapcraft.yaml` file. | N | - +| Key | Description | Required | +| --------------------- | -------------------------------------------------------------------------------------------------- | :------: | +| `snapcraft-yaml-path` | The path to the `snapcraft.yaml` file. | N | +| `token` | A token with permissions to commit to the repository. | Y | +| `update-script` | A script that checks for version updates and updates `snapcraft.yaml` and other files if required. | Y | ### Outputs diff --git a/sync-version/action.yaml b/sync-version/action.yaml index d3da1b1..3747682 100644 --- a/sync-version/action.yaml +++ b/sync-version/action.yaml @@ -6,15 +6,15 @@ branding: color: orange inputs: - update-script: - description: "Bash script that fetches the latest version and updates the source tree as required." - required: true - token: - required: true - description: A token with write privileges to the repository. snapcraft-yaml-path: description: "Custom path to snapcraft.yaml for when it is not in the default location." required: false + token: + required: true + description: A token with write privileges to the repository. + update-script: + description: "Bash script that fetches the latest version and updates the source tree as required." + required: true runs: using: composite diff --git a/test-snap-build/README.md b/test-snap-build/README.md index 57cccc4..7d27acb 100644 --- a/test-snap-build/README.md +++ b/test-snap-build/README.md @@ -34,11 +34,10 @@ jobs: ### Inputs -| Key | Description | Required | Default | -| --------- | -------------------------------------------------------------- | :------: | :------ | -| `install` | If `true`, the built snap is install on the runner after build | N | `false` | -| `snapcraft-yaml-path`| The path to the Snapcraft YAML file. | N | | - +| Key | Description | Required | Default | +| --------------------- | -------------------------------------------------------------- | :------: | :------ | +| `install` | If `true`, the built snap is install on the runner after build | N | `false` | +| `snapcraft-yaml-path` | The path to the Snapcraft YAML file. | N | | ### Outputs From 75ebf044c2a823baa7c9e942e425a27fce19fb40 Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Tue, 5 Dec 2023 11:06:02 +0000 Subject: [PATCH 03/12] feat: add snapcraft-yaml-path option to call-for-testing workflow --- call-for-testing/README.md | 15 +++++++------- call-for-testing/action.yaml | 39 ++++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/call-for-testing/README.md b/call-for-testing/README.md index e82ec61..a7978fe 100644 --- a/call-for-testing/README.md +++ b/call-for-testing/README.md @@ -60,13 +60,14 @@ jobs: ### Inputs -| Key | Description | Required | Default | -| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------: | :---------------- | -| `architectures` | The architectures that the snap supports. | Y | | -| `ci-repo` | The repo to fetch tools/templates from. Only for debugging. | N | `snapcrafters/ci` | -| `channel` | The channel to create the call for testing for. | N | `candidate` | -| `github-token` | A token with permissions to create issues on the repository. | Y | | -| `store-token` | A token with permissions to query the specified channel in the Snap Store. Only required if the revisions to test are not passed to the workflow by the `release-to-candidate` workflow | N | | +| Key | Description | Required | Default | +| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------: | :---------------- | +| `architectures` | The architectures that the snap supports. | Y | | +| `ci-repo` | The repo to fetch tools/templates from. Only for debugging. | N | `snapcrafters/ci` | +| `channel` | The channel to create the call for testing for. | N | `candidate` | +| `github-token` | A token with permissions to create issues on the repository. | Y | | +| `snapcraft-yaml-path` | The path to the `snapcraft.yaml` file. | N | +| `store-token` | A token with permissions to query the specified channel in the Snap Store. Only required if the revisions to test are not passed to the workflow by the `release-to-candidate` workflow | N | | ### Outputs diff --git a/call-for-testing/action.yaml b/call-for-testing/action.yaml index 3b0cc40..18a2353 100644 --- a/call-for-testing/action.yaml +++ b/call-for-testing/action.yaml @@ -20,6 +20,9 @@ inputs: github-token: description: "A token with permissions to create issues on the repository" required: true + snapcraft-yaml-path: + description: "Custom path to snapcraft.yaml for when it is not in the default location." + required: false store-token: description: "A token with permissions to upload to the specified channel" required: false @@ -45,13 +48,41 @@ runs: shell: bash run: | sudo snap install snapcraft --classic + + - name: Find the snapcraft.yaml path + id: yaml-path + shell: bash + run: | + if [[ -n "${{ inputs.snapcraft-yaml-path }} " ]]; then + yaml_path="${{ inputs.snapcraft-yaml-path }}" + else + snapcraft_yaml_paths=( + "snap/snapcraft.yaml" + "snapcraft.yaml" + "build-aux/snap/snapcraft.yaml" + ".snapcraft.yaml" + ) + + for file in "${snapcraft_yaml_paths[@]}"; do + if [[ -f "$file" ]]; then + yaml_path="$file" + fi + done + fi + if [[ ! -n "${yaml-path}" ]]; then + echo "No snapcraft.yaml found" >2 + exit 1 + fi + echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT" + echo "snap-name=$(yq -r '.name' "$yaml_path")" >> "$GITHUB_OUTPUT" - name: Write the arch/rev table shell: bash id: build env: SNAPCRAFT_STORE_CREDENTIALS: ${{ inputs.store-token }} - SNAP_NAME: ${{ github.event.repository.name }} + snap_name: ${{ steps.yaml-path.outputs.snap-name }} + snapcraft_yaml: ${{ steps.yaml-path.outputs.yaml-path }} run: | revisions=() @@ -76,7 +107,7 @@ runs: # Otherwise, get the latest revision for each architecture in the release channel for arch in ${{ inputs.architectures }}; do - rev="$(snapcraft list-revisions "${SNAP_NAME}" --arch "$arch" | grep "latest/${{ inputs.channel }}*" | head -n1 | cut -d' ' -f1)" + rev="$(snapcraft list-revisions "${snap_name}" --arch "$arch" | grep "latest/${{ inputs.channel }}*" | head -n1 | cut -d' ' -f1)" revisions+=("$rev") # Add a row to the HTML table table="${table}${arch}${rev}" @@ -89,7 +120,7 @@ runs: # Get a comma separated list of revisions printf -v joined '%s,' "${revisions[@]}" - version="$(cat snap/snapcraft.yaml | yq -r '.version')" + version="$(cat "$snapcraft_yaml" | yq -r '.version')" echo "version=${version}" >> "$GITHUB_OUTPUT" echo "revisions=${joined%,}" >> "$GITHUB_OUTPUT" echo "table=${table}" >> "$GITHUB_OUTPUT" @@ -104,7 +135,7 @@ runs: id: issue env: GITHUB_TOKEN: ${{ inputs.github-token }} - snap_name: ${{ github.event.repository.name }} + snap_name: ${{ steps.yaml-path.outputs.snap-name }} channel: ${{ inputs.channel }} revisions: ${{ steps.build.outputs.revisions }} table: ${{ steps.build.outputs.table }} From 204f062511ba101164b290b42a3cf1b7cf42b54b Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Tue, 5 Dec 2023 11:09:27 +0000 Subject: [PATCH 04/12] feat: add snapcraft-yaml-path option to get-screenshots workflow --- get-screenshots/README.md | 17 ++++++------- get-screenshots/action.yaml | 48 ++++++++++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/get-screenshots/README.md b/get-screenshots/README.md index edc91da..c65955f 100644 --- a/get-screenshots/README.md +++ b/get-screenshots/README.md @@ -27,14 +27,15 @@ jobs: ### Inputs -| Key | Description | Required | Default | -| ------------------- | ------------------------------------------------------------------------------------------------------------------ | :------: | :---------------------------- | -| `issue-number` | The issue number to post the screenshots to. | Y | | -| `ci-repo` | The repo to fetch tools/templates from. Only for debugging. | N | `snapcrafters/ci` | -| `channel` | The channel to create the call for testing for. | N | `candidate` | -| `github-token` | A token with permissions to common on issues in the repository. | Y | | -| `screenshots-repo` | The repository where screenshots should be uploaded. | N | `snapcrafters/ci-screenshots` | -| `screenshots-token` | A token with permissions to commit screenshots to [ci-screenshots](https://github.com/snapcrafters/ci-screenshots) | Y | | +| Key | Description | Required | Default | +| --------------------- | ------------------------------------------------------------------------------------------------------------------ | :------: | :---------------------------- | +| `issue-number` | The issue number to post the screenshots to. | Y | | +| `ci-repo` | The repo to fetch tools/templates from. Only for debugging. | N | `snapcrafters/ci` | +| `channel` | The channel to create the call for testing for. | N | `candidate` | +| `github-token` | A token with permissions to common on issues in the repository. | Y | | +| `screenshots-repo` | The repository where screenshots should be uploaded. | N | `snapcrafters/ci-screenshots` | +| `screenshots-token` | A token with permissions to commit screenshots to [ci-screenshots](https://github.com/snapcrafters/ci-screenshots) | Y | | +| `snapcraft-yaml-path` | The path to the `snapcraft.yaml` file. | N | ### Outputs diff --git a/get-screenshots/action.yaml b/get-screenshots/action.yaml index cb7add2..1e27e16 100644 --- a/get-screenshots/action.yaml +++ b/get-screenshots/action.yaml @@ -20,6 +20,9 @@ inputs: github-token: description: "A token with permissions to comment on issues" required: true + snapcraft-yaml-path: + description: "Custom path to snapcraft.yaml for when it is not in the default location." + required: false screenshots-repo: description: "The repository where screenshots should be uploaded." default: "snapcrafters/ci-screenshots" @@ -50,11 +53,38 @@ runs: uses: actions/download-artifact@v3 with: name: manifests + + - name: Find the snapcraft.yaml path + id: yaml-path + shell: bash + run: | + if [[ -n "${{ inputs.snapcraft-yaml-path }} " ]]; then + yaml_path="${{ inputs.snapcraft-yaml-path }}" + else + snapcraft_yaml_paths=( + "snap/snapcraft.yaml" + "snapcraft.yaml" + "build-aux/snap/snapcraft.yaml" + ".snapcraft.yaml" + ) + + for file in "${snapcraft_yaml_paths[@]}"; do + if [[ -f "$file" ]]; then + yaml_path="$file" + fi + done + fi + if [[ ! -n "${yaml-path}" ]]; then + echo "No snapcraft.yaml found" >2 + exit 1 + fi + echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT" + echo "snap-name=$(yq -r '.name' "$yaml_path")" >> "$GITHUB_OUTPUT" - name: Prepare VM shell: bash env: - SNAP_NAME: ${{ github.event.repository.name }} + snap_name: ${{ steps.yaml-path.outputs.snap-name }} run: | ghvmctl prepare @@ -62,13 +92,13 @@ runs: if ls manifest-amd64.yaml &>/dev/null; then rev="$(cat manifest-amd64.yaml | yq -r '.revision')" echo "Installing snap revision '${rev}' from build manifest" - ghvmctl install-snap "${SNAP_NAME}" --revision "${rev}" + ghvmctl install-snap "${snap_name}" --revision "${rev}" else echo "Installing snap from 'latest/${{ inputs.channel}}'" - ghvmctl install-snap "${SNAP_NAME}" --channel "latest/${{ inputs.channel }}" + ghvmctl install-snap "${snap_name}" --channel "latest/${{ inputs.channel }}" fi - ghvmctl run-snap "${SNAP_NAME}" + ghvmctl run-snap "${snap_name}" sleep 60 - name: Gather screenshots @@ -80,9 +110,9 @@ runs: - name: Output application logs shell: bash env: - SNAP_NAME: ${{ github.event.repository.name }} + snap_name: ${{ steps.yaml-path.outputs.snap-name }} run: | - ghvmctl exec "cat /home/ubuntu/${SNAP_NAME}.log" + ghvmctl exec "cat /home/ubuntu/${snap_name}.log" - name: Checkout screenshots repo uses: actions/checkout@v4 @@ -95,9 +125,9 @@ runs: shell: bash id: screenshots env: - SNAP_NAME: ${{ github.event.repository.name }} + snap_name: ${{ steps.yaml-path.outputs.snap-name }} run: | - file_prefix="$(date +%Y%m%d)-${SNAP_NAME}-${{ inputs.issue-number }}" + file_prefix="$(date +%Y%m%d)-${snap_name}-${{ inputs.issue-number }}" pushd ci-screenshots mv "$HOME/ghvmctl-screenshots/screenshot-screen.png" "${file_prefix}-screen.png" @@ -107,7 +137,7 @@ runs: git config --global user.name "Snapcrafters Bot" git add -A . - git commit -m "data: screenshots for snapcrafters/${SNAP_NAME}#${{ inputs.issue-number }}" + git commit -m "data: screenshots for snapcrafters/${snap_name}#${{ inputs.issue-number }}" git push origin main echo "screen=https://raw.githubusercontent.com/${{ inputs.screenshots-repo }}/main/${file_prefix}-screen.png" >> "$GITHUB_OUTPUT" From 0bdd878906861b2341b13ebe8a0cf8d35877a899 Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Tue, 5 Dec 2023 11:10:17 +0000 Subject: [PATCH 05/12] fix: remove additional whitespace in conditionals --- call-for-testing/action.yaml | 2 +- get-screenshots/action.yaml | 2 +- promote-to-stable/action.yaml | 2 +- sync-version/action.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/call-for-testing/action.yaml b/call-for-testing/action.yaml index 18a2353..c12a99e 100644 --- a/call-for-testing/action.yaml +++ b/call-for-testing/action.yaml @@ -53,7 +53,7 @@ runs: id: yaml-path shell: bash run: | - if [[ -n "${{ inputs.snapcraft-yaml-path }} " ]]; then + if [[ -n "${{ inputs.snapcraft-yaml-path }}" ]]; then yaml_path="${{ inputs.snapcraft-yaml-path }}" else snapcraft_yaml_paths=( diff --git a/get-screenshots/action.yaml b/get-screenshots/action.yaml index 1e27e16..0cc426a 100644 --- a/get-screenshots/action.yaml +++ b/get-screenshots/action.yaml @@ -58,7 +58,7 @@ runs: id: yaml-path shell: bash run: | - if [[ -n "${{ inputs.snapcraft-yaml-path }} " ]]; then + if [[ -n "${{ inputs.snapcraft-yaml-path }}" ]]; then yaml_path="${{ inputs.snapcraft-yaml-path }}" else snapcraft_yaml_paths=( diff --git a/promote-to-stable/action.yaml b/promote-to-stable/action.yaml index c34d319..302cb22 100644 --- a/promote-to-stable/action.yaml +++ b/promote-to-stable/action.yaml @@ -39,7 +39,7 @@ runs: id: yaml-path shell: bash run: | - if [[ -n "${{ inputs.snapcraft-yaml-path }} " ]]; then + if [[ -n "${{ inputs.snapcraft-yaml-path }}" ]]; then yaml_path="${{ inputs.snapcraft-yaml-path }}" else snapcraft_yaml_paths=( diff --git a/sync-version/action.yaml b/sync-version/action.yaml index 3747682..330f640 100644 --- a/sync-version/action.yaml +++ b/sync-version/action.yaml @@ -28,7 +28,7 @@ runs: id: yaml-path shell: bash run: | - if [[ -n "${{ inputs.snapcraft-yaml-path }} " ]]; then + if [[ -n "${{ inputs.snapcraft-yaml-path }}" ]]; then yaml_path="${{ inputs.snapcraft-yaml-path }}" else snapcraft_yaml_paths=( From 77005a0dab41852875ded4b293601d3399239262 Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Tue, 5 Dec 2023 11:11:28 +0000 Subject: [PATCH 06/12] fix: correct wrong variable name - yaml-path -> yaml_path --- sync-version/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sync-version/action.yaml b/sync-version/action.yaml index 330f640..9115611 100644 --- a/sync-version/action.yaml +++ b/sync-version/action.yaml @@ -72,7 +72,7 @@ runs: prev_version: ${{ steps.yaml-path.outputs.prev-version }} snap_name: ${{ steps.yaml-path.outputs.snap-name }} run: | - new_version="$(yq -r '.version' "$yaml-path")" + new_version="$(yq -r '.version' "$yaml_path")" if [[ ! "$prev_version" == "$new_version" ]]; then version=$new_version fi From a5f48c48975d0fa988eba5d9d185b42e8f4adf68 Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Tue, 5 Dec 2023 11:14:45 +0000 Subject: [PATCH 07/12] feat: add snapcraft-yaml-path option to get-architectures workflow --- get-architectures/README.md | 4 +++- get-architectures/action.yaml | 42 +++++++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/get-architectures/README.md b/get-architectures/README.md index f38f14c..c2ac587 100644 --- a/get-architectures/README.md +++ b/get-architectures/README.md @@ -24,7 +24,9 @@ jobs: ### Inputs -None +| Key | Description | Required | Default | +| --------------------- | -------------------------------------- | :------: | :------ | +| `snapcraft-yaml-path` | The path to the `snapcraft.yaml` file. | N | | ### Outputs diff --git a/get-architectures/action.yaml b/get-architectures/action.yaml index 7a121e4..18753d7 100644 --- a/get-architectures/action.yaml +++ b/get-architectures/action.yaml @@ -5,6 +5,11 @@ branding: icon: code color: orange +inputs: + snapcraft-yaml-path: + description: "Custom path to snapcraft.yaml for when it is not in the default location." + required: false + outputs: architectures: description: "A space-separated list of architectures supported by the snap" @@ -19,20 +24,49 @@ runs: - name: Checkout the source uses: actions/checkout@v4 + - name: Find the snapcraft.yaml path + id: yaml-path + shell: bash + run: | + if [[ -n "${{ inputs.snapcraft-yaml-path }} " ]]; then + yaml_path="${{ inputs.snapcraft-yaml-path }}" + else + snapcraft_yaml_paths=( + "snap/snapcraft.yaml" + "snapcraft.yaml" + "build-aux/snap/snapcraft.yaml" + ".snapcraft.yaml" + ) + + for file in "${snapcraft_yaml_paths[@]}"; do + if [[ -f "$file" ]]; then + yaml_path="$file" + fi + done + fi + if [[ ! -n "${yaml-path}" ]]; then + echo "No snapcraft.yaml found" >2 + exit 1 + fi + echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT" + echo "snap-name=$(yq -r '.name' "$yaml_path")" >> "$GITHUB_OUTPUT" + - name: Compute architectures id: architectures shell: bash + env: + yaml_path: ${{ steps.yaml-path.outputs.yaml-path }} run: | # Get the list as a json array. E.g. ["amd64", "arm64"] - architectures_list="$(cat snap/snapcraft.yaml | yq -r -I=0 -o=json '[.architectures[]]')" + architectures_list="$(cat "$yaml_path" | yq -r -I=0 -o=json '[.architectures[]]')" # Get the list as a space-separated string. E.g. "amd64" "arm64" - architectures="$(cat snap/snapcraft.yaml | yq -r -I=0 -o=csv '[.architectures[]]' | tr ',' ' ')" + architectures="$(cat "$yaml_path" | yq -r -I=0 -o=csv '[.architectures[]]' | tr ',' ' ')" # Handle the case where architectures is a list of objects if echo "$architectures" | grep -q "build-on"; then - architectures_list="$(cat snap/snapcraft.yaml | yq -r -I=0 -o=json '[.architectures[]."build-on"]')" - architectures="$(cat snap/snapcraft.yaml | yq -r -I=0 -o=csv '[.architectures[]."build-on"]' | tr ',' ' ')" + architectures_list="$(cat "$yaml_path" | yq -r -I=0 -o=json '[.architectures[]."build-on"]')" + architectures="$(cat "$yaml_path" | yq -r -I=0 -o=csv '[.architectures[]."build-on"]' | tr ',' ' ')" fi echo "architectures_list=$architectures_list" >> "$GITHUB_OUTPUT" From 9ac938205708bbf54578a04d3491bcfc224459d2 Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Tue, 5 Dec 2023 11:58:44 +0000 Subject: [PATCH 08/12] fix: fix whitespace issue in conditional --- get-architectures/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get-architectures/action.yaml b/get-architectures/action.yaml index 18753d7..98be6f4 100644 --- a/get-architectures/action.yaml +++ b/get-architectures/action.yaml @@ -28,7 +28,7 @@ runs: id: yaml-path shell: bash run: | - if [[ -n "${{ inputs.snapcraft-yaml-path }} " ]]; then + if [[ -n "${{ inputs.snapcraft-yaml-path }}" ]]; then yaml_path="${{ inputs.snapcraft-yaml-path }}" else snapcraft_yaml_paths=( From b5e402f501bd3f0a1c259c9255eba4f2e1d736d6 Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Tue, 5 Dec 2023 12:03:52 +0000 Subject: [PATCH 09/12] build: add linting formatting tools --- .github/dependabot.yml | 7 +++++++ .github/shellcheck-actions.sh | 19 +++++++++++++++++++ .github/workflows/lint.yaml | 33 +++++++++++++++++++++++++++++++++ Makefile | 15 +++++++++++++++ README.md | 22 ++++++++++++++++++++++ 5 files changed, 96 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .github/shellcheck-actions.sh create mode 100644 .github/workflows/lint.yaml create mode 100644 Makefile diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..ac22b57 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + # Check for updates to GitHub Actions every week + interval: "monthly" diff --git a/.github/shellcheck-actions.sh b/.github/shellcheck-actions.sh new file mode 100644 index 0000000..d44381e --- /dev/null +++ b/.github/shellcheck-actions.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -euo pipefail +info() { echo -e "\e[92m[+] $@\e[0m"; } +error() { echo >&2 -e "\e[31m[!] $@\e[0m"; exit 1; } +warn() { echo -e "\e[33m[-] $@\e[0m"; } +DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) + +export SHELLCHECK_OPTS=( + "-s" "bash" + "-e" "2296" + "-e" "2157" + "-e" "2129" + "-e" "2154" +) + +for f in "$DIR"/../**/*.yaml; do + echo $f + yq '.runs.steps[].run' "$f" | grep -v -P "^null$" | shellcheck "${SHELLCHECK_OPTS[@]}" - +done diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..f8cf312 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,33 @@ +name: Lint + +on: + pull_request: + push: + +jobs: + lint: + name: Lint + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + + - name: Run linters + run: | + make lint + + - name: Run formatters + run: | + make format + + - name: Check for modifications to generated files + run: | + if [[ -n "$(git status -s)" ]]; then + echo "Please run 'make format' then commit/push changes" + echo + git diff + exit 1 + fi diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..afd3da6 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +.PHONY: help +help: + @echo "Usage:" + @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' + +.PHONY: lint +lint: +## lint: Lint the codebase with Prettier + npx prettier --print-width=99 --check . + bash ${CURDIR}/.github/shellcheck-actions.sh + +.PHONY: format +format: +## format: Formats both Markdown documents and YAML documents to preferred repository style. + npx prettier --print-width=99 --write . diff --git a/README.md b/README.md index f72c539..738e83b 100644 --- a/README.md +++ b/README.md @@ -23,3 +23,25 @@ You can see examples of these actions in use in the following repos: - [signal-desktop](https://github.com/snapcrafters/signal-desktop/main/.github/workflows) - [mattermost-desktop](https://github.com/snapcrafters/mattermost-desktop/main/.github/workflows) - [discord](https://github.com/snapcrafters/discord/main/.github/workflows) + +## Contributing + +If you'd like to contribute to this repository, please feel free to fork and create a pull request. + +There are a few style guidelines to keep in mind: + +- Code should be linted using [Prettier](https://prettier.io/). You can achieve this with `make +lint` and `make format`. The only requirements are [`npx`](https://www.npmjs.com/package/npx) and + [`shellcheck`](https://github.com/koalaman/shellcheck). +- When defining inputs/outputs in `action.yaml`, or listing them in the tables within `README.md`, + they should be listed in alphabetical order for easy reading and updating. +- Github Action inputs/outputs should be named all lowercase, separated by `-` where needed. The + applies to inputs/outputs to actions themselves, and for individual steps within the actions. For + example: `snap-name` or `token`. +- Environment variables referring to repository level secrets and variables should be named all + uppercase, and separated by `_`. For example: `SNAPCRAFTERS_BOT_COMMIT`. +- Step/job level environment variables should be named all lowercase, and separated by `_`. For + example: `snap_name` or `yaml_path`. +- All `bash` variables should be quoted. +- Scripts of all kinds, including those within actions `run:|` directives should follow the [Google + styleguide](https://google.github.io/styleguide/shellguide.html) From a87d810ad86f243945a1c0bb471bea56f62f1cbf Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Tue, 5 Dec 2023 12:25:22 +0000 Subject: [PATCH 10/12] ci: target main branch with ci checks --- .github/workflows/lint.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index f8cf312..5db3906 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -2,7 +2,11 @@ name: Lint on: pull_request: + branches: + - main push: + branches: + - main jobs: lint: From 799843a4bb4d7e618d89ad7aa9f5a2b2d8a437d3 Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Tue, 5 Dec 2023 12:04:08 +0000 Subject: [PATCH 11/12] style: apply auto-formatting using prettier --- call-for-testing/action.yaml | 6 +++--- get-architectures/action.yaml | 2 +- get-screenshots/action.yaml | 4 ++-- promote-to-stable/action.yaml | 4 ++-- release-to-candidate/action.yaml | 10 ++++------ test-snap-build/action.yaml | 8 ++++---- 6 files changed, 16 insertions(+), 18 deletions(-) diff --git a/call-for-testing/action.yaml b/call-for-testing/action.yaml index c12a99e..55f09cd 100644 --- a/call-for-testing/action.yaml +++ b/call-for-testing/action.yaml @@ -43,12 +43,12 @@ runs: uses: actions/download-artifact@v3 with: name: "manifests" - + - name: Setup snapcraft shell: bash run: | sudo snap install snapcraft --classic - + - name: Find the snapcraft.yaml path id: yaml-path shell: bash @@ -129,7 +129,7 @@ runs: shell: bash run: | wget -qO template.md "https://raw.githubusercontent.com/${{ inputs.ci-repo }}/main/call-for-testing/template.md" - + - name: Create call for testing issue uses: JasonEtco/create-an-issue@v2 id: issue diff --git a/get-architectures/action.yaml b/get-architectures/action.yaml index 98be6f4..1c93851 100644 --- a/get-architectures/action.yaml +++ b/get-architectures/action.yaml @@ -59,7 +59,7 @@ runs: run: | # Get the list as a json array. E.g. ["amd64", "arm64"] architectures_list="$(cat "$yaml_path" | yq -r -I=0 -o=json '[.architectures[]]')" - + # Get the list as a space-separated string. E.g. "amd64" "arm64" architectures="$(cat "$yaml_path" | yq -r -I=0 -o=csv '[.architectures[]]' | tr ',' ' ')" diff --git a/get-screenshots/action.yaml b/get-screenshots/action.yaml index 0cc426a..35434c5 100644 --- a/get-screenshots/action.yaml +++ b/get-screenshots/action.yaml @@ -53,7 +53,7 @@ runs: uses: actions/download-artifact@v3 with: name: manifests - + - name: Find the snapcraft.yaml path id: yaml-path shell: bash @@ -116,7 +116,7 @@ runs: - name: Checkout screenshots repo uses: actions/checkout@v4 - with: + with: repository: ${{ inputs.screenshots-repo }} path: ci-screenshots token: ${{ inputs.screenshots-token }} diff --git a/promote-to-stable/action.yaml b/promote-to-stable/action.yaml index 302cb22..9201f26 100644 --- a/promote-to-stable/action.yaml +++ b/promote-to-stable/action.yaml @@ -34,7 +34,7 @@ runs: shell: bash run: | sudo snap install --classic snapcraft - + - name: Find the snapcraft.yaml path id: yaml-path shell: bash @@ -70,7 +70,7 @@ runs: shell: bash run: | echo "The command was '${{ steps.command.outputs.command-name }}' with arguments '${{ steps.command.outputs.command-arguments }}'" - + arguments=(${{ steps.command.outputs.command-arguments }}) revision=${arguments[0]} channel=${arguments[1]} diff --git a/release-to-candidate/action.yaml b/release-to-candidate/action.yaml index 570e1ad..4d55d99 100644 --- a/release-to-candidate/action.yaml +++ b/release-to-candidate/action.yaml @@ -24,7 +24,6 @@ inputs: description: "A token with permissions to upload to the specified channel" required: true - outputs: revision: description: "The revision of the uploaded snap" @@ -50,7 +49,7 @@ runs: - name: Find the snapcraft.yaml path id: yaml-path shell: bash - run : | + run: | if [[ -n "${{ inputs.snapcraft-yaml-path }}" ]]; then yaml_path="${{ inputs.snapcraft-yaml-path }}" else @@ -74,7 +73,6 @@ runs: echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT" echo "snap-name=$(yq -r '.name' "$yaml_path")" >> "$GITHUB_OUTPUT" - - name: Build the snap (${{ inputs.architecture }}) id: build shell: bash @@ -82,7 +80,7 @@ runs: yaml_path: ${{ steps.yaml-path.outputs.yaml-path }} name: ${{ steps.yaml-path.outputs.snap-name }} arch: ${{ inputs.architecture }} - run : | + run: | # Remove the architecture definition from the snapcraft.yaml due to: # https://bugs.launchpad.net/snapcraft/+bug/1885150 yq -i 'del(.architectures)' "$yaml_path" @@ -108,7 +106,7 @@ runs: shell: bash env: yaml_path: ${{ steps.yaml-path.outputs.yaml-path }} - run : | + run: | # Populate defaults echo "classic=false" >> "$GITHUB_OUTPUT" @@ -120,7 +118,7 @@ runs: # Declare the common locations for plugs/slots declarations plugs_files=("plug-declaration.json" ".github/plug-declaration.json") slots_files=("slot-declaration.json" ".github/slot-declaration.json") - + for file in "${plugs_files[@]}"; do if [[ -f "$file" ]]; then echo "plugs=$file" >> "$GITHUB_OUTPUT" diff --git a/test-snap-build/action.yaml b/test-snap-build/action.yaml index 78e39b1..f4941d2 100644 --- a/test-snap-build/action.yaml +++ b/test-snap-build/action.yaml @@ -11,7 +11,7 @@ inputs: default: "false" required: false snapcraft-yaml-path: - description: "Custom path to snapcraft.yaml for when it is not in the default location." + description: "Custom path to snapcraft.yaml for when it is not in the default location." required: false runs: @@ -50,14 +50,14 @@ runs: uses: snapcore/action-build@v1 id: build with: - path: ${{ steps.yaml-path.outputs.yaml-path }} + path: ${{ steps.yaml-path.outputs.yaml-path }} - name: Parse snap review information id: parse shell: bash env: yaml_path: ${{ steps.yaml-path.outputs.yaml-path }} - run : | + run: | # Populate defaults echo "classic=false" >> "$GITHUB_OUTPUT" @@ -69,7 +69,7 @@ runs: # Declare the common locations for plugs/slots declarations plugs_files=("plug-declaration.json" ".github/plug-declaration.json") slots_files=("slot-declaration.json" ".github/slot-declaration.json") - + for file in "${plugs_files[@]}"; do if [[ -f "$file" ]]; then echo "plugs=$file" >> "$GITHUB_OUTPUT" From 7e1ff68cf1673f9e3b4de5c0b8b8bec08fc37338 Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Tue, 5 Dec 2023 12:06:40 +0000 Subject: [PATCH 12/12] style: apply fixes suggested by linter --- .github/shellcheck-actions.sh | 4 +--- call-for-testing/action.yaml | 13 +++++++------ get-architectures/action.yaml | 12 ++++++------ get-screenshots/action.yaml | 8 ++++---- promote-to-stable/action.yaml | 15 ++++++++------- release-to-candidate/action.yaml | 4 ++-- sync-version/action.yaml | 9 +++++---- test-snap-build/action.yaml | 6 +++--- 8 files changed, 36 insertions(+), 35 deletions(-) diff --git a/.github/shellcheck-actions.sh b/.github/shellcheck-actions.sh index d44381e..1355994 100644 --- a/.github/shellcheck-actions.sh +++ b/.github/shellcheck-actions.sh @@ -1,8 +1,6 @@ #!/usr/bin/env bash set -euo pipefail info() { echo -e "\e[92m[+] $@\e[0m"; } -error() { echo >&2 -e "\e[31m[!] $@\e[0m"; exit 1; } -warn() { echo -e "\e[33m[-] $@\e[0m"; } DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) export SHELLCHECK_OPTS=( @@ -14,6 +12,6 @@ export SHELLCHECK_OPTS=( ) for f in "$DIR"/../**/*.yaml; do - echo $f + info "Linting scripts in $f" yq '.runs.steps[].run' "$f" | grep -v -P "^null$" | shellcheck "${SHELLCHECK_OPTS[@]}" - done diff --git a/call-for-testing/action.yaml b/call-for-testing/action.yaml index 55f09cd..bd6d0d5 100644 --- a/call-for-testing/action.yaml +++ b/call-for-testing/action.yaml @@ -69,8 +69,8 @@ runs: fi done fi - if [[ ! -n "${yaml-path}" ]]; then - echo "No snapcraft.yaml found" >2 + if [[ -z "${yaml_path}" ]]; then + echo "No snapcraft.yaml found" exit 1 fi echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT" @@ -94,10 +94,10 @@ runs: echo "Found build manifests - populating template with revisions from the manifests" # Iterate over the manifest files and write the table rows for each architecture - for file in $(ls manifest-*.yaml); do + for file in manifest-*.yaml; do # Parse the arch and the revision - arch="$(cat "${file}" | yq -r '.architecture')" - rev="$(cat "${file}" | yq -r '.revision')" + arch="$(yq -r '.architecture' "${file}")" + rev="$(yq -r '.revision' "${file}")" # Write the table row and add the revision to the list we're tracking table="${table}${arch}${rev}" revisions+=("$rev") @@ -106,6 +106,7 @@ runs: echo "No build manifests found - populating template with information from the store" # Otherwise, get the latest revision for each architecture in the release channel + # shellcheck disable=SC1083 for arch in ${{ inputs.architectures }}; do rev="$(snapcraft list-revisions "${snap_name}" --arch "$arch" | grep "latest/${{ inputs.channel }}*" | head -n1 | cut -d' ' -f1)" revisions+=("$rev") @@ -120,7 +121,7 @@ runs: # Get a comma separated list of revisions printf -v joined '%s,' "${revisions[@]}" - version="$(cat "$snapcraft_yaml" | yq -r '.version')" + version="$(yq -r '.version' "$snapcraft_yaml")" echo "version=${version}" >> "$GITHUB_OUTPUT" echo "revisions=${joined%,}" >> "$GITHUB_OUTPUT" echo "table=${table}" >> "$GITHUB_OUTPUT" diff --git a/get-architectures/action.yaml b/get-architectures/action.yaml index 1c93851..f02ce00 100644 --- a/get-architectures/action.yaml +++ b/get-architectures/action.yaml @@ -44,8 +44,8 @@ runs: fi done fi - if [[ ! -n "${yaml-path}" ]]; then - echo "No snapcraft.yaml found" >2 + if [[ -z "${yaml_path}" ]]; then + echo "No snapcraft.yaml found" exit 1 fi echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT" @@ -58,15 +58,15 @@ runs: yaml_path: ${{ steps.yaml-path.outputs.yaml-path }} run: | # Get the list as a json array. E.g. ["amd64", "arm64"] - architectures_list="$(cat "$yaml_path" | yq -r -I=0 -o=json '[.architectures[]]')" + architectures_list="$(yq -r -I=0 -o=json '[.architectures[]]' | "$yaml_path")" # Get the list as a space-separated string. E.g. "amd64" "arm64" - architectures="$(cat "$yaml_path" | yq -r -I=0 -o=csv '[.architectures[]]' | tr ',' ' ')" + architectures="$(yq -r -I=0 -o=csv '[.architectures[]]' "$yaml_path" | tr ',' ' ')" # Handle the case where architectures is a list of objects if echo "$architectures" | grep -q "build-on"; then - architectures_list="$(cat "$yaml_path" | yq -r -I=0 -o=json '[.architectures[]."build-on"]')" - architectures="$(cat "$yaml_path" | yq -r -I=0 -o=csv '[.architectures[]."build-on"]' | tr ',' ' ')" + architectures_list="$(yq -r -I=0 -o=json '[.architectures[]."build-on"]' "$yaml_path")" + architectures="$(yq -r -I=0 -o=csv '[.architectures[]."build-on"]' "$yaml_path" | tr ',' ' ')" fi echo "architectures_list=$architectures_list" >> "$GITHUB_OUTPUT" diff --git a/get-screenshots/action.yaml b/get-screenshots/action.yaml index 35434c5..025dc9f 100644 --- a/get-screenshots/action.yaml +++ b/get-screenshots/action.yaml @@ -74,8 +74,8 @@ runs: fi done fi - if [[ ! -n "${yaml-path}" ]]; then - echo "No snapcraft.yaml found" >2 + if [[ -z "${yaml_path}" ]]; then + echo "No snapcraft.yaml found" exit 1 fi echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT" @@ -90,7 +90,7 @@ runs: # If we got a manifest file then parse the revision from it if ls manifest-amd64.yaml &>/dev/null; then - rev="$(cat manifest-amd64.yaml | yq -r '.revision')" + rev="$(yq -r '.revision' manifest-amd64.yaml)" echo "Installing snap revision '${rev}' from build manifest" ghvmctl install-snap "${snap_name}" --revision "${rev}" else @@ -129,7 +129,7 @@ runs: run: | file_prefix="$(date +%Y%m%d)-${snap_name}-${{ inputs.issue-number }}" - pushd ci-screenshots + pushd ci-screenshots || exit 1 mv "$HOME/ghvmctl-screenshots/screenshot-screen.png" "${file_prefix}-screen.png" mv "$HOME/ghvmctl-screenshots/screenshot-window.png" "${file_prefix}-window.png" diff --git a/promote-to-stable/action.yaml b/promote-to-stable/action.yaml index 9201f26..d1aad77 100644 --- a/promote-to-stable/action.yaml +++ b/promote-to-stable/action.yaml @@ -55,8 +55,8 @@ runs: fi done fi - if [[ ! -n "${yaml-path}" ]]; then - echo "No snapcraft.yaml found" >2 + if [[ -z "${yaml_path}" ]]; then + echo "No snapcraft.yaml found" exit 1 fi echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT" @@ -71,6 +71,7 @@ runs: run: | echo "The command was '${{ steps.command.outputs.command-name }}' with arguments '${{ steps.command.outputs.command-arguments }}'" + # shellcheck disable=SC1083,SC2206 arguments=(${{ steps.command.outputs.command-arguments }}) revision=${arguments[0]} channel=${arguments[1]} @@ -93,20 +94,20 @@ runs: fi # Iterate over each specified revision and release - revs=$(echo $revision | tr "," "\n") + revs=$(echo "$revision" | tr "," "\n") released_revs=() for r in $revs; do - snapcraft release $snap_name "$r" "$channel" + snapcraft release "$snap_name" "$r" "$channel" released_revs+=("$r") done # Get a comma separated list of released revisions printf -v joined '%s,' "${released_revs[@]}" - echo "revisions=${joined%,}" >> $GITHUB_OUTPUT - echo "channel=$channel" >> $GITHUB_OUTPUT - echo "done=$done" >> $GITHUB_OUTPUT + echo "revisions=${joined%,}" >> "$GITHUB_OUTPUT" + echo "channel=$channel" >> "$GITHUB_OUTPUT" + echo "done=$done" >> "$GITHUB_OUTPUT" - name: Comment on call for testing issue uses: actions/github-script@v7 diff --git a/release-to-candidate/action.yaml b/release-to-candidate/action.yaml index 4d55d99..5501ecd 100644 --- a/release-to-candidate/action.yaml +++ b/release-to-candidate/action.yaml @@ -66,8 +66,8 @@ runs: fi done fi - if [[ ! -n "${yaml_path}" ]]; then - echo "No snapcraft.yaml found" >2 + if [[ -z "${yaml_path}" ]]; then + echo "No snapcraft.yaml found" exit 1 fi echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT" diff --git a/sync-version/action.yaml b/sync-version/action.yaml index 9115611..9e523fc 100644 --- a/sync-version/action.yaml +++ b/sync-version/action.yaml @@ -44,8 +44,8 @@ runs: fi done fi - if [[ ! -n "${yaml-path}" ]]; then - echo "No snapcraft.yaml found" >2 + if [[ -z "${yaml_path}" ]]; then + echo "No snapcraft.yaml found" exit 1 fi echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT" @@ -55,14 +55,15 @@ runs: - name: Run update script shell: bash run: | + # shellcheck disable=SC2288,SC2086,SC1083 ${{ inputs.update-script }} - name: Check for modified files shell: bash id: git-check run: | - MODIFIED=$([ -z "`git status --porcelain`" ] && echo "false" || echo "true") - echo "modified=$MODIFIED" >> $GITHUB_OUTPUT + MODIFIED=$([ -z "$(git status --porcelain)" ] && echo "false" || echo "true") + echo "modified=$MODIFIED" >> "$GITHUB_OUTPUT" - name: Commit changes if: steps.git-check.outputs.modified == 'true' diff --git a/test-snap-build/action.yaml b/test-snap-build/action.yaml index f4941d2..2abacfd 100644 --- a/test-snap-build/action.yaml +++ b/test-snap-build/action.yaml @@ -40,8 +40,8 @@ runs: fi done fi - if [[ ! -n "${yaml_path}" ]]; then - echo "No snapcraft.yaml found" >2 + if [[ -z "${yaml_path}" ]]; then + echo "No snapcraft.yaml found" exit 1 fi echo "yaml-path=${yaml_path}" >> "$GITHUB_OUTPUT" @@ -94,4 +94,4 @@ runs: if: ${{ inputs.install == 'true' }} shell: bash run: | - sudo snap install --classic --dangerous ${{ steps.build.outputs.snap }} + sudo snap install --classic --dangerous "${{ steps.build.outputs.snap }}"