diff --git a/README.md b/README.md index 738e83b..b8d0b5f 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ listed below has it's own README - [snapcrafters/ci/call-for-testing](call-for-testing/README.md) - [snapcrafters/ci/get-architectures](get-architectures/README.md) - [snapcrafters/ci/get-screenshots](get-screenshots/README.md) +- [snapcrafters/ci/parse-snapcraft-yaml](parse-snapcraft-yaml/README.md) - [snapcrafters/ci/promote-to-stable](promote-to-stable/README.md) - [snapcrafters/ci/release-to-candidate](release-to-candidate/README.md) - [snapcrafters/ci/sync-version](sync-version/README.md) diff --git a/call-for-testing/action.yaml b/call-for-testing/action.yaml index bd6d0d5..3ec2742 100644 --- a/call-for-testing/action.yaml +++ b/call-for-testing/action.yaml @@ -49,40 +49,19 @@ runs: 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: Find and parse snapcraft.yaml + id: snapcraft-yaml + uses: snapcrafters/ci/parse-snapcraft-yaml@main + with: + snapcraft-yaml-path: ${{ inputs.snapcraft-yaml-path }} - name: Write the arch/rev table shell: bash id: build env: SNAPCRAFT_STORE_CREDENTIALS: ${{ inputs.store-token }} - snap_name: ${{ steps.yaml-path.outputs.snap-name }} - snapcraft_yaml: ${{ steps.yaml-path.outputs.yaml-path }} + snap_name: ${{ steps.snapcraft-yaml.outputs.snap-name }} + snapcraft_yaml: ${{ steps.snapcraft-yaml.outputs.yaml-path }} run: | revisions=() @@ -136,7 +115,7 @@ runs: id: issue env: GITHUB_TOKEN: ${{ inputs.github-token }} - snap_name: ${{ steps.yaml-path.outputs.snap-name }} + snap_name: ${{ steps.snapcraft-yaml.outputs.snap-name }} channel: ${{ inputs.channel }} revisions: ${{ steps.build.outputs.revisions }} table: ${{ steps.build.outputs.table }} diff --git a/get-architectures/action.yaml b/get-architectures/action.yaml index 2599f94..78edd1f 100644 --- a/get-architectures/action.yaml +++ b/get-architectures/action.yaml @@ -24,38 +24,17 @@ 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: Find and parse snapcraft.yaml + id: snapcraft-yaml + uses: snapcrafters/ci/parse-snapcraft-yaml@main + with: + snapcraft-yaml-path: ${{ inputs.snapcraft-yaml-path }} - name: Compute architectures id: architectures shell: bash env: - yaml_path: ${{ steps.yaml-path.outputs.yaml-path }} + yaml_path: ${{ steps.snapcraft-yaml.outputs.yaml-path }} run: | # Get the list as a json array. E.g. ["amd64", "arm64"] architectures_list="$(yq -r -I=0 -o=json '[.architectures[]]' "$yaml_path")" diff --git a/get-screenshots/action.yaml b/get-screenshots/action.yaml index 025dc9f..b74c864 100644 --- a/get-screenshots/action.yaml +++ b/get-screenshots/action.yaml @@ -54,37 +54,16 @@ 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: Find and parse snapcraft.yaml + id: snapcraft-yaml + uses: snapcrafters/ci/parse-snapcraft-yaml@main + with: + snapcraft-yaml-path: ${{ inputs.snapcraft-yaml-path }} - name: Prepare VM shell: bash env: - snap_name: ${{ steps.yaml-path.outputs.snap-name }} + snap_name: ${{ steps.snapcraft-yaml.outputs.snap-name }} run: | ghvmctl prepare @@ -110,7 +89,7 @@ runs: - name: Output application logs shell: bash env: - snap_name: ${{ steps.yaml-path.outputs.snap-name }} + snap_name: ${{ steps.snapcraft-yaml.outputs.snap-name }} run: | ghvmctl exec "cat /home/ubuntu/${snap_name}.log" @@ -125,7 +104,7 @@ runs: shell: bash id: screenshots env: - snap_name: ${{ steps.yaml-path.outputs.snap-name }} + snap_name: ${{ steps.snapcraft-yaml.outputs.snap-name }} run: | file_prefix="$(date +%Y%m%d)-${snap_name}-${{ inputs.issue-number }}" diff --git a/parse-snapcraft-yaml/README.md b/parse-snapcraft-yaml/README.md new file mode 100644 index 0000000..a7841e4 --- /dev/null +++ b/parse-snapcraft-yaml/README.md @@ -0,0 +1,40 @@ +# snapcrafters/ci/parse-snapcraft-yaml + +This action is more for use internally than otherwise. It's purpose is to either find a snapcraft.yaml file from a list of known common locations in a repository, or take the path to a snapcraft.yaml, then parse some information from it and provide that information as outputs. + +You only need to specify the `snapcraft-yaml-path` input if your `snapcraft.yaml` is not in one of the following locations: + +- `.snapcraft.yaml` +- `build-aux/snap/snapcraft.yaml` +- `snap/snapcraft.yaml` +- `snapcraft.yaml` + +## Usage + +```yaml +# ... +jobs: + parse-snapcraft-yaml: + name: 🖥 Parse the snapcraft yaml file + runs-on: ubuntu-latest + steps: + - name: Find and parse snapcraft.yaml + id: snapcraft-yaml + uses: snapcrafters/ci/parse-snapcraft-yaml@main +``` + +## API + +### Inputs + +| Key | Description | Required | Default | +| --------------------- | -------------------------------------- | :------: | :------ | +| `snapcraft-yaml-path` | The path to the `snapcraft.yaml` file. | N | | + +### Outputs + +| Key | Description | Example | +| ----------- | ------------------------------------------------------ | --------------------- | +| `snap_name` | The name of the snap as declared in the snapcraft.yaml | `signal-desktop` | +| `version` | The version declared in the snapcraft.yaml file | `6.41.0` | +| `yaml_path` | The path to the snapcraft.yaml for the project | `snap/snapcraft.yaml` | diff --git a/parse-snapcraft-yaml/action.yaml b/parse-snapcraft-yaml/action.yaml new file mode 100644 index 0000000..cb79f4a --- /dev/null +++ b/parse-snapcraft-yaml/action.yaml @@ -0,0 +1,58 @@ +name: Parse Snapcraft YAML +description: Finds the snapcraft yaml for a repo and parses key information from it. +author: Snapcrafters +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: + snap-name: + description: "The name of the snap as declared in the snapcraft.yaml" + value: ${{ steps.parse.outputs.snap-name }} + version: + description: "The version declared in the snapcraft.yaml file" + value: ${{ steps.parse.outputs.version }} + yaml-path: + description: "The path to the snapcraft.yaml for the project" + value: ${{ steps.parse.outputs.yaml-path }} + +runs: + using: composite + steps: + - name: Checkout the source + uses: actions/checkout@v4 + + - name: Find and parse snapcraft.yaml + id: parse + shell: bash + run: | + if [[ -n "${{ inputs.snapcraft-yaml-path }}" ]]; then + yaml_path="${{ inputs.snapcraft-yaml-path }}" + else + common_paths=( + ".snapcraft.yaml" + "build-aux/snap/snapcraft.yaml" + "snap/snapcraft.yaml" + "snapcraft.yaml" + ) + + for file in "${common_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" + echo "version=$(yq -r '.version' "$yaml_path")" >> "$GITHUB_OUTPUT" diff --git a/promote-to-stable/action.yaml b/promote-to-stable/action.yaml index 9bc0ebf..24de7f4 100644 --- a/promote-to-stable/action.yaml +++ b/promote-to-stable/action.yaml @@ -52,38 +52,17 @@ 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: Find and parse snapcraft.yaml + id: snapcraft-yaml + uses: snapcrafters/ci/parse-snapcraft-yaml@main + with: + snapcraft-yaml-path: ${{ inputs.snapcraft-yaml-path }} - name: Promote snap to latest/stable id: promote env: SNAPCRAFT_STORE_CREDENTIALS: ${{ inputs.store-token }} - snap_name: ${{ steps.yaml-path.outputs.snap-name }} + snap_name: ${{ steps.snapcraft-yaml.outputs.snap-name }} valid_revisions: ${{ steps.valid-revisions.outputs.result }} shell: bash run: | diff --git a/release-to-candidate/action.yaml b/release-to-candidate/action.yaml index 5501ecd..670c447 100644 --- a/release-to-candidate/action.yaml +++ b/release-to-candidate/action.yaml @@ -46,40 +46,19 @@ runs: git config --global user.email "github-actions@github.com" git config --global user.name "Github Actions" - - 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: Find and parse snapcraft.yaml + id: snapcraft-yaml + uses: snapcrafters/ci/parse-snapcraft-yaml@main + with: + snapcraft-yaml-path: ${{ inputs.snapcraft-yaml-path }} - name: Build the snap (${{ inputs.architecture }}) id: build shell: bash env: - yaml_path: ${{ steps.yaml-path.outputs.yaml-path }} - name: ${{ steps.yaml-path.outputs.snap-name }} arch: ${{ inputs.architecture }} + name: ${{ steps.snapcraft-yaml.outputs.snap-name }} + yaml_path: ${{ steps.snapcraft-yaml.outputs.yaml-path }} run: | # Remove the architecture definition from the snapcraft.yaml due to: # https://bugs.launchpad.net/snapcraft/+bug/1885150 @@ -105,7 +84,7 @@ runs: id: parse shell: bash env: - yaml_path: ${{ steps.yaml-path.outputs.yaml-path }} + yaml_path: ${{ steps.snapcraft-yaml.outputs.yaml-path }} run: | # Populate defaults echo "classic=false" >> "$GITHUB_OUTPUT" diff --git a/sync-version/action.yaml b/sync-version/action.yaml index 9e523fc..4defd55 100644 --- a/sync-version/action.yaml +++ b/sync-version/action.yaml @@ -24,33 +24,11 @@ runs: with: token: ${{ inputs.token }} - - 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" - echo "prev-version=$(yq -r '.version' "$yaml_path")" >> "$GITHUB_OUTPUT" + - name: Find and parse snapcraft.yaml + id: snapcraft-yaml + uses: snapcrafters/ci/parse-snapcraft-yaml@main + with: + snapcraft-yaml-path: ${{ inputs.snapcraft-yaml-path }} - name: Run update script shell: bash @@ -69,18 +47,18 @@ runs: if: steps.git-check.outputs.modified == 'true' shell: bash 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.snapcraft-yaml.outputs.snap-name }} + version: ${{ steps.snapcraft-yaml.outputs.version }} + yaml_path: ${{ steps.snapcraft-yaml.outputs.yaml-path }} run: | new_version="$(yq -r '.version' "$yaml_path")" - if [[ ! "$prev_version" == "$new_version" ]]; then + if [[ ! "$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" fi diff --git a/test-snap-build/action.yaml b/test-snap-build/action.yaml index 2abacfd..fc71b32 100644 --- a/test-snap-build/action.yaml +++ b/test-snap-build/action.yaml @@ -20,43 +20,23 @@ 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" + - name: Find and parse snapcraft.yaml + id: snapcraft-yaml + uses: snapcrafters/ci/parse-snapcraft-yaml@main + with: + snapcraft-yaml-path: ${{ inputs.snapcraft-yaml-path }} - name: Build snap uses: snapcore/action-build@v1 id: build with: - path: ${{ steps.yaml-path.outputs.yaml-path }} + path: ${{ steps.snapcraft-yaml.outputs.yaml-path }} - name: Parse snap review information id: parse shell: bash env: - yaml_path: ${{ steps.yaml-path.outputs.yaml-path }} + yaml_path: ${{ steps.snapcraft-yaml.outputs.yaml-path }} run: | # Populate defaults echo "classic=false" >> "$GITHUB_OUTPUT"