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..1355994 --- /dev/null +++ b/.github/shellcheck-actions.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -euo pipefail +info() { echo -e "\e[92m[+] $@\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 + info "Linting scripts in $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..5db3906 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,37 @@ +name: Lint + +on: + pull_request: + branches: + - main + push: + branches: + - main + +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) 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..bd6d0d5 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 @@ -40,18 +43,46 @@ 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 + 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 [[ -z "${yaml_path}" ]]; then + echo "No snapcraft.yaml found" + 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=() @@ -63,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") @@ -75,8 +106,9 @@ 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)" + 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 +121,7 @@ runs: # Get a comma separated list of revisions printf -v joined '%s,' "${revisions[@]}" - version="$(cat snap/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" @@ -98,13 +130,13 @@ 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 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 }} 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..f02ce00 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 [[ -z "${yaml_path}" ]]; then + echo "No snapcraft.yaml found" + 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="$(yq -r -I=0 -o=json '[.architectures[]]' | "$yaml_path")" + # 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="$(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 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="$(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/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..025dc9f 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" @@ -51,24 +54,51 @@ runs: 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 [[ -z "${yaml_path}" ]]; then + echo "No snapcraft.yaml found" + 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 # 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}" + 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,13 +110,13 @@ 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 - with: + with: repository: ${{ inputs.screenshots-repo }} path: ci-screenshots token: ${{ inputs.screenshots-token }} @@ -95,11 +125,11 @@ 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 + 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" @@ -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" 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..d1aad77 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 @@ -35,15 +35,43 @@ runs: 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 [[ -z "${yaml_path}" ]]; then + echo "No snapcraft.yaml found" + 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 }}'" - + + # shellcheck disable=SC1083,SC2206 arguments=(${{ steps.command.outputs.command-arguments }}) revision=${arguments[0]} channel=${arguments[1]} @@ -66,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/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..5501ecd 100644 --- a/release-to-candidate/action.yaml +++ b/release-to-candidate/action.yaml @@ -17,13 +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: revision: @@ -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 @@ -67,14 +66,13 @@ 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" 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/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 907c92d..9e523fc 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 @@ -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=( @@ -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' @@ -70,17 +71,17 @@ 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")" + new_version="$(yq -r '.version' "$yaml_path")" if [[ ! "$prev_version" == "$new_version" ]]; then version=$new_version fi 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 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 diff --git a/test-snap-build/action.yaml b/test-snap-build/action.yaml index 78e39b1..2abacfd 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: @@ -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" @@ -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" @@ -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 }}"