forked from tangled.org/core
Monorepo for Tangled

lexicons: introduce sh.tangled.pipeline.status

Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.sh>

anirudh.fi 8dbf6ee8 b9ed95dc

verified
Changed files
+480 -1
api
cmd
lexicons
pipeline
+385
api/tangled/cbor_gen.go
··· 1799 1799 1800 1800 return nil 1801 1801 } 1802 + func (t *PipelineStatus) MarshalCBOR(w io.Writer) error { 1803 + if t == nil { 1804 + _, err := w.Write(cbg.CborNull) 1805 + return err 1806 + } 1807 + 1808 + cw := cbg.NewCborWriter(w) 1809 + fieldCount := 7 1810 + 1811 + if t.Error == nil { 1812 + fieldCount-- 1813 + } 1814 + 1815 + if t.ExitCode == nil { 1816 + fieldCount-- 1817 + } 1818 + 1819 + if t.FinishedAt == nil { 1820 + fieldCount-- 1821 + } 1822 + 1823 + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { 1824 + return err 1825 + } 1826 + 1827 + // t.LexiconTypeID (string) (string) 1828 + if len("$type") > 1000000 { 1829 + return xerrors.Errorf("Value in field \"$type\" was too long") 1830 + } 1831 + 1832 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { 1833 + return err 1834 + } 1835 + if _, err := cw.WriteString(string("$type")); err != nil { 1836 + return err 1837 + } 1838 + 1839 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("sh.tangled.pipeline.status"))); err != nil { 1840 + return err 1841 + } 1842 + if _, err := cw.WriteString(string("sh.tangled.pipeline.status")); err != nil { 1843 + return err 1844 + } 1845 + 1846 + // t.Error (string) (string) 1847 + if t.Error != nil { 1848 + 1849 + if len("error") > 1000000 { 1850 + return xerrors.Errorf("Value in field \"error\" was too long") 1851 + } 1852 + 1853 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("error"))); err != nil { 1854 + return err 1855 + } 1856 + if _, err := cw.WriteString(string("error")); err != nil { 1857 + return err 1858 + } 1859 + 1860 + if t.Error == nil { 1861 + if _, err := cw.Write(cbg.CborNull); err != nil { 1862 + return err 1863 + } 1864 + } else { 1865 + if len(*t.Error) > 1000000 { 1866 + return xerrors.Errorf("Value in field t.Error was too long") 1867 + } 1868 + 1869 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Error))); err != nil { 1870 + return err 1871 + } 1872 + if _, err := cw.WriteString(string(*t.Error)); err != nil { 1873 + return err 1874 + } 1875 + } 1876 + } 1877 + 1878 + // t.Status (string) (string) 1879 + if len("status") > 1000000 { 1880 + return xerrors.Errorf("Value in field \"status\" was too long") 1881 + } 1882 + 1883 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("status"))); err != nil { 1884 + return err 1885 + } 1886 + if _, err := cw.WriteString(string("status")); err != nil { 1887 + return err 1888 + } 1889 + 1890 + if len(t.Status) > 1000000 { 1891 + return xerrors.Errorf("Value in field t.Status was too long") 1892 + } 1893 + 1894 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Status))); err != nil { 1895 + return err 1896 + } 1897 + if _, err := cw.WriteString(string(t.Status)); err != nil { 1898 + return err 1899 + } 1900 + 1901 + // t.ExitCode (int64) (int64) 1902 + if t.ExitCode != nil { 1903 + 1904 + if len("exitCode") > 1000000 { 1905 + return xerrors.Errorf("Value in field \"exitCode\" was too long") 1906 + } 1907 + 1908 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("exitCode"))); err != nil { 1909 + return err 1910 + } 1911 + if _, err := cw.WriteString(string("exitCode")); err != nil { 1912 + return err 1913 + } 1914 + 1915 + if t.ExitCode == nil { 1916 + if _, err := cw.Write(cbg.CborNull); err != nil { 1917 + return err 1918 + } 1919 + } else { 1920 + if *t.ExitCode >= 0 { 1921 + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(*t.ExitCode)); err != nil { 1922 + return err 1923 + } 1924 + } else { 1925 + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-*t.ExitCode-1)); err != nil { 1926 + return err 1927 + } 1928 + } 1929 + } 1930 + 1931 + } 1932 + 1933 + // t.StartedAt (string) (string) 1934 + if len("startedAt") > 1000000 { 1935 + return xerrors.Errorf("Value in field \"startedAt\" was too long") 1936 + } 1937 + 1938 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("startedAt"))); err != nil { 1939 + return err 1940 + } 1941 + if _, err := cw.WriteString(string("startedAt")); err != nil { 1942 + return err 1943 + } 1944 + 1945 + if len(t.StartedAt) > 1000000 { 1946 + return xerrors.Errorf("Value in field t.StartedAt was too long") 1947 + } 1948 + 1949 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.StartedAt))); err != nil { 1950 + return err 1951 + } 1952 + if _, err := cw.WriteString(string(t.StartedAt)); err != nil { 1953 + return err 1954 + } 1955 + 1956 + // t.UpdatedAt (string) (string) 1957 + if len("updatedAt") > 1000000 { 1958 + return xerrors.Errorf("Value in field \"updatedAt\" was too long") 1959 + } 1960 + 1961 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("updatedAt"))); err != nil { 1962 + return err 1963 + } 1964 + if _, err := cw.WriteString(string("updatedAt")); err != nil { 1965 + return err 1966 + } 1967 + 1968 + if len(t.UpdatedAt) > 1000000 { 1969 + return xerrors.Errorf("Value in field t.UpdatedAt was too long") 1970 + } 1971 + 1972 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.UpdatedAt))); err != nil { 1973 + return err 1974 + } 1975 + if _, err := cw.WriteString(string(t.UpdatedAt)); err != nil { 1976 + return err 1977 + } 1978 + 1979 + // t.FinishedAt (string) (string) 1980 + if t.FinishedAt != nil { 1981 + 1982 + if len("finishedAt") > 1000000 { 1983 + return xerrors.Errorf("Value in field \"finishedAt\" was too long") 1984 + } 1985 + 1986 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("finishedAt"))); err != nil { 1987 + return err 1988 + } 1989 + if _, err := cw.WriteString(string("finishedAt")); err != nil { 1990 + return err 1991 + } 1992 + 1993 + if t.FinishedAt == nil { 1994 + if _, err := cw.Write(cbg.CborNull); err != nil { 1995 + return err 1996 + } 1997 + } else { 1998 + if len(*t.FinishedAt) > 1000000 { 1999 + return xerrors.Errorf("Value in field t.FinishedAt was too long") 2000 + } 2001 + 2002 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.FinishedAt))); err != nil { 2003 + return err 2004 + } 2005 + if _, err := cw.WriteString(string(*t.FinishedAt)); err != nil { 2006 + return err 2007 + } 2008 + } 2009 + } 2010 + return nil 2011 + } 2012 + 2013 + func (t *PipelineStatus) UnmarshalCBOR(r io.Reader) (err error) { 2014 + *t = PipelineStatus{} 2015 + 2016 + cr := cbg.NewCborReader(r) 2017 + 2018 + maj, extra, err := cr.ReadHeader() 2019 + if err != nil { 2020 + return err 2021 + } 2022 + defer func() { 2023 + if err == io.EOF { 2024 + err = io.ErrUnexpectedEOF 2025 + } 2026 + }() 2027 + 2028 + if maj != cbg.MajMap { 2029 + return fmt.Errorf("cbor input should be of type map") 2030 + } 2031 + 2032 + if extra > cbg.MaxLength { 2033 + return fmt.Errorf("PipelineStatus: map struct too large (%d)", extra) 2034 + } 2035 + 2036 + n := extra 2037 + 2038 + nameBuf := make([]byte, 10) 2039 + for i := uint64(0); i < n; i++ { 2040 + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000) 2041 + if err != nil { 2042 + return err 2043 + } 2044 + 2045 + if !ok { 2046 + // Field doesn't exist on this type, so ignore it 2047 + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { 2048 + return err 2049 + } 2050 + continue 2051 + } 2052 + 2053 + switch string(nameBuf[:nameLen]) { 2054 + // t.LexiconTypeID (string) (string) 2055 + case "$type": 2056 + 2057 + { 2058 + sval, err := cbg.ReadStringWithMax(cr, 1000000) 2059 + if err != nil { 2060 + return err 2061 + } 2062 + 2063 + t.LexiconTypeID = string(sval) 2064 + } 2065 + // t.Error (string) (string) 2066 + case "error": 2067 + 2068 + { 2069 + b, err := cr.ReadByte() 2070 + if err != nil { 2071 + return err 2072 + } 2073 + if b != cbg.CborNull[0] { 2074 + if err := cr.UnreadByte(); err != nil { 2075 + return err 2076 + } 2077 + 2078 + sval, err := cbg.ReadStringWithMax(cr, 1000000) 2079 + if err != nil { 2080 + return err 2081 + } 2082 + 2083 + t.Error = (*string)(&sval) 2084 + } 2085 + } 2086 + // t.Status (string) (string) 2087 + case "status": 2088 + 2089 + { 2090 + sval, err := cbg.ReadStringWithMax(cr, 1000000) 2091 + if err != nil { 2092 + return err 2093 + } 2094 + 2095 + t.Status = string(sval) 2096 + } 2097 + // t.ExitCode (int64) (int64) 2098 + case "exitCode": 2099 + { 2100 + 2101 + b, err := cr.ReadByte() 2102 + if err != nil { 2103 + return err 2104 + } 2105 + if b != cbg.CborNull[0] { 2106 + if err := cr.UnreadByte(); err != nil { 2107 + return err 2108 + } 2109 + maj, extra, err := cr.ReadHeader() 2110 + if err != nil { 2111 + return err 2112 + } 2113 + var extraI int64 2114 + switch maj { 2115 + case cbg.MajUnsignedInt: 2116 + extraI = int64(extra) 2117 + if extraI < 0 { 2118 + return fmt.Errorf("int64 positive overflow") 2119 + } 2120 + case cbg.MajNegativeInt: 2121 + extraI = int64(extra) 2122 + if extraI < 0 { 2123 + return fmt.Errorf("int64 negative overflow") 2124 + } 2125 + extraI = -1 - extraI 2126 + default: 2127 + return fmt.Errorf("wrong type for int64 field: %d", maj) 2128 + } 2129 + 2130 + t.ExitCode = (*int64)(&extraI) 2131 + } 2132 + } 2133 + // t.StartedAt (string) (string) 2134 + case "startedAt": 2135 + 2136 + { 2137 + sval, err := cbg.ReadStringWithMax(cr, 1000000) 2138 + if err != nil { 2139 + return err 2140 + } 2141 + 2142 + t.StartedAt = string(sval) 2143 + } 2144 + // t.UpdatedAt (string) (string) 2145 + case "updatedAt": 2146 + 2147 + { 2148 + sval, err := cbg.ReadStringWithMax(cr, 1000000) 2149 + if err != nil { 2150 + return err 2151 + } 2152 + 2153 + t.UpdatedAt = string(sval) 2154 + } 2155 + // t.FinishedAt (string) (string) 2156 + case "finishedAt": 2157 + 2158 + { 2159 + b, err := cr.ReadByte() 2160 + if err != nil { 2161 + return err 2162 + } 2163 + if b != cbg.CborNull[0] { 2164 + if err := cr.UnreadByte(); err != nil { 2165 + return err 2166 + } 2167 + 2168 + sval, err := cbg.ReadStringWithMax(cr, 1000000) 2169 + if err != nil { 2170 + return err 2171 + } 2172 + 2173 + t.FinishedAt = (*string)(&sval) 2174 + } 2175 + } 2176 + 2177 + default: 2178 + // Field doesn't exist on this type, so ignore it 2179 + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { 2180 + return err 2181 + } 2182 + } 2183 + } 2184 + 2185 + return nil 2186 + } 1802 2187 func (t *Pipeline_CloneOpts) MarshalCBOR(w io.Writer) error { 1803 2188 if t == nil { 1804 2189 _, err := w.Write(cbg.CborNull)
+35
api/tangled/pipelinestatus.go
··· 1 + // Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT. 2 + 3 + package tangled 4 + 5 + // schema: sh.tangled.pipeline.status 6 + 7 + import ( 8 + "github.com/bluesky-social/indigo/lex/util" 9 + ) 10 + 11 + const ( 12 + PipelineStatusNSID = "sh.tangled.pipeline.status" 13 + ) 14 + 15 + func init() { 16 + util.RegisterType("sh.tangled.pipeline.status", &PipelineStatus{}) 17 + } // 18 + // RECORDTYPE: PipelineStatus 19 + type PipelineStatus struct { 20 + LexiconTypeID string `json:"$type,const=sh.tangled.pipeline.status" cborgen:"$type,const=sh.tangled.pipeline.status"` 21 + // error: error message if failed 22 + Error *string `json:"error,omitempty" cborgen:"error,omitempty"` 23 + // exitCode: exit code if failed 24 + ExitCode *int64 `json:"exitCode,omitempty" cborgen:"exitCode,omitempty"` 25 + // finishedAt: pipeline finish time, if finished 26 + FinishedAt *string `json:"finishedAt,omitempty" cborgen:"finishedAt,omitempty"` 27 + // pipeline: pipeline at ref 28 + Pipeline string `json:"pipeline" cborgen:"pipeline"` 29 + // startedAt: pipeline start time 30 + StartedAt string `json:"startedAt" cborgen:"startedAt"` 31 + // status: Pipeline status 32 + Status string `json:"status" cborgen:"status"` 33 + // updatedAt: pipeline last updated time 34 + UpdatedAt string `json:"updatedAt" cborgen:"updatedAt"` 35 + }
+1 -1
api/tangled/tangledpipeline.go
··· 85 85 // Pipeline_Workflow is a "workflow" in the sh.tangled.pipeline schema. 86 86 type Pipeline_Workflow struct { 87 87 Clone *Pipeline_CloneOpts `json:"clone" cborgen:"clone"` 88 - Dependencies []Pipeline_Dependencies_Elem `json:"dependencies" cborgen:"dependencies"` 88 + Dependencies []Pipeline_Dependencies_Elem `json:"dependencies" cborgen:"dependencies"` 89 89 Environment []*Pipeline_Workflow_Environment_Elem `json:"environment" cborgen:"environment"` 90 90 Name string `json:"name" cborgen:"name"` 91 91 Steps []*Pipeline_Step `json:"steps" cborgen:"steps"`
+1
cmd/gen.go
··· 22 22 tangled.GitRefUpdate{}, 23 23 tangled.GraphFollow{}, 24 24 tangled.KnotMember{}, 25 + tangled.PipelineStatus{}, 25 26 tangled.Pipeline_CloneOpts{}, 26 27 tangled.Pipeline_Dependencies_Elem{}, 27 28 tangled.Pipeline_ManualTriggerData_Inputs_Elem{},
+58
lexicons/pipeline/status.json
··· 1 + { 2 + "lexicon": 1, 3 + "id": "sh.tangled.pipeline.status", 4 + "needsCbor": true, 5 + "needsType": true, 6 + "defs": { 7 + "main": { 8 + "type": "record", 9 + "key": "tid", 10 + "record": { 11 + "type": "object", 12 + "required": ["pipeline", "status", "startedAt", "updatedAt"], 13 + "properties": { 14 + "pipeline": { 15 + "type": "string", 16 + "format": "at-uri", 17 + "description": "pipeline at ref" 18 + }, 19 + "status": { 20 + "type": "string", 21 + "description": "Pipeline status", 22 + "enum": [ 23 + "pending", 24 + "running", 25 + "failed", 26 + "timeout", 27 + "cancelled", 28 + "success" 29 + ] 30 + }, 31 + "error": { 32 + "type": "string", 33 + "description": "error message if failed" 34 + }, 35 + "exitCode": { 36 + "type": "integer", 37 + "description": "exit code if failed" 38 + }, 39 + "startedAt": { 40 + "type": "string", 41 + "format": "datetime", 42 + "description": "pipeline start time" 43 + }, 44 + "updatedAt": { 45 + "type": "string", 46 + "format": "datetime", 47 + "description": "pipeline last updated time" 48 + }, 49 + "finishedAt": { 50 + "type": "string", 51 + "format": "datetime", 52 + "description": "pipeline finish time, if finished" 53 + } 54 + } 55 + } 56 + } 57 + } 58 + }