-
Notifications
You must be signed in to change notification settings - Fork 9
/
action.yml
106 lines (97 loc) · 4.2 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: 'Update snap tag'
description: 'Update the snapcraft.yaml for a given snap with the latest upstream tag'
# Inputs required by the action to perform correctly.
# token: This is the GITHUB_TOKEN that exists for the other repo whose workflow uses this action. Without the other repo's token, this action does not have permission to perform tasks on the other repo, like pushing changes or opening a PR
# repo: This is the repo who is using this action. This repo contains the snapcraft.yaml that this action will be working on.
inputs:
token:
description: 'A Github PAT'
required: true
repo:
description: 'The repo containing the snapcraft.yaml to be updated'
required: true
default: 'None'
version-schema:
description: 'Version schema of snapping repository'
required: false
default: 'None'
rock-version-schema:
description: 'Version schema of rock repository'
required: false
default: 'None'
# Outputs generated by running this action.
outputs:
new-snapcraft-yaml:
description: "Updated snapcraft.yaml"
value: ${{ steps.updatesnapyaml.outputs.new-snapcraft-yaml }}
# Global env var that can keep track of if there was a change or not. This determines if there are commits to be pushed.
env:
IS_CHANGE: false
IS_VERSION_CHANGE: false
# The jobs description defining a composite action
runs:
using: "composite"
steps:
# Step to checkout the desktop-snaps repo so that we can run updatesnapyaml.py. We need to define a folder called desktop-snaps to avoid the checkout overwriting the other repo's checkout which comes first in the other repo's workflow
- name: checkout desktop-snaps repo
uses: actions/checkout@v3
with:
repository: 'ubuntu/desktop-snaps'
ref: stable
path: desktop-snaps
# Step to run the script that will generate a new output_file with an updated tag, if one is available. If there was a change, then we move this to the snapcraft.yaml and note that there was a change.
- name: run updatesnapyaml
id: updatesnapyaml
run: |
./desktop-snaps/updatesnap/updatesnapyaml.py --github-user $GITHUB_USER --github-token $GITHUB_TOKEN --version-schema $VERSION_SCHEMA --rock-version-schema $ROCK_VERSION_SCHEMA https://github.com/${{ github.repository }}
# Make sure to put the updated snapcraft.yaml file in the right location if it lives in a snap directory
if [ -f version_file ]; then
echo "IS_VERSION_CHANGE=true" >> $GITHUB_ENV
rm version_file
fi
if [ -f output_file ]; then
echo "IS_CHANGE=true" >> $GITHUB_ENV
if [ -f rockcraft.yaml ]; then
mv output_file rockcraft.yaml
elif [ -d snap ]; then
mv output_file snap/snapcraft.yaml
else
mv output_file snapcraft.yaml
fi
fi
env:
GITHUB_USER: ubuntu
GITHUB_TOKEN: ${{ inputs.token }}
VERSION_SCHEMA: ${{ inputs.version-schema }}
ROCK_VERSION_SCHEMA: ${{ inputs.rock-version-schema }}
shell: bash
# Step to remove the desktop-snaps folder so that when we commit changes in another repo, the desktop-snaps folder is not committed there.
- name: Cleanup
run: |
rm -rf desktop-snaps
shell: bash
# If there was a change detected, then let's commit the changes
- name: Commit files
if: ${{ env.IS_CHANGE || env.IS_VERSION_CHANGE}}
run: |
set -x
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
commit_msg="Update tag"
if [ $IS_VERSION_CHANGE = true ] && [ $IS_CHANGE = false ]; then
commit_msg="Update snap version"
fi
if [ $IS_VERSION_CHANGE = true ] && [ $IS_CHANGE = true ]; then
commit_msg="Update snap version/tag"
fi
git commit -a -m "$commit_msg"
shell: bash
# If there was a change detected, then let's push the changes
- name: Push changes
if: ${{ env.IS_CHANGE || env.IS_VERSION_CHANGE }}
uses: ad-m/github-push-action@master
env:
GITHUB_USER: ubuntu
GITHUB_TOKEN: ${{ inputs.token }}
with:
branch: ${{ github.ref }}