Skip to content

Commit

Permalink
feat: add parse-snapcraft-yaml action
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsgruk committed Dec 5, 2023
1 parent 09be27c commit 353e542
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 200 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
37 changes: 8 additions & 29 deletions call-for-testing/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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=()
Expand Down Expand Up @@ -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 }}
Expand Down
33 changes: 6 additions & 27 deletions get-architectures/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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")"
Expand Down
37 changes: 8 additions & 29 deletions get-screenshots/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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 }}"
Expand Down
40 changes: 40 additions & 0 deletions parse-snapcraft-yaml/README.md
Original file line number Diff line number Diff line change
@@ -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` |
58 changes: 58 additions & 0 deletions parse-snapcraft-yaml/action.yaml
Original file line number Diff line number Diff line change
@@ -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"
33 changes: 6 additions & 27 deletions promote-to-stable/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
37 changes: 8 additions & 29 deletions release-to-candidate/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,40 +46,19 @@ runs:
git config --global user.email "[email protected]"
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
Expand All @@ -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"
Expand Down
Loading

0 comments on commit 353e542

Please sign in to comment.